Class: RuboCop::Cop::RSpec::ExpectActual

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

Overview

Checks for ‘expect(…)` calls containing literal values.

Examples:

# bad
expect(5).to eq(price)
expect(/foo/).to eq(pattern)
expect("John").to eq(name)

# good
expect(price).to eq(5)
expect(pattern).to eq(/foo/)
expect(name).to eq("John")

Constant Summary collapse

MSG =
'Provide the actual you are testing to `expect(...)`.'
SIMPLE_LITERALS =
%i[
  true
  false
  nil
  int
  float
  str
  sym
  complex
  rational
  regopt
].freeze
COMPLEX_LITERALS =
%i[
  array
  hash
  pair
  irange
  erange
  regexp
].freeze

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



46
47
48
49
50
# File 'lib/rubocop/cop/rspec/expect_actual.rb', line 46

def on_send(node)
  expect_literal(node) do |argument|
    add_offense(argument, location: :expression)
  end
end