3.10.3 breaks hash argument matching in Ruby 3+
Created by: alextwoods
Subject of the issue
With rspec-mocks 3.10.3 we started seeing test failures in our CI: Previously passing run - fails now with rspec mocks 3.10.3 for ruby 3+. (Note, passes with rspec-mocks 3.10.2).
I believe the change in behavior is related to #1394.
Note: This issue is similar to #1457 but applies to a slightly different case
Your environment
- Ruby version: 3.0.2
- rspec-mocks version: 3.10.3
Steps to reproduce
class TestObject
def initialize(object)
@object = object
end
def foo(arg, options={})
@object.foo(arg, options)
end
end
describe 'rspec-mocks 3.10.3' do
# This code passes in Ruby 2.7, but fails on Ruby 3.
# Note: this test passes on Ruby 3 w/ rspec-mocks 3.10.2
it 'breaks in ruby 3.0' do
object = double('object')
t = TestObject.new(object)
expect(object).to receive(:foo).with('arg', opt: 'value')
t.foo('arg', opt: 'value')
end
# This is the issue from: #1457
# this code passes in ruby 3
it 'breaks in ruby 2.7' do
obj = Object.new
expect(obj).to receive(:call).with(:foo, **{})
obj.call(:foo, **{})
end
end
The above tests can be fixed by either:
- Changing the spec to:
with('arg', {opt: 'value'})
- Or changing the code to use the double splat:
@object.foo(arg, **options)
Expected behavior
Tests that pass in 3.10.2 should pass in 3.10.3.
Actual behavior
Some tests fail.