Class: RuboCop::Cop::RSpec::ItBehavesLike

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ConfigurableEnforcedStyle
Defined in:
lib/rubocop/cop/rspec/it_behaves_like.rb

Overview

Checks that only one ‘it_behaves_like` style is used.

Examples:

‘EnforcedStyle: it_behaves_like` (default)

# bad
it_should_behave_like 'a foo'

# good
it_behaves_like 'a foo'

‘EnforcedStyle: it_should_behave_like`

# bad
it_behaves_like 'a foo'

# good
it_should_behave_like 'a foo'

Constant Summary collapse

MSG =
'Prefer `%<replacement>s` over `%<original>s` when including ' \
'examples in a nested context.'
RESTRICT_ON_SEND =
%i[it_behaves_like it_should_behave_like].freeze

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_or_numblock_pattern, #block_pattern, #numblock_pattern, #send_pattern

Methods included from RSpec::Language

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#example_inclusion_offense(node) ⇒ Object



31
# File 'lib/rubocop/cop/rspec/it_behaves_like.rb', line 31

def_node_matcher :example_inclusion_offense, '(send _ % ...)'

#on_send(node) ⇒ Object



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

def on_send(node)
  example_inclusion_offense(node, alternative_style) do
    add_offense(node) do |corrector|
      corrector.replace(node.loc.selector, style.to_s)
    end
  end
end