Class: RuboCop::Cop::RSpec::Focus
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rspec/focus.rb
Overview
Checks if examples are focused.
This cop does not support autocorrection in some cases.
Constant Summary collapse
- MSG =
'Focused spec found.'
Instance Method Summary collapse
- #focusable_selector?(node) ⇒ Object
- #focused_block?(node) ⇒ Object
- #metadata(node) ⇒ Object
- #on_send(node) ⇒ Object
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
#focusable_selector?(node) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 59 def_node_matcher :focusable_selector?, <<~PATTERN { #ExampleGroups.regular #ExampleGroups.skipped #Examples.regular #Examples.skipped #Examples.pending #SharedGroups.all } PATTERN |
#focused_block?(node) ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 77 def_node_matcher :focused_block?, <<~PATTERN (send #rspec? {#ExampleGroups.focused #Examples.focused} ...) PATTERN |
#metadata(node) ⇒ Object
71 72 73 74 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 71 def_node_matcher :metadata, <<~PATTERN {(send #rspec? #focusable_selector? <$(sym :focus) ...>) (send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))} PATTERN |
#on_send(node) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 81 def on_send(node) return if node.chained? || node.each_ancestor(:def, :defs).any? (node) do |focus| add_offense(focus) do |corrector| if focus.pair_type? || focus.str_type? || focus.sym_type? corrector.remove(with_surrounding(focus)) elsif focus.send_type? correct_send(corrector, focus) end end end end |