Please enter name
please enter valid email
please enter comment
Please enter correct code

Factory Girl with Test Console

Contributed by Neev Technologies on 27 Sep 2012

I thought I’ll share something I picked up yesterday while trying hard to figure out answers to these questions, being fairly new to factory girl (I’ve mostly used fixtures before ) :

  1. How to create new Factories and model associations between them
  2. Test the factories I created .

It would have been easy if we could have something like the rails console to create objects from the factories and see if they are alright . We know the rails console command accepts the environment as the parameter , and since the factories are loaded in the test environment , wouldn’t running the rails console in “test” environment let us create objects out of Factories ? Yes !

$ rails c test ( This will start the console in test environment )

>hiring_event =  Factory(:hiring_event_with_candidates) ( This works ! )

>hiring_event.candidates

So if somebody wants to test your dependencies in factories , don’t hesitate to use the test console !

Another useful thing to note : you may find yourself restarting the console everytime you change the factories , because the console doesn’t reflect live changes . Save yourself the trouble .

> FactoryGirl.reload ( will reload all factories , so you don’t have to restart the console everytime you change a factory )

Contributor : Emil Soman

Visit us at Neevtech.com to know more about our offerings.

Tags: ,

One Comment

  1. cjytest says:

    cjytest…

    I had been very pleased to get this kind of web-site.I needed to be able to good occasion because of this wonderful go through!! My partner and i undoubtedly taking pleasure in each and every little bit of this and I maybe you have bookmarked to look a…

Leave a Comment

Security Code: