Class: RuboCop::Cop::RSpec::Extra::FlatExamples

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rspec/extra/flat_examples.rb

Overview

Restrict unnecessary nesting by example groups.

Examples:

# bad
context 'when condition' do
  it 'tests something' do
  end
end

# good
it 'tests something when condition' do
end

Constant Summary collapse

MSG =
"Unnecessary nesting by example groups detected."

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



28
29
30
31
32
# File 'lib/rubocop/cop/rspec/extra/flat_examples.rb', line 28

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
  return unless redundant?(node)

  add_offense(node)
end

#redundant?(node) ⇒ Object



24
25
26
# File 'lib/rubocop/cop/rspec/extra/flat_examples.rb', line 24

def_node_matcher :redundant?, "(block (send #rspec? #ExampleGroups.regular ...) _ (block (send _ #Examples.regular ...) ...))\n"