How do I define sequences in FactoryGirlRails?

痞子三分冷 提交于 2019-12-07 16:28:50

问题


Previously in Factory girl, we could define sequences like so:

# /spec/factories.rb

FactoryGirl.define do

  # this is the sequence in question:
  sequence(:random_token) { Digest::MD5.hexdigest(rand.to_s) }

  factory :story do
    sequence(:title) { |n| "My Cool Story##{n}"  }
    # Call the sequence here:
    token { Factory.next(:random_token) }
    description { "#{title} description"}
  end

end

Now, when I try that approach - I get a deprecation warning telling me:

WARNING: FactoryGirl::Sequence#next is deprecated.
Use #run instead.

When I replace #next with #run, I get a no-method error. I can't find the new syntax in any of the docs... Can anyone point me in the right direction?

Thanks


回答1:


I think you should use Factory.create(...) instead, e.g.

token { Factory.create(:random_token) }


来源:https://stackoverflow.com/questions/5497801/how-do-i-define-sequences-in-factorygirlrails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!