Skip to content

Commit b097f52

Browse files
committed
RSpec/ReturnFromStub Optimize #on_block
1 parent 8423de4 commit b097f52

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/rubocop/cop/rspec/return_from_stub.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ReturnFromStub < Cop
4040
MSG_BLOCK = 'Use block for static values.'
4141

4242
def_node_search :contains_stub?, '(send nil? :receive (...))'
43+
def_node_matcher :stub_with_block?, '(block #contains_stub? ...)'
4344
def_node_search :and_return_value, <<-PATTERN
4445
$(send _ :and_return $(...))
4546
PATTERN
@@ -53,7 +54,7 @@ def on_send(node)
5354

5455
def on_block(node)
5556
return unless style == :and_return
56-
return unless contains_stub?(node)
57+
return unless stub_with_block?(node)
5758

5859
check_block_body(node)
5960
end

0 commit comments

Comments
 (0)