diff --git a/lib/rubocop/cop/rspec/nested_groups.rb b/lib/rubocop/cop/rspec/nested_groups.rb index cda5b5223..2193d0720 100644 --- a/lib/rubocop/cop/rspec/nested_groups.rb +++ b/lib/rubocop/cop/rspec/nested_groups.rb @@ -110,9 +110,10 @@ def on_top_level_describe(node, _args) private def find_nested_example_groups(node, nesting: 1, &block) - yield node, nesting if example_group?(node) && nesting > max_nesting + example_group = example_group?(node) + yield node, nesting if example_group && nesting > max_nesting - next_nesting = example_group?(node) ? nesting + 1 : nesting + next_nesting = example_group ? nesting + 1 : nesting node.each_child_node do |child| find_nested_example_groups(child, nesting: next_nesting, &block)