문제

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

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top