Class: RuboCop::Cop::RSpec::EmptyExampleGroup
- 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
Methods inherited from Base
inherited, #on_new_investigation
Methods included from RSpec::Language::NodePattern
Methods included from RSpec::Language
#example?, #example_group?, #example_group_with_body?, #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
51 52 53 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 51 def_node_matcher :example_group_body, <<~PATTERN (block #{send_pattern('#ExampleGroups.all')} args $_) PATTERN |
#example_or_group_or_include?(node) ⇒ Array<RuboCop::AST::Node>
Match examples, example groups and includes
69 70 71 72 73 74 75 76 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 69 def_node_matcher :example_or_group_or_include?, <<~PATTERN { #{block_pattern( '{#Examples.all #ExampleGroups.all #Includes.all}' )} #{send_pattern('{#Examples.all #Includes.all}')} } PATTERN |
#examples?(node) ⇒ Array<RuboCop::AST::Node>
Matches examples defined in scopes where they could run
126 127 128 129 130 131 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 126 def_node_matcher :examples?, <<~PATTERN { #examples_directly_or_in_block? (begin <#examples_directly_or_in_block? ...>) } PATTERN |
#examples_directly_or_in_block?(node) ⇒ Array<RuboCop::AST::Node>
Match examples or examples inside blocks
107 108 109 110 111 112 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 107 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
93 94 95 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 93 def_node_matcher :examples_inside_block?, <<~PATTERN (block !#{send_pattern('#Hooks.all')} _ #examples?) PATTERN |
#on_block(node) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/rubocop/cop/rspec/empty_example_group.rb', line 133 def on_block(node) return if node.each_ancestor(:def, :defs).any? return if node.each_ancestor(:block).any? { |block| example?(block) } example_group_body(node) do |body| add_offense(node.send_node) if offensive?(body) end end |