Skip to content

Commit

Permalink
test/rubocop/no_fileutils_rmrf: Reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
issyl0 committed Jul 13, 2024
1 parent ffaa407 commit a7a1dbd
Showing 1 changed file with 46 additions and 38 deletions.
84 changes: 46 additions & 38 deletions Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,60 @@
RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
subject(:cop) { described_class.new }

it "registers an offense when using FileUtils.rm_rf" do
expect_offense(<<~RUBY)
FileUtils.rm_rf("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end
describe "FileUtils.rm_rf" do
it "registers an offense" do
expect_offense(<<~RUBY)
FileUtils.rmtree_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end

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

it "registers an offense when using FileUtils.rmtree_f" do
expect_offense(<<~RUBY)
FileUtils.rmtree_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
expect(corrected).to eq(<<~RUBY)
FileUtils.rm_r("path/to/directory")
RUBY
end
end

it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
FileUtils.rm_rf("path/to/directory")
RUBY
describe "FileUtils.rm_f" do
it "registers an offense" do
expect_offense(<<~RUBY)
FileUtils.rm_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end

expect(corrected).to eq(<<~RUBY)
FileUtils.rm_r("path/to/directory")
RUBY
end
it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
FileUtils.rm_f("path/to/directory")
RUBY

it "does not register an offense when using FileUtils.rm_r" do
expect_no_offenses(<<~RUBY)
FileUtils.rm_r("path/to/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
FileUtils.rm("path/to/directory")
RUBY
end
end

it "does not register an offense when using FileUtils.rm" do
expect_no_offenses(<<~RUBY)
FileUtils.rm("path/to/directory")
RUBY
end
describe "FileUtils.rmtree_f" do
it "registers an offense when using FileUtils.rmtree_f" do
expect_offense(<<~RUBY)
FileUtils.rmtree_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end

it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
FileUtils.rmtree_f("path/to/directory")
RUBY

it "does not register an offense when using FileUtils.rmtree" do
expect_no_offenses(<<~RUBY)
FileUtils.rmtree("path/to/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
FileUtils.rmtree("path/to/directory")
RUBY
end
end
end

0 comments on commit a7a1dbd

Please sign in to comment.