Skip to content

Commit 36b5c77

Browse files
authored
Merge pull request #945 from andrykonchin/optimize-performance-return-from-stub
Performance. RSpec/ReturnFromStub
2 parents fad3387 + b097f52 commit 36b5c77

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/rubocop/cop/rspec/return_from_stub.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,21 @@ 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
4647

4748
def on_send(node)
48-
return unless contains_stub?(node)
4949
return unless style == :block
50+
return unless contains_stub?(node)
5051

5152
check_and_return_call(node)
5253
end
5354

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

5859
check_block_body(node)
5960
end

0 commit comments

Comments
 (0)