File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
lib/rubocop/cop/rspec_rails
spec/rubocop/cop/rspec_rails Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change 22
33## Master (Unreleased)
44
5- - Support correcting ` assert_nil ` and ` refute_nil ` to ` RSpec/Rails/MinitestAssertions ` . ([ @G-Rath ] )
5+ - Support correcting ` assert_nil ` and ` refute_nil ` in ` RSpec/Rails/MinitestAssertions ` . ([ @G-Rath ] )
6+ - Support correcting ` assert_not_equal ` and ` assert_not_equal ` in ` RSpec/Rails/MinitestAssertions ` . ([ @G-Rath ] )
67- Fix a false positive for ` RSpec/ExpectActual ` when used with rspec-rails routing matchers. ([ @naveg ] )
78- Add new ` RSpec/RepeatedSubjectCall ` cop. ([ @drcapulet ] )
89
Original file line number Diff line number Diff line change @@ -29,19 +29,21 @@ class MinitestAssertions < Base
2929 MSG = 'Use `%<prefer>s`.'
3030 RESTRICT_ON_SEND = %i[
3131 assert_equal
32+ assert_not_equal
3233 refute_equal
3334 assert_nil
35+ assert_not_nil
3436 refute_nil
3537 ] . freeze
3638
3739 # @!method minitest_equal_assertion(node)
3840 def_node_matcher :minitest_equal_assertion , <<~PATTERN
39- (send nil? {:assert_equal :refute_equal} $_ $_ $_?)
41+ (send nil? {:assert_equal :assert_not_equal : refute_equal} $_ $_ $_?)
4042 PATTERN
4143
4244 # @!method minitest_nil_assertion(node)
4345 def_node_matcher :minitest_nil_assertion , <<~PATTERN
44- (send nil? {:assert_nil :refute_nil} $_ $_?)
46+ (send nil? {:assert_nil :assert_not_nil : refute_nil} $_ $_?)
4547 PATTERN
4648
4749 def on_send ( node )
Original file line number Diff line number Diff line change 4949 RUBY
5050 end
5151
52+ it 'registers an offense when using `assert_not_equal`' do
53+ expect_offense ( <<~RUBY )
54+ assert_not_equal a, b
55+ ^^^^^^^^^^^^^^^^^^^^^ Use `expect(b).not_to eq(a)`.
56+ RUBY
57+
58+ expect_correction ( <<~RUBY )
59+ expect(b).not_to eq(a)
60+ RUBY
61+ end
62+
5263 it 'registers an offense when using `refute_equal`' do
5364 expect_offense ( <<~RUBY )
5465 refute_equal a, b
120131 RUBY
121132 end
122133
134+ it 'registers an offense when using `assert_not_nil`' do
135+ expect_offense ( <<~RUBY )
136+ assert_not_nil a
137+ ^^^^^^^^^^^^^^^^ Use `expect(a).not_to eq(nil)`.
138+ RUBY
139+
140+ expect_correction ( <<~RUBY )
141+ expect(a).not_to eq(nil)
142+ RUBY
143+ end
144+
123145 it 'registers an offense when using `refute_nil`' do
124146 expect_offense ( <<~RUBY )
125147 refute_nil a
You can’t perform that action at this time.
0 commit comments