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

#example?, #example_group?, #example_group_with_body?, #explicit_rspec?, #hook?, #include?, #let?, #rspec?, #shared_group?, #spec_group?, #subject?

Instance Method Details

#on_block(node) ⇒ Object

rubocop:disable InternalAffairs/NumblockHandler



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

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

  check_let_declarations(node.body)
end