lib/rubocop/cop/rspec/receive_counts.rb in rubocop-rspec-1.31.0 vs lib/rubocop/cop/rspec/receive_counts.rb in rubocop-rspec-1.32.0

- old
+ new

@@ -28,12 +28,16 @@ def_node_matcher :receive_counts, <<-PATTERN (send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times) PATTERN + def_node_search :stub?, '(send nil? :receive ...)' + def on_send(node) receive_counts(node) do |offending_node| + return unless stub?(offending_node.receiver) + offending_range = range(node, offending_node) add_offense( offending_node, message: message_for(offending_node, offending_range.source), @@ -46,13 +50,12 @@ lambda do |corrector| replacement = matcher_for( node.method_name, node.first_argument.source.to_i ) - corrector.replace( - range(node.parent, node), - replacement - ) + + original = range(node.parent, node) + corrector.replace(original, replacement) end end private