class RuboCop::Cop::RSpec::ScatteredLet
end
let!(:baz) { 3 }
let(:bar) { 2 }
let(:foo) { 1 }
before { prepare }
subject { Foo }
describe Foo do
# good
end
let!(:baz) { 3 }
before { prepare }
let(:bar) { 2 }
subject { Foo }
let(:foo) { 1 }
describe Foo do
# bad
@example
Group lets together
Checks for let scattered across the example group.
def check_let_declarations(body)
def check_let_declarations(body) lets = body.each_child_node.select { |node| let?(node) } first_let = lets.first lets.each_with_index do |node, idx| next if node.sibling_index == first_let.sibling_index + idx add_offense(node) end end
def on_block(node)
def on_block(node) return unless example_group_with_body?(node) check_let_declarations(node.body) end