FactoryGirl瞬态变量的未定义方法

我在version 4.4使用FactoryGirl 。 我正在尝试创建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> 

根据官方工厂女孩指南我正在做的一切正确: 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 

原因:硕士论文为FactoryGirl v.5.0做好准备。 瞬态将在5.0版本上发布。

更多阅读: http : //github.com/thoughtbot/factory_girl/issues/658