Class: RuboCop::Cop::RSpec::VerifiedDoubles

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/rspec/verified_doubles.rb

Overview

Prefer using verifying doubles over normal doubles. see: relishapp.com/rspec/rspec-mocks/docs/verifying-doubles

Examples:

# bad
it '...' do
  widget = double("Widget")
end

# good
it '...' do
  widget = instance_double("Widget")
end

Constant Summary collapse

MSG =
'Prefer using verifying doubles over normal doubles.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object


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

def on_send(node)
  _receiver, method_name, *_args = *node
  return unless method_name == :double
  add_offense(node,
              :expression,
              format(MSG, node.loc.expression.source))
end