问题描述
我正在使用version 4.4
中的FactoryGirl
.我正在尝试创建after(:create)
回调,但是在评估变量上却失败了.
I'm working with FactoryGirl
in version 4.4
. I'm trying to create after(:create)
callbacks but I'm failing on evaluator variables.
FactoryGirl.define do
factory :organization do
name 'example'
factory :organization_with_links do
transient do
links_count 5
end
after(:create) do |organization, evaluator|
create_list(:link, evaluator.links_count, organization: organization)
end
end
end
end
很不幸,我得到了
NoMethodError: undefined method `links_count' for FactoryGirl::SyntaxRunner:0x007fcefb1ff780>
根据正式工厂女工指南,我正在正确地进行一切操作: https ://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations
according to officall factory girl guide I'm doing everything properly :https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations
关于如何使transient variable
工作的任何建议?
any advices how to make transient variable
working?
推荐答案
所以解决方案是更改
transient do
links_count 5
end
到
ignore do
links_count 5
end
原因:master上的文档已为FactoryGirl v.5.0
准备. 5.0
发行版时,瞬变将被唤醒.
Reason: Docs on master are prepared for FactoryGirl v.5.0
. transient will wok on 5.0
release.
更多阅读内容: http://github.com/thoughtbot/factory_girl/issues/658
这篇关于未定义的FactoryGirl瞬态变量方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!