rspec/rspec-mocks — pull request #221 by myronmarston (2013-02-05 07:06:00+00:00)
Title: Use the matching parent stub rather than just picking the first one.

Previously, when a mock expectation was added, it was derived as a
child stub from the first existing stub. However, if there were multiple
existing stubs constrained with different `with` criteria, this could
cause it to pick the wrong one because it arbitrarily chose the first
one.

Our fix is to defer the choosing of the parent stub until the message
expectation is invoked, at which point we can properly match the
parent stub based on the arguments.

As part of this, I've refactored MessageExpectation, extracting a new
MessageImplementation class to hold the logic for an implementation
based on `and_return` and `and_yield` declarations.

Fixes #127.

@dchelimsky / @alindeman -- can one or both of you review this? This is a large enough change that it has the potential to introduce regressions (although, all specs pass, of course). If either of you can think of a simpler/better fix, please let me know!