Skip to content

Commit

Permalink
rubocop/no_fileutils_rmrf: Reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
issyl0 committed Jul 14, 2024
1 parent 99be6a1 commit 1e2e5ec
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +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.rm_rf("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" do
expect_offense(<<~RUBY)
FileUtils.rmtree("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
describe "FileUtils.rmtree" do
it "registers an offense when using FileUtils.rmtree" do
expect_offense(<<~RUBY)
FileUtils.rmtree("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end

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

expect(corrected).to eq(<<~RUBY)
FileUtils.rm_r("path/to/directory")
RUBY
end
end
end

0 comments on commit 1e2e5ec

Please sign in to comment.