A simple factory_girl question

Posted by gmile on Stack Overflow See other posts from Stack Overflow or by gmile
Published on 2010-03-16T23:26:36Z Indexed on 2010/03/16 23:31 UTC
Read the original article Hit count: 350

Filed under:
|
|
|
|

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(:user_last_state, :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?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rails