lib/rubocop/cop/rspec/overwriting_setup.rb in rubocop-rspec-1.21.0 vs lib/rubocop/cop/rspec/overwriting_setup.rb in rubocop-rspec-1.22.0
- old
+ new
@@ -5,36 +5,34 @@
module RSpec
# Checks if there is a let/subject that overwrites an existing one.
#
# @example
# # bad
- # let(:foo) { bar }
- # let(:foo) { baz }
+ # let(:foo) { bar }
+ # let(:foo) { baz }
#
- # subject(:foo) { bar }
- # let(:foo) { baz }
+ # subject(:foo) { bar }
+ # let(:foo) { baz }
#
- # let(:foo) { bar }
- # let!(:foo) { baz }
+ # let(:foo) { bar }
+ # let!(:foo) { baz }
#
# # good
- # subject(:test) { something }
- # let(:foo) { bar }
- # let(:baz) { baz }
- # let!(:other) { other }
+ # subject(:test) { something }
+ # let(:foo) { bar }
+ # let(:baz) { baz }
+ # let!(:other) { other }
class OverwritingSetup < Cop
MSG = '`%<name>s` is already defined.'.freeze
def_node_matcher :setup?, <<-PATTERN
(block (send nil? {:let :let! :subject} (sym $_)) ...)
PATTERN
def on_block(node)
return unless example_group_with_body?(node)
- _describe, _args, body = *node
-
- find_duplicates(body) do |duplicate, name|
+ find_duplicates(node.body) do |duplicate, name|
add_offense(
duplicate,
location: :expression,
message: format(MSG, name: name)
)