lib/rubocop/cop/rspec/let_before_examples.rb in rubocop-rspec-2.12.1 vs lib/rubocop/cop/rspec/let_before_examples.rb in rubocop-rspec-2.13.0

- old
+ new

@@ -4,11 +4,11 @@ module Cop module RSpec # Checks for `let` definitions that come after an example. # # @example - # # Bad + # # bad # let(:foo) { bar } # # it 'checks what foo does' do # expect(foo).to be # end @@ -17,11 +17,11 @@ # # it 'checks what some does' do # expect(some).to be # end # - # # Good + # # good # let(:foo) { bar } # let(:some) { other } # # it 'checks what foo does' do # expect(foo).to be @@ -41,11 +41,11 @@ #{block_pattern('{#ExampleGroups.all #Examples.all}')} #{send_pattern('#Includes.examples')} } PATTERN - def on_block(node) + def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler return unless example_group_with_body?(node) check_let_declarations(node.body) if multiline_block?(node.body) end @@ -57,15 +57,14 @@ def check_let_declarations(node) first_example = find_first_example(node) return unless first_example - node.each_child_node do |child| - next if child.sibling_index < first_example.sibling_index - next unless let?(child) + first_example.right_siblings.each do |sibling| + next unless let?(sibling) - add_offense(child) do |corrector| - autocorrect(corrector, child, first_example) + add_offense(sibling) do |corrector| + autocorrect(corrector, sibling, first_example) end end end def find_first_example(node)