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

Zach Dennis zach.dennis at gmail.com
Thu Oct 30 11:58:36 EDT 2008

On Thu, Oct 30, 2008 at 11:41 AM, Rémi Gagnon <lists at ruby-forum.com> wrote:

> I do agree, That's what we're gonna do. it was just an example.
> But what if we want to test find_thingy(in model spec) to make sure the
> :conditions is set properly?

You are probably more interested in the fact that find_thingy works rather
then it sets a bunch of conditions. Perhaps something like the below would
work for you:

it "can find things by blank and blank" do
   thing1 = Thing.create! :nte_no => 1, vaat_id_type_statut_pcpa => 2
   thing2 = Thing.create! :nte_no => 2, vaat_id_type_statut_pcpa => 3
   Thing.find_by_thingy(1,2).should == thing1
   Thing.find_by_thingy(2,3).should == thing2

If you have a way of generating "things" that are valid, then I'd use that
mechanism and pass in the attributes you are specifically going to be
testing against (so they stand out in the example that that's what matters
in the example).

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,

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

More information about the rspec-users mailing list