Class: RuboCop::Cop::RSpec::EmptyExampleGroup
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- 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.
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
55 56 57 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 55 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
73 74 75 76 77 78 79 80 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 73 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
130 131 132 133 134 135 136 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 130 def_node_matcher :examples?, <<~PATTERN { #examples_directly_or_in_block? (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
111 112 113 114 115 116 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 111 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
97 98 99 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 97 def_node_matcher :examples_inside_block?, <<~PATTERN (block !(send nil? #Hooks.all ...) _ #examples?) PATTERN |
#on_block(node) ⇒ Object
rubocop:disable InternalAffairs/NumblockHandler
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 138 def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return if node.each_ancestor(:def, :defs).any? return if node.each_ancestor(:block).any? { |block| example?(block) } 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 |