Skip to content

Commit

Permalink
Require VoidExpect operate inside an example block
Browse files Browse the repository at this point in the history
  • Loading branch information
corsonknowles committed Oct 14, 2024
1 parent 961e544 commit 38a6f78
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rubocop/cop/rspec/void_expect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ class VoidExpect < Base

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
Expand All @@ -54,6 +56,10 @@ def void?(expect)

parent.block_type? && parent.body == expect
end

def inside_example?(node)
node.each_ancestor(:block).any? { |ancestor| example?(ancestor) }
end
end
end
end
Expand Down

0 comments on commit 38a6f78

Please sign in to comment.