我希望能够简化工厂中创建/构建后的钩子函数,使其更符合DRY原则:
我想在我的工厂中DRY up创建/构建后的钩子:
FactoryGirl.define do
factory :poll do
sequence :title do |n|
"MyPollTitle#{n}"
end
sequence :description do |n|
"MyPollDescription#{n}"
end
user
factory :poll_with_answers do
ignore do
answers_count 2
end
after(:build) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << build(:answer, poll: poll)
end
end
after(:create) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << create(:answer, poll: poll)
end
end
end
end
end
我面临的问题是,似乎我无法在FG中定义方法?有没有什么方法可以使它更加DRY(Don't Repeat Yourself)?
evaluator
是什么 :) - Stefan Kanev