[mocha-developer] Beyond multiple return values

Dan North dan at tastapod.com
Fri Mar 9 09:15:03 EST 2007

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).


James Mead wrote:
> On 05/03/07, James Moore <jamesthepiper at gmail.com> wrote:
>> How about saying that if what is passed to returns() is an exception, or a
>> class that's a descendant of Exception, it's raised instead of returned?
>> You could still return an exception by returning it from a lambda.
>> obj.stubs(:save!).returns(RuntimeError.new("testing..."), true)  # Raises,
>> true
>> obj.stubs(:save!).returns(RuntimeError, true) # Raises, true
>> obj.stubs(:save!).returns(lambda {RuntimeError}, true) # returns the
>> exception object, true
> I'm not sure it's so clear what's going to happen in the above cases.
> Adding raises() to TestObject seems a bit intrusive.
> In what way do you think it would be intrusive?

More information about the mocha-developer mailing list