Class: RuboCop::Cop::RSpec::ScatteredLet

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rspec/scattered_let.rb

Overview

Checks for let scattered across the example group.

Group lets together

Examples:

# bad
describe Foo do
  let(:foo) { 1 }
  subject { Foo }
  let(:bar) { 2 }
  before { prepare }
  let!(:baz) { 3 }
end

# good
describe Foo do
  subject { Foo }
  before { prepare }
  let(:foo) { 1 }
  let(:bar) { 2 }
  let!(:baz) { 3 }
end

Constant Summary collapse

MSG =
'Group all let/let! blocks in the example group together.'

Instance Method Summary collapse

Methods inherited from Base

inherited, #on_new_investigation

Methods included from RSpec::Language::NodePattern

#block_pattern, #send_pattern

Instance Method Details

#on_block(node) ⇒ Object


34
35
36
37
38
# File 'lib/rubocop/cop/rspec/scattered_let.rb', line 34

def on_block(node)
  return unless example_group_with_body?(node)

  check_let_declarations(node.body)
end