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 ) :
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 ! )
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.
© 2015 Neevtech Blog | Neev Technologies