[mocha-developer] Beyond multiple return values

James Moore jamesthepiper at gmail.com
Fri Mar 9 18:38:53 EST 2007

On 3/9/07, Dan North <dan at tastapod.com> wrote:
> I have to agree with James - I'm not a fan of returns changing its
> behaviour based on the return type. What if I'm writing an exceptions
> factory, or some sort of exception processor (say something to log parts
> of a stack trace)?
> I'm happy with .returns(quietly) and .raises(mayhem).

It does already, though.  For example, there's not a clean way to mock
something that returns closures, which is probably more common than
something that returns exceptions.  If returns() is given something that
happens to be a lambda, it doesn't return the lambda (which is what you'd
normally expect), it calls it and returns its value instead.  I'm just
suggesting adding to that concept:

case return_value
when its a Proc: call the proc, return the result # Existing behavior
when its an Exception, or an instance of an exception, raise it # Additional
else return return_value

I do see your point though - I'm not convinced this is worth arguing
strongly for, but I do think it fits well with the current code.

 - James Moore

More information about the mocha-developer mailing list