[mocha-developer] mocking methods called multiple times

Jay Fields jay at jayfields.com
Fri Mar 28 21:51:00 EDT 2008

Examples are always nice, but in the mean time...

Model.expects(:save).at_least_once will let you call it one or more  
Model.stubs(:save) will let you call it zero or more times

But, if you want to test models without hitting the database you can  
use UnitRecord. If you want to take it another level and test models  
without loading the Rails framework you can use arbs: http://arbs.rubyforge.org

Cheers, Jay

On Mar 28, 2008, at 7:30 PM, James Mead wrote:

> On 28/03/2008, Ryan Sobol <ryan.sobol at tobi.com> wrote:
>> i'm trying to use a test dummy to block the interaction between my
>> test and our database.
>> the code im testing makes a handful of active_record calls
>> (create_table, add_index, etc.) i'm trying to use mocks to expect
>> calls at the database adapter level (i'm thinking #execute, but no
>> committed to it yet)
>> long story short, i'm having difficulties telling mocha to expect 2
>> calls to this method in the same test.  thoughts?
> Can you give us some more specifics? Ideally a simple test along  
> with the
> code that it exercises? Try and keep it as simple as possible while  
> still
> illustrating the point. It's always much easier to discuss concrete
> examples.
> Thanks.
> -- 
> James.
> http://blog.floehopper.org
> http://tumble.floehopper.org
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer

More information about the mocha-developer mailing list