質問

I am writing an RSpec using FactoryGirl. It has been giving errors

   NoMethodError: undefined method `saved?' for nil:NilClass

I think this error is happening because the object C is not being initialized properly. Here I have defined three models A, B and C among which model C is dependent on other two models. I have written them in factory.rb in no particular order i.e. first I have written C then A and B. I would like to know whether they have to be defined in particular order according to the dependency. Thank you.

役に立ちましたか?

解決

Order of definition does not matter in FactoryGirl definitions in terms of any code that is within the blocks being passed in. That's because the code within the blocks is not executed until the factories are actually invoked.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top