Class: RuboCop::Cop::RSpec::LetBeforeExamples

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

Overview

Checks for `let` definitions that come after an example.

Examples:

# Bad
let(:foo) { bar }

it 'checks what foo does' do
  expect(foo).to be
end

let(:some) { other }

it 'checks what some does' do
  expect(some).to be
end

# Good
let(:foo) { bar }
let(:some) { other }

it 'checks what foo does' do
  expect(foo).to be
end

it 'checks what some does' do
  expect(some).to be
end

Constant Summary collapse

MSG =
'Move `let` before the examples in the group.'

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


45
46
47
48
49
# File 'lib/rubocop/cop/rspec/let_before_examples.rb', line 45

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

  check_let_declarations(node.body) if multiline_block?(node.body)
end