| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/compact_blank" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::Homebrew::CompactBlank, :config do | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |   it "registers and corrects an offense when using `reject { |e| e.blank? }`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject { |e| e.blank? } | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `reject(&:blank?)`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject(&:blank?) | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^ Use `compact_blank` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `delete_if { |e| e.blank? }`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.delete_if { |e| e.blank? } | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank! | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `delete_if(&:blank?)`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.delete_if(&:blank?) | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank! | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `reject! { |e| e.blank? }`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject! { |e| e.blank? } | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank! | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `reject!(&:blank?)`" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject!(&:blank?) | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank! | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "registers and corrects an offense when using `reject(&:blank?)` in block" do | 
					
						
							|  |  |  |     expect_offense(<<~RUBY) | 
					
						
							|  |  |  |       hash.transform_values { |value| value.reject(&:blank?) } | 
					
						
							| 
									
										
										
										
											2024-01-26 13:32:29 -08:00
										 |  |  |                                             ^^^^^^^^^^^^^^^^ Use `compact_blank` instead. | 
					
						
							| 
									
										
										
										
											2024-01-26 13:24:32 -08:00
										 |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~RUBY) | 
					
						
							|  |  |  |       hash.transform_values { |value| value.compact_blank } | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not register an offense when using `compact_blank`" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not register an offense when using `compact_blank!`" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       collection.compact_blank! | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not register an offense when using `reject { |k, v| k.blank? }`" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject { |k, v| k.blank? } | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not register an offense when using the receiver of `blank?` is not a block variable" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       def foo(arg) | 
					
						
							|  |  |  |         collection.reject { |_| arg.blank? } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not register an offense when using `reject { |e| e.empty? }`" do | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |       collection.reject { |e| e.empty? } | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |