Just started using factory girl. If one has to save a factory into the db then one has to run
FactoryGirl.create().
But is there any way to load a collection of factories into the database without having to call create on each of the factories?
If its of any help i’m using Ruby 1.9.3, Rails 3.2.8 and Factory Girl 4.1.
If you need a bunch of factories of different type, you’ll simply have to create them individually. You can make this a bit less verbose by adding this to your
test_helper.rb:Then you can create factories like this:
And of course, if you need a bunch of records of the same type, you can create them like this:
As mentioned in my comment, creating all your factories in one fell swoop on initialization of your test framework is counter-productive. The idea behind FactoryGirl is to provide just the data you need for each test case or context. This avoids dependencies between tests that tend to slip into a fixture-driven approach.