class RuboCop::Cop::RSpec::NestedGroups


end
end
end
context ‘bar’ do # <– nested groups 2
path ‘/foo’ do # <– nested groups 1 (not counted)
describe Foo do # <– nested groups 1
@example ‘AllowedGroups: [path]`
end
end
end
context ’bar’ do # <– nested groups 3
context ‘foo’ do # <– nested groups 2
describe Foo do # <– nested groups 1
@example ‘AllowedGroups: [] (default)`
end
end
end
end
context ’baz’ do # flagged by rubocop
context ‘bar’ do # flagged by rubocop
context ‘foo’ do
describe Foo do
# bad
@example ‘Max: 2`
end
end
end
end
context ’baz’ do # flagged by rubocop
context ‘bar’ do
context ‘foo’ do
describe Foo do
# bad
@example ‘Max: 3` (default)
end
it ’yada yada’
it ‘blah blah’
end
)
role: ‘admin’
age: 22,
name: ‘John’,
UserCreate.call(
let(:user) do
let(:feature) { :setup }
let(:some) { :various }
context ‘using some feature as an admin’ do
# good
end
end
end
it ‘yada yada’
it ‘blah blah’
let(:role) { ‘admin’ }
context ‘when user is an admin’ do # flagged by rubocop
end
}
role: role
age: 22,
name: ‘John’,
{
let(:user_attributes) do
end
UserCreate.call(user_attributes)
let(:user) do
context ‘when user is signed in’ do # flagged by rubocop
let(:feature) { :setup }
let(:some) { :various }
context ‘when using some feature’ do
# bad
@example
and supports ‘–auto-gen-config`.
This cop is configurable using the `Max` option
Checks for nested example groups.

def allowed_groups

def allowed_groups
  @allowed_groups ||= cop_config.fetch('AllowedGroups', [])
end

def count_up_nesting?(node, example_group)

def count_up_nesting?(node, example_group)
  example_group &&
    node.block_type? &&
    !allowed_groups.include?(node.method_name.to_s)
end

def find_nested_example_groups(node, nesting: 1, &block)

def find_nested_example_groups(node, nesting: 1, &block)
  example_group = example_group?(node)
  yield node, nesting if example_group && nesting > max_nesting
  next_nesting = if count_up_nesting?(node, example_group)
                   nesting + 1
                 else
                   nesting
                 end
  node.each_child_node(:block, :begin) do |child|
    find_nested_example_groups(child, nesting: next_nesting, &block)
  end
end

def max_nesting

def max_nesting
  @max_nesting ||= Integer(max_nesting_config)
end

def max_nesting_config

def max_nesting_config
  if cop_config.key?(DEPRECATED_MAX_KEY)
    warn DEPRECATION_WARNING
    cop_config.fetch(DEPRECATED_MAX_KEY)
  else
    cop_config.fetch('Max', 3)
  end
end

def message(nesting)

def message(nesting)
  format(MSG, total: nesting, max: max_nesting)
end

def on_top_level_group(node)

def on_top_level_group(node)
  find_nested_example_groups(node) do |example_group, nesting|
    self.max = nesting
    add_offense(
      example_group.send_node,
      message: message(nesting)
    )
  end
end