Class: RuboCop::Cop::RSpec::EmptyExampleGroup
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, InsideExample
- Defined in:
- lib/rubocop/cop/rspec/empty_example_group.rb
Overview
Checks if an example group does not include any tests.
Constant Summary collapse
- MSG =
'Empty example group detected.'
Instance Method Summary collapse
-
#example_group_body(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match example group blocks and yield their body.
-
#example_or_group_or_include?(node) ⇒ Array<RuboCop::AST::Node>
Match examples, example groups and includes.
-
#examples?(node) ⇒ Array<RuboCop::AST::Node>
Matches examples defined in scopes where they could run.
-
#examples_directly_or_in_block?(node) ⇒ Array<RuboCop::AST::Node>
Match examples or examples inside blocks.
-
#examples_inside_block?(node) ⇒ Array<RuboCop::AST::Node>
Match examples defined inside a block which is not a hook.
-
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler.
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
#example_group_body(node) {|RuboCop::AST::Node| ... } ⇒ Object
Match example group blocks and yield their body
56 57 58 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 56 def_node_matcher :example_group_body, <<~PATTERN (block (send #rspec? #ExampleGroups.all ...) args $_) PATTERN |
#example_or_group_or_include?(node) ⇒ Array<RuboCop::AST::Node>
Match examples, example groups and includes
74 75 76 77 78 79 80 81 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 74 def_node_matcher :example_or_group_or_include?, <<~PATTERN { (block (send #rspec? {#Examples.all #ExampleGroups.all #Includes.all} ...) ...) (send nil? {#Examples.all #Includes.all} ...) } PATTERN |
#examples?(node) ⇒ Array<RuboCop::AST::Node>
Matches examples defined in scopes where they could run
131 132 133 134 135 136 137 138 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 131 def_node_matcher :examples?, <<~PATTERN { #examples_directly_or_in_block? #examples_in_branches? (begin <#examples_directly_or_in_block? ...>) (begin <#examples_in_branches? ...>) } PATTERN |
#examples_directly_or_in_block?(node) ⇒ Array<RuboCop::AST::Node>
Match examples or examples inside blocks
112 113 114 115 116 117 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 112 def_node_matcher :examples_directly_or_in_block?, <<~PATTERN { #example_or_group_or_include? #examples_inside_block? } PATTERN |
#examples_inside_block?(node) ⇒ Array<RuboCop::AST::Node>
Match examples defined inside a block which is not a hook
98 99 100 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 98 def_node_matcher :examples_inside_block?, <<~PATTERN (block !(send nil? #Hooks.all ...) _ #examples?) PATTERN |
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 140 def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler return if node.each_ancestor(:any_def).any? return if inside_example?(node) example_group_body(node) do |body| next unless offensive?(body) add_offense(node.send_node) do |corrector| corrector.remove(removed_range(node)) end end end |