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
and supports ‘–auto-gen-config`.
This cop is configurable using the `Max` option
Checks for nested example groups.
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 = example_group ? nesting + 1 : nesting 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