Reputation: 729
I have a factory that creates a "Character" object, but before I can this object, I must call a method called "init" that instantiates a lot of important attributes and associations. How would I call this method before I start testing the character object?
Because it interacts with a DB, I don't think it would be a good idea to call it at each "it" block
Upvotes: 0
Views: 1541
Reputation: 115511
Look at the the doc here.
There are useful callbacks you can add in your factories:
- after(:build) - called after a factory is built (via FactoryGirl.build, FactoryGirl.create)
- before(:create) - called before a factory is saved (via FactoryGirl.create)
- after(:create) - called after a factory is saved (via FactoryGirl.create)
- after(:stub) - called after a factory is stubbed (via FactoryGirl.build_stubbed)
Upvotes: 2