lib/rubocop/cop/rspec/overwriting_setup.rb in rubocop-rspec-1.25.1 vs lib/rubocop/cop/rspec/overwriting_setup.rb in rubocop-rspec-1.26.0

- old
+ new

@@ -20,15 +20,15 @@ # subject(:test) { something } # let(:foo) { bar } # let(:baz) { baz } # let!(:other) { other } class OverwritingSetup < Cop + include RuboCop::RSpec::Util + MSG = '`%<name>s` is already defined.'.freeze - def_node_matcher :setup?, <<-PATTERN - (block (send nil? {:let :let! :subject} (sym $_)) ...) - PATTERN + def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern def on_block(node) return unless example_group_with_body?(node) find_duplicates(node.body) do |duplicate, name| @@ -43,12 +43,18 @@ private def find_duplicates(node) setup_expressions = Set.new node.each_child_node do |child| - setup?(child) do |name| - yield child, name unless setup_expressions.add?(name) - end + next unless setup?(child) + + name = if child.send_node.arguments? + child.send_node.first_argument.value + else + :subject + end + + yield child, name unless setup_expressions.add?(name) end end end end end