class RuboCop::Cop::RSpec::NestedGroups
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
let(:feature) { :setup }
let(:some) { :various }
context ‘when using some feature’ do
Max: 2
RSpec/NestedGroups:
# .rubocop.yml
@example configuration
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
# better
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
This cop is configurable using the ‘Max` option
Checks for nested example groups.
def find_nested_contexts(node, nesting: 1, &block)
def find_nested_contexts(node, nesting: 1, &block) find_contexts(node) do |nested_context| yield(nested_context, nesting) if nesting > max_nesting nested_context.each_child_node do |child| find_nested_contexts(child, nesting: nesting + 1, &block) end 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, nesting, max_nesting) end
def on_top_level_describe(node, _)
def on_top_level_describe(node, _) find_nested_contexts(node.parent) do |context, nesting| add_offense(context.children.first, :expression, message(nesting)) end end