Class: RuboCop::Cop::RSpec::ScatteredSetup
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, FinalEndLocation
- Defined in:
- lib/rubocop/cop/rspec/scattered_setup.rb
Overview
Checks for setup scattered across multiple hooks in an example group.
Unify ‘before`, `after`, and `around` hooks when possible.
Constant Summary collapse
- MSG =
'Do not define multiple `%<hook_name>s` hooks in the same ' \ 'example group (also defined on %<lines>s).'
Instance Method Summary collapse
-
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler.
Methods included from FinalEndLocation
Methods inherited from Base
inherited, #on_new_investigation
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
rubocop:disable InternalAffairs/NumblockHandler
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/rspec/scattered_setup.rb', line 33 def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless example_group?(node) repeated_hooks(node).each do |occurrences| occurrences.each do |occurrence| = (occurrences, occurrence) add_offense(occurrence, message: ) do |corrector| autocorrect(corrector, occurrences.first, occurrence) end end end end |