It may be a cheap trick, but you can create a lambda in the second factory:
factory :poll_with_answers do ignore do answers_count 2 end make_answers = lambda do |poll, evaluator, method| evaluator.answers_count.times do poll.answers << send(method, :answer, poll: poll) end end after(:build) do |poll, evaluator| make_answers.call poll, evaluator, :build end after(:create) do |poll, evaluator| make_answers.call poll, evaluator, :create end end
I'm not quite happy with this model, but at least it's DRY stuff.
source share