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?, "{\n #ExampleGroups.regular\n #ExampleGroups.skipped\n #Examples.regular\n #Examples.skipped\n #Examples.pending\n #SharedGroups.all\n}\n" |
#focused_block?(node) ⇒ Object
77 78 79 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 77 def_node_matcher :focused_block?, "(send #rspec? {#ExampleGroups.focused #Examples.focused} ...)\n" |
#metadata(node) ⇒ Object
71 72 73 74 |
# File 'lib/rubocop/cop/rspec/focus.rb', line 71 def_node_matcher :metadata, "{(send #rspec? #focusable_selector? <$(sym :focus) ...>)\n (send #rspec? #focusable_selector? ... (hash <$(pair (sym :focus) true) ...>))}\n" |
#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 |