rubocop/no_fileutils_rmrf: Reorganize tests
This commit is contained in:
parent
ebd9d183dc
commit
cc7784605d
@ -5,46 +5,60 @@ 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
|
||||||
expect_offense(<<~RUBY)
|
it "registers an offense" do
|
||||||
FileUtils.rm_rf("path/to/directory")
|
expect_offense(<<~RUBY)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
FileUtils.rm_rf("path/to/directory")
|
||||||
RUBY
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "autocorrects" do
|
||||||
|
corrected = autocorrect_source(<<~RUBY)
|
||||||
|
FileUtils.rm_rf("path/to/directory")
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
expect(corrected).to eq(<<~RUBY)
|
||||||
|
FileUtils.rm_r("path/to/directory")
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense when using FileUtils.rm_f" do
|
describe "FileUtils.rm_f" do
|
||||||
expect_offense(<<~RUBY)
|
it "registers an offense" do
|
||||||
FileUtils.rm_f("path/to/directory")
|
expect_offense(<<~RUBY)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
FileUtils.rm_f("path/to/directory")
|
||||||
RUBY
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "autocorrects" do
|
||||||
|
corrected = autocorrect_source(<<~RUBY)
|
||||||
|
FileUtils.rm_f("path/to/directory")
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
expect(corrected).to eq(<<~RUBY)
|
||||||
|
FileUtils.rm("path/to/directory")
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense when using FileUtils.rmtree" do
|
describe "FileUtils.rmtree" do
|
||||||
expect_offense(<<~RUBY)
|
it "registers an offense" do
|
||||||
FileUtils.rmtree("path/to/directory")
|
expect_offense(<<~RUBY)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
FileUtils.rmtree("path/to/directory")
|
||||||
RUBY
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
|
||||||
end
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "autocorrects" do
|
it "autocorrects" do
|
||||||
corrected = autocorrect_source(<<~RUBY)
|
corrected = autocorrect_source(<<~RUBY)
|
||||||
FileUtils.rm_rf("path/to/directory")
|
FileUtils.rmtree("path/to/directory")
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect(corrected).to eq(<<~RUBY)
|
expect(corrected).to eq(<<~RUBY)
|
||||||
FileUtils.rm_r("path/to/directory")
|
FileUtils.rm_r("path/to/directory")
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not register an offense when using FileUtils.rm_r" do
|
|
||||||
expect_no_offenses(<<~RUBY)
|
|
||||||
FileUtils.rm_r("path/to/directory")
|
|
||||||
RUBY
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not register an offense when using FileUtils.rm" do
|
|
||||||
expect_no_offenses(<<~RUBY)
|
|
||||||
FileUtils.rm("path/to/directory")
|
|
||||||
RUBY
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user