| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/no_fileutils_rmrf" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSpec.describe RuboCop::Cop::Homebrew::NoFileutilsRmrf do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |   describe "rm_rf" do | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |     it "registers an offense" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_rf("path/to/directory") | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm_rf("path/to/directory") | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-07-13 16:01:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |     it "autocorrects" do | 
					
						
							|  |  |  |       corrected = autocorrect_source(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_rf("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm_rf("path/to/other/directory") | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       expect(corrected).to eq(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_r("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm_r("path/to/other/directory") | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-07-13 16:12:30 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |   describe "rm_f" do | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |     it "registers an offense" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_f("path/to/directory") | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm_f("path/to/other/directory") | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |     it "autocorrects" do | 
					
						
							|  |  |  |       corrected = autocorrect_source(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_f("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm_f("path/to/other/directory") | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       expect(corrected).to eq(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 14:13:37 -04:00
										 |  |  |         FileUtils.rm("path/to/other/directory") | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2024-07-13 16:01:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |   describe "rmtree" do | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |     it "registers an offense" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rmtree("path/to/directory") | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-14 22:34:34 -04:00
										 |  |  |         other_dir = Pathname("path/to/other/directory") | 
					
						
							|  |  |  |         other_dir.rmtree | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-15 14:05:36 -04:00
										 |  |  |         def buildpath | 
					
						
							|  |  |  |           Pathname("path/to/yet/another/directory") | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         buildpath.rmtree | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-15 15:09:55 -04:00
										 |  |  |         (path/"here").rmtree | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^ Homebrew/NoFileutilsRmrf: #{RuboCop::Cop::Homebrew::NoFileutilsRmrf::MSG} | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "autocorrects" do | 
					
						
							|  |  |  |       corrected = autocorrect_source(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rmtree("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 22:34:34 -04:00
										 |  |  |         other_dir = Pathname("path/to/other/directory") | 
					
						
							|  |  |  |         other_dir.rmtree | 
					
						
							| 
									
										
										
										
											2024-07-15 14:05:36 -04:00
										 |  |  |         def buildpath | 
					
						
							|  |  |  |           Pathname("path/to/yet/another/directory") | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         buildpath.rmtree | 
					
						
							| 
									
										
										
										
											2024-07-15 15:09:55 -04:00
										 |  |  |         (path/"here").rmtree | 
					
						
							| 
									
										
										
										
											2024-07-13 16:24:22 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(corrected).to eq(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2024-07-14 12:09:59 -04:00
										 |  |  |         rm_r("path/to/directory") | 
					
						
							| 
									
										
										
										
											2024-07-14 22:34:34 -04:00
										 |  |  |         other_dir = Pathname("path/to/other/directory") | 
					
						
							|  |  |  |         FileUtils.rm_r(other_dir) | 
					
						
							| 
									
										
										
										
											2024-07-15 14:05:36 -04:00
										 |  |  |         def buildpath | 
					
						
							|  |  |  |           Pathname("path/to/yet/another/directory") | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         FileUtils.rm_r(buildpath) | 
					
						
							| 
									
										
										
										
											2024-07-15 15:09:55 -04:00
										 |  |  |         FileUtils.rm_r(path/"here") | 
					
						
							| 
									
										
										
										
											2024-07-13 22:13:03 -04:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2024-07-13 15:35:06 -04:00
										 |  |  | end |