brew/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb

77 lines
2.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "rubocops/no_fileutils_rmrf"
RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do
subject(:cop) { described_class.new }
describe "rm_rf" do
it "registers an offense" do
expect_offense(<<~RUBY)
rm_rf("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
FileUtils.rm_rf("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end
it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
rm_rf("path/to/directory")
FileUtils.rm_rf("path/to/other/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
rm_r("path/to/directory")
FileUtils.rm_r("path/to/other/directory")
RUBY
end
end
describe "rm_f" do
it "registers an offense" do
expect_offense(<<~RUBY)
rm_f("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
FileUtils.rm_f("path/to/other/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end
it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
rm_f("path/to/directory")
FileUtils.rm_f("path/to/other/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
rm("path/to/directory")
FileUtils.rm("path/to/other/directory")
RUBY
end
end
describe "rmtree" do
it "registers an offense" do
expect_offense(<<~RUBY)
rmtree("path/to/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
Pathname.rmtree("path/to/other/directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG}
RUBY
end
it "autocorrects" do
corrected = autocorrect_source(<<~RUBY)
rmtree("path/to/directory")
Pathname.rmtree("path/to/other/directory")
RUBY
expect(corrected).to eq(<<~RUBY)
rm_r("path/to/directory")
FileUtils.rm_r("path/to/other/directory")
RUBY
end
end
end