未定义的FactoryGirl瞬态变量方法 [英] Undefined methods for FactoryGirl transient variables

查看:59
本文介绍了未定义的FactoryGirl瞬态变量方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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瞬态变量方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆