lib/rubocop/cop/rspec/nested_groups.rb in rubocop-rspec-1.24.0 vs lib/rubocop/cop/rspec/nested_groups.rb in rubocop-rspec-1.25.0
- old
+ new
@@ -4,10 +4,11 @@
module Cop
module RSpec
# Checks for nested example groups.
#
# This cop is configurable using the `Max` option
+ # and supports `--auto-gen-config
#
# @example
# # bad
# context 'when using some feature' do
# let(:some) { :various }
@@ -53,12 +54,12 @@
# end
#
# @example configuration
#
# # .rubocop.yml
- # RSpec/NestedGroups:
- # Max: 2
+ # # RSpec/NestedGroups:
+ # # Max: 2
#
# context 'when using some feature' do
# let(:some) { :various }
# let(:feature) { :setup }
#
@@ -68,11 +69,11 @@
# end
#
# let(:user_attributes) do
# {
# name: 'John',
- # age: 22
+ # age: 22,
# role: role
# }
# end
#
# context 'when user is an admin' do # flagged by rubocop
@@ -83,10 +84,11 @@
# end
# end
# end
#
class NestedGroups < Cop
+ include ConfigurableMax
include RuboCop::RSpec::TopLevelDescribe
MSG = 'Maximum example group nesting exceeded ' \
'[%<total>d/%<max>d].'.freeze
@@ -98,9 +100,10 @@
def_node_search :find_contexts, ExampleGroups::ALL.block_pattern
def on_top_level_describe(node, _args)
find_nested_contexts(node.parent) do |context, nesting|
+ self.max = nesting
add_offense(
context.children.first,
location: :expression,
message: message(nesting)
)