开发者

How do I define sequences in FactoryGirlRails?

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} de开发者_开发百科scription"}
  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


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

token { Factory.create(:random_token) }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜