freerange / mocha

A mocking and stubbing library for Ruby
https://mocha.jamesmead.org
Other
1.23k stars 158 forks source link

Investigate rationalising Configuration.stubbing_non_existent_method= & Mock#responds_like #531

Open floehopper opened 2 years ago

floehopper commented 2 years ago

While investigating #149 I realised that there's some overlap between the behaviour controlled by Configuration.stubbing_non_existent_method= and the responder-related behaviour controlled by Mock#responds_like & Mock#responds_like_instance_of.

The configuration check

The responder check

I'm not entirely sure why we can't just use Object#respond_to? with include_all set to true in both cases. It would be worth making this change and seeing if any (acceptance) tests fail.

If we can use the same check for both, it would then be worth considering only making the check in one place. My inclination is to do this at stubbing time which I think is what RSpec does. However, note that the current implementation in Mockery.on_stubbing only seems to be triggered for partial mocks (i.e. from ObjectMethods#expects & ObjectMethods#stubs), so we'd need to change that to make it work for mock objects with a responder.

floehopper commented 2 years ago

See also #580 & #583.