[rspec-users] spec'ing the :conditions argument of a find

Zach Dennis zach.dennis at gmail.com
Thu Oct 30 13:00:56 EDT 2008

On Thu, Oct 30, 2008 at 12:41 PM, Matt Wynne <matt at mattwynne.net> wrote:

> On 30 Oct 2008, at 15:58, Zach Dennis wrote:
>> I know the above example breaks the one assertion per test guideline
>> people strive to adhere to, but I think it is ok.  If there are more
>> examples that should be used to make sure find_thingy works then I'd break
>> out a separate describe block and have multiple 'it' examples,
> It also goes to the database, which will make it a slow unit test. I
> personally do pretty much the same thing myself mostly when working with
> ActiveRecord, but it doesn't mean I'm comfortable with it. (And it also
> doesn't mean our unit test suite is anything other than shamefully slow)

It will make it a *slower* unit test. I am yet to be convinced that when
working with ActiveRecord, it is worthwhile to not hit the database when you
trying to verify that custom queries are working correctly. I have yet to
see model examples which were so slow I didn't want to run them. I get more
confidence and value out of knowing custom queries work at the model example
level, rather than waiting for an acceptance test to trigger their failure.

I do get value out of not hitting the database for things that I don't need
to hit it for, but custom finds aren't one of those things IMO. It's also
easier to track down the failure and fix it at the model example level,
rather than having to truck through acceptance test backtraces, log files,
etc to find that you had a typo in your custom finder.

For the record, my definition of custom apples to handcrafted SQL as well as
handcrafted conditions, scopes, joins, etc that are used when creating find
methods which encapsulate this logic (such as find_thingy 1, 2)

Zach Dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081030/b8e37a96/attachment.html>

More information about the rspec-users mailing list