[mocha-developer] Stubbing yielding methods

James Mead jamesmead44 at gmail.com
Fri Sep 21 11:13:13 EDT 2007

I've just been tying my brain in knots looking at bug #8687 (

I've been (1) trying to work out whether there is anything logically wrong
with Mocha's existing behaviour and (2) whether Mocha should support the
requested functionality.

It all centres around the use of the Expectation#yields method. I've put a
couple of examples together to try and help me think about it. The first one
(http://pastie.caboo.se/99412) is a simplified version of the example in the
bug report using a block and stubbing a method that yields to that block.

In the second example (http://pastie.caboo.se/99413) I tried to think about
how it would work if I converted the block to a method on an object. I
slightly ran out of steam on this one when I realised that in this case when
I realised Executor#execute wouldn't be called because the implementation of
Collaborator#yielding_method is stubbed.

This made me wonder if the Expectation#yields method should exist at all! In
particular, in the block example, it feels odd because you are going from
real code (ClassUnderTest) into mock code (mocked version of Collaborator)
and back into real code (the block itself). I wonder if this is really
sensible and/or useful.

Has anybody got any thoughts?


More information about the mocha-developer mailing list