Class: RuboCop::Cop::RSpec::RedundantAround

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

Overview

Remove redundant ‘around` hook.

Examples:

# bad
around do |example|
  example.run
end

# good

Constant Summary collapse

MSG =
'Remove redundant `around` hook.'
RESTRICT_ON_SEND =
%i[around].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

#on_block(node) ⇒ Object Also known as: on_numblock



23
24
25
26
27
28
29
# File 'lib/rubocop/cop/rspec/redundant_around.rb', line 23

def on_block(node)
  return unless match_redundant_around_hook_block?(node)

  add_offense(node) do |corrector|
    autocorrect(corrector, node)
  end
end

#on_send(node) ⇒ Object



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

def on_send(node)
  return unless match_redundant_around_hook_send?(node)

  add_offense(node) do |corrector|
    autocorrect(corrector, node)
  end
end