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 2
2
3
3
## Master (Unreleased)
4
4
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 ] )
6
7
- Fix a false positive for ` RSpec/ExpectActual ` when used with rspec-rails routing matchers. ([ @naveg ] )
7
8
- Add new ` RSpec/RepeatedSubjectCall ` cop. ([ @drcapulet ] )
8
9
Original file line number Diff line number Diff line change @@ -29,19 +29,21 @@ class MinitestAssertions < Base
29
29
MSG = 'Use `%<prefer>s`.'
30
30
RESTRICT_ON_SEND = %i[
31
31
assert_equal
32
+ assert_not_equal
32
33
refute_equal
33
34
assert_nil
35
+ assert_not_nil
34
36
refute_nil
35
37
] . freeze
36
38
37
39
# @!method minitest_equal_assertion(node)
38
40
def_node_matcher :minitest_equal_assertion , <<~PATTERN
39
- (send nil? {:assert_equal :refute_equal} $_ $_ $_?)
41
+ (send nil? {:assert_equal :assert_not_equal : refute_equal} $_ $_ $_?)
40
42
PATTERN
41
43
42
44
# @!method minitest_nil_assertion(node)
43
45
def_node_matcher :minitest_nil_assertion , <<~PATTERN
44
- (send nil? {:assert_nil :refute_nil} $_ $_?)
46
+ (send nil? {:assert_nil :assert_not_nil : refute_nil} $_ $_?)
45
47
PATTERN
46
48
47
49
def on_send ( node )
Original file line number Diff line number Diff line change 49
49
RUBY
50
50
end
51
51
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
+
52
63
it 'registers an offense when using `refute_equal`' do
53
64
expect_offense ( <<~RUBY )
54
65
refute_equal a, b
120
131
RUBY
121
132
end
122
133
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
+
123
145
it 'registers an offense when using `refute_nil`' do
124
146
expect_offense ( <<~RUBY )
125
147
refute_nil a
You can’t perform that action at this time.
0 commit comments