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`.'
RESTRICT_ON_SEND =
%i[never].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

#method_on_stub?(node) ⇒ Object



21
# File 'lib/rubocop/cop/rspec/receive_never.rb', line 21

def_node_search :method_on_stub?, '(send nil? :receive ...)'

#on_send(node) ⇒ Object



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

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