Class: RuboCop::Cop::RSpec::NotToNot

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

Overview

Checks for consistent method usage for negating expectations.

Examples:

‘EnforcedStyle: not_to` (default)

# bad
it '...' do
  expect(false).to_not be_true
end

# good
it '...' do
  expect(false).not_to be_true
end

‘EnforcedStyle: to_not`

# bad
it '...' do
  expect(false).not_to be_true
end

# good
it '...' do
  expect(false).to_not be_true
end

Constant Summary collapse

MSG =
'Prefer `%<replacement>s` over `%<original>s`.'
RESTRICT_ON_SEND =
%i[not_to to_not].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

#not_to_not_offense(node) ⇒ Object



38
# File 'lib/rubocop/cop/rspec/not_to_not.rb', line 38

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

#on_send(node) ⇒ Object



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

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