[mocha-developer] Expect with "real world" returns?

Justin Reagor justinwr at gmail.com
Wed May 21 16:51:23 EDT 2008


> So this is not really mocking, just setting expectations about what  
> will be called and with what arguments.


Isn't that the current functionality though?

If I do a...

Model.expects(:find).with(:all, {:conditions => ['id = ?',  
1]}).returns(@model)

I get the arguments tested because Model.find(:all) would fail and  
tell me I forgot the :conditions hash.

Now I do understand that the return value would not be tested by  
Mocha against what I provided... but if I'm testing return values I  
would just do.

@model.should_not be_nil

:: Justin Reagor
:: justinwr at gmail.com



On May 21, 2008, at 4:35 PM, Carl Mercier wrote:

> I think you missed my point.  I -do- want the real database row,  
> but I also want to make sure that the "find" method is called with  
> the right parameters and x number of times.
>
> So this is not really mocking, just setting expectations about what  
> will be called and with what arguments.
>
> On 21-May-08, at 4:32 PM, Zach Moazeni wrote:
>
>> On May 21, 2008, at 10:56 AM, Carl Mercier wrote:
>>
>>> I wish Mocha supported this "out of the box" with this syntax:
>>>
>>> User.expects(:find).with(1)     # returns the "real" row from the  
>>> database
>>> User.expects(:find).with(1).returns(mocked_row)  # returns a fake  
>>> row
>>
>> In my opinion, I don't find that useful. If I want the real row  
>> from the database to brought in, I wouldn't use mocking. I only  
>> use expects / stubs when I want to alter and/or assert behavior.
>>
>>> and to have something explicitly return nil (without running the  
>>> real code):
>>> Foo.expects(:bar).returns(nil)
>>
>> I'm too lazy to check right now, but I thought that was the  
>> current behavior.
>>
>> Foo.expects(:bar)
>> Foo.bar => nil
>>
>> _______________________________________________
>> mocha-developer mailing list
>> mocha-developer at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/mocha-developer
>
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer



More information about the mocha-developer mailing list