Class: RuboCop::Cop::RSpec::ReceiveNever

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rspec/receive_never.rb

Overview

Prefer `not_to receive(…)` over `receive(…).never`.

Examples:


# bad
expect(foo).to receive(:bar).never

# good
expect(foo).not_to receive(:bar)

Constant Summary collapse

MSG =
'Use `not_to receive` instead of `never`.'

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


22
23
24
25
26
27
28
# File 'lib/rubocop/cop/rspec/receive_never.rb', line 22

def on_send(node)
  return unless node.method?(:never) && method_on_stub?(node)

  add_offense(node.loc.selector) do |corrector|
    autocorrect(corrector, node)
  end
end