[rspec-users] When to mock

Mark Wilden mark at mwilden.com
Tue Aug 19 10:23:49 EDT 2008

On Tue, Aug 19, 2008 at 7:08 AM, Scott Taylor <mailing_lists at railsnewbie.com
> wrote:

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

Another reason why you'd mock out the database is that that's not your code
- it's ActiveRecord and MySQL/PostgreSQL/etc (which one would imagine have
been rather thoroughly tested elsewhere:). The idea is that if you know
you're calling ActiveRecord methods correctly, you don't actually have to go
any deeper than that in a unit spec.

The key, I think, is to ask yourself "what am I testing/speccing?" Generally
(again, for a unit test), it's the contents of a file or files that you are
writing - very often, a single method. You want to make sure that you've
specified what the contents of that method do, and that the lines of code in
it are correct.

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

More information about the rspec-users mailing list