Class: RuboCop::Cop::RSpec::MessageChain

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/message_chain.rb

Overview

Check that chains of messages are not being stubbed.

Examples:

# bad
allow(foo).to receive_message_chain(:bar, :baz).and_return(42)

# better
thing = Thing.new(baz: 42)
allow(foo).to receive(:bar).and_return(thing)

Constant Summary collapse

MSG =
'Avoid stubbing using `%<method>s`.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_send(node) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/rspec/message_chain.rb', line 23

def on_send(node)
  message_chain(node) do
    add_offense(
      node.loc.selector,
      message: format(MSG, method: node.method_name)
    )
  end
end