From 900c0f93af4ff65db03afa15fa4c56d54dcd7c46 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 13 Jul 2024 16:24:22 -0400 Subject: [PATCH] test/rubocop/no_fileutils_rmrf: Reorganize tests --- .../test/rubocops/no_fileutils_rmrf_spec.rb | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb index c4db081f63a6aa..12bd2730b81b08 100644 --- a/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb +++ b/Library/Homebrew/test/rubocops/no_fileutils_rmrf_spec.rb @@ -5,52 +5,61 @@ 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.rmtree_f("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_f" do - expect_offense(<<~RUBY) - FileUtils.rmtree_f("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 - end - it "does not register an offense when using FileUtils.rmtree" do - expect_no_offenses(<<~RUBY) - FileUtils.rmtree("path/to/directory") - RUBY + describe "FileUtils.rmtree_f" do + it "registers an offense when using FileUtils.rmtree_f" do + expect_offense(<<~RUBY) + FileUtils.rmtree_f("path/to/directory") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} + RUBY + end + + it "autocorrects" do + corrected = autocorrect_source(<<~RUBY) + FileUtils.rmtree_f("path/to/directory") + RUBY + + expect(corrected).to eq(<<~RUBY) + FileUtils.rmtree("path/to/directory") + RUBY + end end end