Skip to content

Commit 1e2e5ec

Browse files
committed
rubocop/no_fileutils_rmrf: Reorganize tests
1 parent 99be6a1 commit 1e2e5ec

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,60 @@
55
RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
66
subject(:cop) { described_class.new }
77

8-
it "registers an offense when using FileUtils.rm_rf" do
9-
expect_offense(<<~RUBY)
10-
FileUtils.rm_rf("path/to/directory")
11-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
12-
RUBY
13-
end
8+
describe "FileUtils.rm_rf" do
9+
it "registers an offense" do
10+
expect_offense(<<~RUBY)
11+
FileUtils.rm_rf("path/to/directory")
12+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
13+
RUBY
14+
end
1415

15-
it "registers an offense when using FileUtils.rm_f" do
16-
expect_offense(<<~RUBY)
17-
FileUtils.rm_f("path/to/directory")
18-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
19-
RUBY
20-
end
16+
it "autocorrects" do
17+
corrected = autocorrect_source(<<~RUBY)
18+
FileUtils.rm_rf("path/to/directory")
19+
RUBY
2120

22-
it "registers an offense when using FileUtils.rmtree" do
23-
expect_offense(<<~RUBY)
24-
FileUtils.rmtree("path/to/directory")
25-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
26-
RUBY
21+
expect(corrected).to eq(<<~RUBY)
22+
FileUtils.rm_r("path/to/directory")
23+
RUBY
24+
end
2725
end
2826

29-
it "autocorrects" do
30-
corrected = autocorrect_source(<<~RUBY)
31-
FileUtils.rm_rf("path/to/directory")
32-
RUBY
27+
describe "FileUtils.rm_f" do
28+
it "registers an offense" do
29+
expect_offense(<<~RUBY)
30+
FileUtils.rm_f("path/to/directory")
31+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
32+
RUBY
33+
end
3334

34-
expect(corrected).to eq(<<~RUBY)
35-
FileUtils.rm_r("path/to/directory")
36-
RUBY
37-
end
35+
it "autocorrects" do
36+
corrected = autocorrect_source(<<~RUBY)
37+
FileUtils.rm_f("path/to/directory")
38+
RUBY
3839

39-
it "does not register an offense when using FileUtils.rm_r" do
40-
expect_no_offenses(<<~RUBY)
41-
FileUtils.rm_r("path/to/directory")
42-
RUBY
40+
expect(corrected).to eq(<<~RUBY)
41+
FileUtils.rm("path/to/directory")
42+
RUBY
43+
end
4344
end
4445

45-
it "does not register an offense when using FileUtils.rm" do
46-
expect_no_offenses(<<~RUBY)
47-
FileUtils.rm("path/to/directory")
48-
RUBY
46+
describe "FileUtils.rmtree" do
47+
it "registers an offense when using FileUtils.rmtree" do
48+
expect_offense(<<~RUBY)
49+
FileUtils.rmtree("path/to/directory")
50+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
51+
RUBY
52+
end
53+
54+
it "autocorrects" do
55+
corrected = autocorrect_source(<<~RUBY)
56+
FileUtils.rmtree("path/to/directory")
57+
RUBY
58+
59+
expect(corrected).to eq(<<~RUBY)
60+
FileUtils.rm_r("path/to/directory")
61+
RUBY
62+
end
4963
end
5064
end

0 commit comments

Comments
 (0)