Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Bump RuboCop requirement to +1.81. ([@ydah])
- Fix a false positive for `RSpec/LetSetup` when `let!` used in outer scope. ([@ydah])
- Fix a false positive for `RSpec/ReceiveNever` cop when `allow(...).to receive(...).never`. ([@ydah])
- Fix detection of nameless doubles with methods in `RSpec/VerifiedDoubles`. ([@ushi-as])

## 3.7.0 (2025-09-01)

Expand Down Expand Up @@ -1082,6 +1083,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
[@tmaier]: https://github.com/tmaier
[@topalovic]: https://github.com/topalovic
[@twalpole]: https://github.com/twalpole
[@ushi-as]: https://github.com/ushi-as
[@vzvu3k6k]: https://github.com/vzvu3k6k
[@walf443]: https://github.com/walf443
[@yasu551]: https://github.com/yasu551
Expand Down
6 changes: 5 additions & 1 deletion lib/rubocop/cop/rspec/verified_doubles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class VerifiedDoubles < Base

def on_send(node)
unverified_double(node) do |name, *_args|
return if name.nil? && cop_config['IgnoreNameless']
return if (name.nil? || hash?(name)) && cop_config['IgnoreNameless']
return if symbol?(name) && cop_config['IgnoreSymbolicNames']

add_offense(node)
Expand All @@ -90,6 +90,10 @@ def on_send(node)
def symbol?(name)
name&.sym_type?
end

def hash?(arg)
arg.hash_type?
end
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions spec/rubocop/cop/rspec/verified_doubles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
end
RUBY
end

it 'flags doubles that have no name but methods specified' do
expect_offense(<<~RUBY)
it do
foo = double(call: :bar)
^^^^^^^^^^^^^^^^^^ Prefer using verifying doubles over normal doubles.
end
RUBY
end
end

it 'ignores doubles that have no name specified' do
Expand All @@ -74,6 +83,14 @@
RUBY
end

it 'ignores doubles that have no name but methods specified' do
expect_no_offenses(<<~RUBY)
it do
foo = double(call: :bar)
end
RUBY
end

it 'ignores instance_doubles' do
expect_no_offenses(<<~RUBY)
it do
Expand Down