rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 356 forks source link

Fix `with` for instance doubles didn't verify Ruby 3 keyword arguments #1473

Closed nashbridges closed 2 years ago

nashbridges commented 2 years ago

This is a follow-up to https://github.com/rspec/rspec-mocks/pull/1394.

The change introduced in that PR handle a pure double, but not an instance double.

The reason is that VerifyingMessageExpectation is a subclass of MessageExpectation with with method being overridden. That makes ruby2_keywords definition declared in the superclass to be "dropped" (and therefore to confuse the Hash.ruby2_keywords_hash? check).

I'm not fully sure if this is an expected Ruby behavior, but the current fix is to repeat the definition in the subclass.

nashbridges commented 2 years ago

@pirj thanks for reviewing this!

eregon commented 2 years ago

I'm not fully sure if this is an expected Ruby behavior, but the current fix is to repeat the definition in the subclass.

It is expected, there is no "inheritance" of ruby2_keywords or anything like that, each method which needs to delegate kwargs through *args needs ruby2_keywords.