Skip to content

Commit 8bb3a46

Browse files
committed
RSpec/VerifiedDoubles: fix detection of nameless doubles
1 parent 812bdfe commit 8bb3a46

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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

lib/rubocop/cop/rspec/verified_doubles.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

spec/rubocop/cop/rspec/verified_doubles_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
RUBY
7575
end
7676

77+
it 'ignores doubles that have no name but methods specified' do
78+
expect_no_offenses(<<~RUBY)
79+
it do
80+
foo = double(call: :bar)
81+
end
82+
RUBY
83+
end
84+
7785
it 'ignores instance_doubles' do
7886
expect_no_offenses(<<~RUBY)
7987
it do

0 commit comments

Comments
 (0)