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

Inherits:
Cop
  • 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: thing)

Constant Summary collapse

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

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION

Constants included from RSpec::Language

RSpec::Language::ALL

Instance Method Summary collapse

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#message(node) ⇒ Object



23
24
25
# File 'lib/rubocop/cop/rspec/message_chain.rb', line 23

def message(node)
  format(MSG, method: node.method_name)
end

#on_send(node) ⇒ Object



19
20
21
# File 'lib/rubocop/cop/rspec/message_chain.rb', line 19

def on_send(node)
  message_chain(node) { add_offense(node, :selector) }
end