rubocop/no_fileutils_rmrf: Reorganize tests

This commit is contained in:
Issy Long 2024-07-13 16:24:22 -04:00 committed by Issy Long
parent ebd9d183dc
commit cc7784605d
No known key found for this signature in database

View File

@ -5,27 +5,14 @@ require "rubocops/no_fileutils_rmrf"
RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
it "registers an offense when using FileUtils.rm_rf" do describe "FileUtils.rm_rf" do
it "registers an offense" do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
FileUtils.rm_rf("path/to/directory") FileUtils.rm_rf("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY RUBY
end 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 "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 it "autocorrects" do
corrected = autocorrect_source(<<~RUBY) corrected = autocorrect_source(<<~RUBY)
FileUtils.rm_rf("path/to/directory") FileUtils.rm_rf("path/to/directory")
@ -35,16 +22,43 @@ RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
FileUtils.rm_r("path/to/directory") FileUtils.rm_r("path/to/directory")
RUBY RUBY
end end
end
it "does not register an offense when using FileUtils.rm_r" do describe "FileUtils.rm_f" do
expect_no_offenses(<<~RUBY) it "registers an offense" do
FileUtils.rm_r("path/to/directory") expect_offense(<<~RUBY)
FileUtils.rm_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY RUBY
end end
it "does not register an offense when using FileUtils.rm" do it "autocorrects" do
expect_no_offenses(<<~RUBY) corrected = autocorrect_source(<<~RUBY)
FileUtils.rm_f("path/to/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
FileUtils.rm("path/to/directory") FileUtils.rm("path/to/directory")
RUBY RUBY
end end
end
describe "FileUtils.rmtree" do
it "registers an offense" 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 end