Class: Rubocop::Cop::RSpec::SpecifyExpected

Inherits:
Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Defined in:
lib/rubocop/cop/rspec/specify_expected.rb

Overview

Checks whether ‘specify` is used with `is_expected` and suggests the use of `it`.

Examples:


# bad
specify { is_expected.to eq(true) }

# good
it { is_expected.to eq(true) }

Constant Summary collapse

MSG =
'Prefer using `it` when used with `is_expected`.'
RESTRICT_ON_SEND =
%i[specify].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/rubocop/cop/rspec/specify_expected.rb', line 39

def on_send(node)
  return unless specify_with_expected?(node.parent)

  add_offense(node) do |corrector|
    corrector.replace(node, 'it')
  end
end

#specify_with_expected?(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/rspec/specify_expected.rb', line 26

def_node_matcher :specify_with_expected?, <<~PATTERN
  (block
    (send nil? :specify ...)
    _args
    (send
      (send nil? :is_expected)
      ...
    )
  )
PATTERN