File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ - Fix ` RSpec/VoidExpect ` to only operate inside an example block. ([ @corsonknowles ] )
5
6
- Change ` RSpec/ContextWording ` cop to always report an offense when both ` Prefixes ` and ` AllowedPatterns ` are empty. ([ @ydah ] )
6
7
- Fix an error for ` RSpec/ChangeByZero ` when ` change (...) .by (0) ` and ` change (...) ` , concatenated with ` and ` and ` or ` . ([ @ydah ] )
7
8
Original file line number Diff line number Diff line change @@ -29,12 +29,14 @@ class VoidExpect < Base
29
29
30
30
def on_send ( node )
31
31
return unless expect? ( node )
32
+ return unless inside_example? ( node )
32
33
33
34
check_expect ( node )
34
35
end
35
36
36
37
def on_block ( node ) # rubocop:disable InternalAffairs/NumblockHandler
37
38
return unless expect_block? ( node )
39
+ return unless inside_example? ( node )
38
40
39
41
check_expect ( node )
40
42
end
@@ -49,11 +51,14 @@ def check_expect(node)
49
51
50
52
def void? ( expect )
51
53
parent = expect . parent
52
- return true unless parent
53
54
return true if parent . begin_type?
54
55
55
56
parent . block_type? && parent . body == expect
56
57
end
58
+
59
+ def inside_example? ( node )
60
+ node . each_ancestor ( :block ) . any? { |ancestor | example? ( ancestor ) }
61
+ end
57
62
end
58
63
end
59
64
end
Original file line number Diff line number Diff line change 44
44
end
45
45
RUBY
46
46
end
47
+
48
+ it 'ignores unrelated method named expect in an example block' do
49
+ expect_no_offenses ( <<~RUBY )
50
+ it 'something' do
51
+ MyObject.expect(:foo)
52
+ end
53
+ RUBY
54
+ end
55
+
56
+ context 'when expect has no parent node' do
57
+ it 'does not register an offense' do
58
+ expect_no_offenses ( <<~RUBY )
59
+ expect(something)
60
+ RUBY
61
+ end
62
+
63
+ it 'does not register an offense for unrelated expect with block' do
64
+ expect_no_offenses ( <<~RUBY )
65
+ expect { block_contents }
66
+ RUBY
67
+ end
68
+ end
47
69
end
You can’t perform that action at this time.
0 commit comments