[rspec-users] When to mock

Scott Taylor mailing_lists at railsnewbie.com
Tue Aug 19 10:08:10 EDT 2008

On Aug 19, 2008, at 9:38 AM, Jonathan Kinney wrote:

> I noticed that the examples on the rspec website for model code http://rspec.info/documentation/rails/writing/models.html 
>  have no mocks or stubs. However both the controller example and  
> view example do have mocks and stubs implemented. I was having some  
> problems getting mocks to work in my model (using mock_model and  
> passing in a hash or stubs) but I'm wondering if I shouldn't be  
> mocking or stubbing in my model at all? I've done the googling on  
> mocks vs stubs and read a bunch or info, I'm just wondring how some  
> of the fellow rspec users implement mocking and stubbing in their  
> specs and whether or not it is ok to mock and or stub in a model?

Of course it's OK to mock - but with that said, you should probably  
have some sort of "real" integration tests, which do touch the database.

Ultimately, it's all about convenience and your comfort level.  The  
reason mocking is as popular as it is is simply because of slow test  
suites (google Dan Manges and unitrecord, if you are curious).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080819/848923c4/attachment.html>

More information about the rspec-users mailing list