lib/rubocop/cop/rspec/message_chain.rb in rubocop-rspec-1.12.0 vs lib/rubocop/cop/rspec/message_chain.rb in rubocop-rspec-1.13.0
- old
+ new
@@ -10,16 +10,19 @@
# # better
# thing = Thing.new(baz: 42)
# allow(foo).to receive(bar: thing)
#
class MessageChain < Cop
- MESSAGE = 'Avoid stubbing using `%<method>s`'.freeze
+ MSG = 'Avoid stubbing using `%<method>s`.'.freeze
+ def_node_matcher :message_chain, Matchers::MESSAGE_CHAIN.send_pattern
+
def on_send(node)
- _receiver, method_name, *_args = *node
- return unless Matchers::MESSAGE_CHAIN.include?(method_name)
+ message_chain(node) { add_offense(node, :selector) }
+ end
- add_offense(node, :selector, format(MESSAGE, method: method_name))
+ def message(node)
+ format(MSG, method: node.method_name)
end
end
end
end
end