File tree 2 files changed +31
-4
lines changed
2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,15 @@ def on_block(node)
45
45
def find_duplicates ( node )
46
46
setup_expressions = Set . new
47
47
node . each_child_node do |child |
48
- setup? ( child ) do
49
- name = one ( child . send_node . arguments ) . value
50
- yield child , name unless setup_expressions . add? ( name )
51
- end
48
+ next unless setup? ( child )
49
+
50
+ name = if child . send_node . arguments?
51
+ child . send_node . first_argument . value
52
+ else
53
+ :subject
54
+ end
55
+
56
+ yield child , name unless setup_expressions . add? ( name )
52
57
end
53
58
end
54
59
end
Original file line number Diff line number Diff line change 22
22
RUBY
23
23
end
24
24
25
+ it 'works with `subject!` and `let!`' do
26
+ expect_offense ( <<-RUBY )
27
+ RSpec.describe User do
28
+ subject!(:a) { a }
29
+
30
+ let!(:a) { b }
31
+ ^^^^^^^^^^^^^^ `a` is already defined.
32
+ end
33
+ RUBY
34
+ end
35
+
25
36
it 'finds `let!` overwriting `let`' do
26
37
expect_offense ( <<-RUBY )
27
38
RSpec.describe User do
44
55
RUBY
45
56
end
46
57
58
+ it 'handles unnamed subjects' do
59
+ expect_offense ( <<-RUBY )
60
+ RSpec.describe User do
61
+ subject { a }
62
+
63
+ let(:subject) { b }
64
+ ^^^^^^^^^^^^^^^^^^^ `subject` is already defined.
65
+ end
66
+ RUBY
67
+ end
68
+
47
69
it 'does not encounter an error when handling an empty describe' do
48
70
expect { inspect_source ( 'RSpec.describe(User) do end' , 'a_spec.rb' ) }
49
71
. not_to raise_error
You can’t perform that action at this time.
0 commit comments