I have two factories (post_factory.rb
, comment_factory.rb
) in separate files. I'd like to create a bit complex factory, which will create a post with associated comments for me. I created a third file, called complex_factory.rb
, and wrote the following code:
Factory.define :post_with_comments, :parent => :post do |post|
post.after_create { |p| Factory(:comment, :post => p) }
end
But rake spec
raises an error, stating that the file is unaware of post and comment factories. At the very next moment, I naïvely wrote requires at the top:
require "post_factory.rb"
require "comment_factory.rb"
But that didn't gave any proper result. Maybe this requires actually looking the wrong direction? Or they pretty much don't matter (as registering factories for visibility might be more complex that I assume).
Am I missing something? Any ideas?