Closed andrykonchin closed 2 years ago
The similar situation with
expect(a).to receive(:foo).with(1, 2, c: 3)
a.foo(1, 2, {c: 3})
(actual argument - Hash, expected - keyword argument)
Such test successfully passes.
Just by looking at those specs, do you think something is incorrect?
I tend to agree with what you say:
$ rvm use 3.0.1
$ irb
def x(a, b, c:)
puts [a,b,c]
end
x(1, 2, {c:3})
ArgumentError: wrong number of arguments (given 3, expected 2; required keyword: c)
Would you like to send a PR to fix this case, or at least with failing examples?
Ah, I see. Thank you.
Yes, I will try to find a workaround and create a PR.
Looks like the issue is already fixed by https://github.com/rspec/rspec-mocks/pull/1473 on the main branch.
Thank you.
Subject of the issue
It's more a question and not an issue.
It seems to me that argument expectation (with
with
method) is too permissive and allows expecting successfully a Hash argument when actual is a keyword argument.Your environment
Steps to reproduce
Expected behavior
The test should fail because the last expected argument is a Hash, but the actual last argument is a keyword argument.
Actual behavior
The test passes successfully: