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)

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

Constant Summary collapse

MSG =
'Avoid stubbing using `%<method>s`.'
RESTRICT_ON_SEND =
%i[receive_message_chain stub_chain].freeze

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_send(node) ⇒ Object



20
21
22
23
24
# File 'lib/rubocop/cop/rspec/message_chain.rb', line 20

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