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

Inherits:
RuboCop::Cop show all
Includes:
RSpec::SpecOnly
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(...)`'.freeze
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 included from RSpec::SpecOnly

RSpec::SpecOnly::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods included from RSpec::SpecOnly

#relevant_file?

Instance Method Details

#on_send(node) ⇒ Object



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

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