Class: RuboCop::Cop::RSpec::HooksBeforeExamples
- Includes:
- RangeHelp, RSpec::FinalEndLocation
- Defined in:
- lib/rubocop/cop/rspec/hooks_before_examples.rb
Overview
Checks for before/around/after hooks that come after an example.
Constant Summary collapse
- MSG =
'Move `%<hook>s` above the examples in the group.'
Constants inherited from Cop
Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE
Constants included from RSpec::Language
RSpec::Language::ALL, RSpec::Language::RSPEC
Instance Method Summary collapse
Methods included from RSpec::FinalEndLocation
Methods inherited from Cop
Instance Method Details
#autocorrect(node) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/rspec/hooks_before_examples.rb', line 45 def autocorrect(node) lambda do |corrector| first_example = find_first_example(node.parent) first_example_pos = first_example.loc.expression indent = "\n" + ' ' * first_example.loc.column corrector.insert_before(first_example_pos, source(node) + indent) corrector.remove(node_range_with_surrounding_space(node)) end end |
#on_block(node) ⇒ Object
39 40 41 42 43 |
# File 'lib/rubocop/cop/rspec/hooks_before_examples.rb', line 39 def on_block(node) return unless example_group_with_body?(node) check_hooks(node.body) if multiline_block?(node.body) end |