我工作FactoryGirl
在version 4.4
。我正在尝试创建after(:create)
回调,但是在评估变量上失败了。
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>
根据officall工厂女工指南,我做得很好:https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations
任何建议如何使transient variable
工作?
所以解决方案是改变
transient do
links_count 5
end
到
ignore do
links_count 5
end
原因:master上的文档已准备就绪FactoryGirl v.5.0
。瞬变将在5.0
释放时唤醒。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句