Sha256: 4909884d2857db1902159d2ce3dbce935a8c1921c00a9c4360bb345ba3a90fe6
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Checks for let scattered across the example group. # # Group lets together # # @example # # 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 # class ScatteredLet < Cop MSG = 'Group all let/let! blocks in the example group together.'.freeze def_node_matcher :let?, Helpers::ALL.block_pattern def on_block(node) return unless example_group_with_body?(node) check_let_declarations(node.body) end private 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, location: :expression) end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.27.0 | lib/rubocop/cop/rspec/scattered_let.rb |
rubocop-rspec-1.26.0 | lib/rubocop/cop/rspec/scattered_let.rb |