lib/rubocop/cop/rspec/void_expect.rb in rubocop-rspec-3.1.0 vs lib/rubocop/cop/rspec/void_expect.rb in rubocop-rspec-3.2.0

- old
+ new

@@ -27,16 +27,18 @@ (block #expect? (args) _body) PATTERN def on_send(node) return unless expect?(node) + return unless inside_example?(node) check_expect(node) end def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless expect_block?(node) + return unless inside_example?(node) check_expect(node) end private @@ -47,13 +49,16 @@ add_offense(node) end def void?(expect) parent = expect.parent - return true unless parent return true if parent.begin_type? parent.block_type? && parent.body == expect + end + + def inside_example?(node) + node.each_ancestor(:block).any? { |ancestor| example?(ancestor) } end end end end end