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

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

Overview

Prefer using verifying doubles over normal doubles.

Examples:

# bad
let(:foo) do
  double(method_name: 'returned value')
end

# bad
let(:foo) do
  double("ClassName", method_name: 'returned value')
end

# good
let(:foo) do
  instance_double("ClassName", method_name: 'returned value')
end

See Also:

Constant Summary collapse

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

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL, RSpec::Language::RSPEC

Instance Method Summary collapse

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#on_send(node) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rubocop/cop/rspec/verified_doubles.rb', line 32

def on_send(node)
  unverified_double(node) do |name, *_args|
    return if name.nil? && cop_config['IgnoreNameless']
    return if symbol?(name) && cop_config['IgnoreSymbolicNames']

    add_offense(node, location: :expression)
  end
end