diff --git a/spec/rubocop/cop/rails/compact_blank_spec.rb b/spec/rubocop/cop/rails/compact_blank_spec.rb index 93d1ca2bd7..3b3cd9d77b 100644 --- a/spec/rubocop/cop/rails/compact_blank_spec.rb +++ b/spec/rubocop/cop/rails/compact_blank_spec.rb @@ -24,6 +24,17 @@ RUBY end + it 'registers and corrects an offense when using `reject { |k, v| v.blank? }`' do + expect_offense(<<~RUBY) + collection.reject { |k, v| v.blank? } + ^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead. + 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? } @@ -46,6 +57,17 @@ RUBY end + it 'registers and corrects an offense when using `delete_if { |k, v| v.blank? }`' do + expect_offense(<<~RUBY) + collection.delete_if { |k, v| v.blank? } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. + RUBY + + expect_correction(<<~RUBY) + collection.compact_blank! + RUBY + end + it 'does not registers an offense when using `reject! { |e| e.blank? }`' do expect_no_offenses(<<~RUBY) collection.reject! { |e| e.blank? } @@ -91,6 +113,17 @@ RUBY end + it 'registers and corrects an offense when using `select { |k, v| v.present? }`' do + expect_offense(<<~RUBY) + collection.select { |k, v| v.present? } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank` instead. + RUBY + + expect_correction(<<~RUBY) + collection.compact_blank + RUBY + end + it 'registers and corrects an offense when using `keep_if { |e| e.present? }`' do expect_offense(<<~RUBY) collection.keep_if { |e| e.present? } @@ -113,6 +146,17 @@ RUBY end + it 'registers and corrects an offense when using `keep_if { |k, v| v.present? }`' do + expect_offense(<<~RUBY) + collection.keep_if { |k, v| v.present? } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `compact_blank!` instead. + RUBY + + expect_correction(<<~RUBY) + collection.compact_blank! + RUBY + end + it 'does not register an offense when using `select! { |e| e.present? }`' do expect_no_offenses(<<~RUBY) collection.select! { |e| e.present? }