File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 33## Master (Unreleased)
44
55- Add new cop ` RSpec/LeakyLocalVariable ` . ([ @lovro-bikic ] )
6+ - Fix detection of nameless doubles with methods in ` RSpec/VerifiedDoubles ` . ([ @ushi-as ] )
67
78## 3.7.0 (2025-09-01)
89
@@ -1079,6 +1080,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
10791080[ @tmaier ] : https://github.com/tmaier
10801081[ @topalovic ] : https://github.com/topalovic
10811082[ @twalpole ] : https://github.com/twalpole
1083+ [ @ushi-as ] : https://github.com/ushi-as
10821084[ @vzvu3k6k ] : https://github.com/vzvu3k6k
10831085[ @walf443 ] : https://github.com/walf443
10841086[ @yasu551 ] : https://github.com/yasu551
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class VerifiedDoubles < Base
3434
3535 def on_send ( node )
3636 unverified_double ( node ) do |name , *_args |
37- return if name . nil? && cop_config [ 'IgnoreNameless' ]
37+ return if ( name . nil? || hash? ( name ) ) && cop_config [ 'IgnoreNameless' ]
3838 return if symbol? ( name ) && cop_config [ 'IgnoreSymbolicNames' ]
3939
4040 add_offense ( node )
@@ -46,6 +46,10 @@ def on_send(node)
4646 def symbol? ( name )
4747 name &.sym_type?
4848 end
49+
50+ def hash? ( arg )
51+ arg &.hash_type?
52+ end
4953 end
5054 end
5155 end
Original file line number Diff line number Diff line change 6464 end
6565 RUBY
6666 end
67+
68+ it 'flags doubles that have no name but methods specified' do
69+ expect_offense ( <<~RUBY )
70+ it do
71+ foo = double(call: :bar)
72+ ^^^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
73+ end
74+ RUBY
75+ end
6776 end
6877
6978 it 'ignores doubles that have no name specified' do
7483 RUBY
7584 end
7685
86+ it 'ignores doubles that have no name but methods specified' do
87+ expect_no_offenses ( <<~RUBY )
88+ it do
89+ foo = double(call: :bar)
90+ end
91+ RUBY
92+ end
93+
7794 it 'ignores instance_doubles' do
7895 expect_no_offenses ( <<~RUBY )
7996 it do
You can’t perform that action at this time.
0 commit comments