Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top