From cc7784605d5dfbbca330d2934e7616cf38c46c5d Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 13 Jul 2024 16:24:22 -0400 Subject: [PATCH] rubocop/no_fileutils_rmrf: Reorganize tests --- .../test/rubocops/no_fileutils_rmrf_spec.rb | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb index 90cf8718e5..9ea3634ae2 100644 --- a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb +++ b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb @@ -5,46 +5,60 @@ require "rubocops/no_fileutils_rmrf" 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 + 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 "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 - 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 + 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 + + 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 - 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 + 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.rm_rf("path/to/directory") - RUBY + 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 - - 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 + expect(corrected).to eq(<<~RUBY) + FileUtils.rm_r("path/to/directory") + RUBY + end end end