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.'.freeze
DOUBLE_TYPES =
[:double, :spy].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/rubocop/cop/rspec/verified_doubles.rb', line 24

def on_send(node)
  _receiver, method_name, *args = *node
  name, *_stubs = *args
  return unless DOUBLE_TYPES.include?(method_name)
  return if name.nil?
  return if name_is_symbol?(name) && cop_config['IgnoreSymbolicNames']
  add_offense(node,
              :expression,
              format(MSG, node.loc.expression.source))
end