diff --git a/CHANGELOG.md b/CHANGELOG.md index 692a1914c..1c4336d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Master (Unreleased) -- Support correcting `assert_nil` and `refute_nil` to `RSpec/Rails/MinitestAssertions`. ([@G-Rath]) +- Support correcting `assert_nil` and `refute_nil` in `RSpec/Rails/MinitestAssertions`. ([@G-Rath]) +- Support correcting `assert_not_equal` and `assert_not_equal` in `RSpec/Rails/MinitestAssertions`. ([@G-Rath]) - Fix a false positive for `RSpec/ExpectActual` when used with rspec-rails routing matchers. ([@naveg]) - Add new `RSpec/RepeatedSubjectCall` cop. ([@drcapulet]) diff --git a/lib/rubocop/cop/rspec/rails/minitest_assertions.rb b/lib/rubocop/cop/rspec/rails/minitest_assertions.rb index f12448691..15e53c3d3 100644 --- a/lib/rubocop/cop/rspec/rails/minitest_assertions.rb +++ b/lib/rubocop/cop/rspec/rails/minitest_assertions.rb @@ -29,19 +29,21 @@ class MinitestAssertions < Base MSG = 'Use `%s`.' RESTRICT_ON_SEND = %i[ assert_equal + assert_not_equal refute_equal assert_nil + assert_not_nil refute_nil ].freeze # @!method minitest_equal_assertion(node) def_node_matcher :minitest_equal_assertion, <<~PATTERN - (send nil? {:assert_equal :refute_equal} $_ $_ $_?) + (send nil? {:assert_equal :assert_not_equal :refute_equal} $_ $_ $_?) PATTERN # @!method minitest_nil_assertion(node) def_node_matcher :minitest_nil_assertion, <<~PATTERN - (send nil? {:assert_nil :refute_nil} $_ $_?) + (send nil? {:assert_nil :assert_not_nil :refute_nil} $_ $_?) PATTERN def on_send(node) diff --git a/spec/rubocop/cop/rspec/rails/minitest_assertions_spec.rb b/spec/rubocop/cop/rspec/rails/minitest_assertions_spec.rb index 7537060be..d1e817a61 100644 --- a/spec/rubocop/cop/rspec/rails/minitest_assertions_spec.rb +++ b/spec/rubocop/cop/rspec/rails/minitest_assertions_spec.rb @@ -49,6 +49,17 @@ RUBY end + it 'registers an offense when using `assert_not_equal`' do + expect_offense(<<~RUBY) + assert_not_equal a, b + ^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).not_to eq(a)`. + RUBY + + expect_correction(<<~RUBY) + expect(b).not_to eq(a) + RUBY + end + it 'registers an offense when using `refute_equal`' do expect_offense(<<~RUBY) refute_equal a, b @@ -120,6 +131,17 @@ RUBY end + it 'registers an offense when using `assert_not_nil`' do + expect_offense(<<~RUBY) + assert_not_nil a + ^^^^^^^^^^^^^^^^ Use `expect(a).not_to eq(nil)`. + RUBY + + expect_correction(<<~RUBY) + expect(a).not_to eq(nil) + RUBY + end + it 'registers an offense when using `refute_nil`' do expect_offense(<<~RUBY) refute_nil a