[mocha-developer] Beyond multiple return values

Frederick Cheung fred at 82ask.com
Mon Mar 5 06:37:06 EST 2007


On 5 Mar 2007, at 11:06, James Mead wrote:
>> The same basic method works:
>>
>> lambdas = [lambda {raise 'Foo'}, lambda {return true}]
>> object.stubs(:save!).returns {lambda {lambdas.shift.call}}
>>
>> It's a lot less readable than your average lovely bit of mocha based
>> test.
>>
>> Can anyone think of a way of doing this that looks nice?
>>
>
> Interesting. Perhaps we can at least do this...
>
> object.stubs(:save!).returns(lambda { raise 'Foo' }, true )
>
> Or (if we add a 'raises' method to TestCase)...
>
> object.stubs(:save!).returns(raises(), true)

Someone a little while back proposed added a then() method. It was a  
little more cumbersome than returns(:foo_1, :foo_2) but
object.stubs(:save!).raises('Foo').then.returns(true)
isn't too bad.

Fred


More information about the mocha-developer mailing list