[rspec-users] tests using factorygirl

Ben Atkin ben at benatkin.com
Thu Mar 1 06:02:43 UTC 2012

Here is the relevant documentation:


Or if it already exists you might try:

FactoryGirl.define :account do
  location { Location.where("city = ?", 'Austin').first }

(The code in the block just needs to return a single Location, and since
it's run within a block it's delayed until the spec is run, rather than at
load time.)


On Wed, Feb 29, 2012 at 10:19 PM, S Ahmed <sahmed1020 at gmail.com> wrote:

> I'm trying to use factory for a test case, but the model I am creating via
> the factory depends on another model, how do you setup a factory like this?
> Model Account has a location_id attribute (where Location is another model)
> So how do I set it?
> FactoryGirl..... do
>   location_id  ????????/
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120229/3f742554/attachment-0001.html>

More information about the rspec-users mailing list