如何在 FactoryGirlRails 中定义序列?
以前在 Factory Girl 中,我们可以这样定义序列:
# /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
现在,当我尝试这种方法时 - 我收到一条弃用警告,告诉我:
WARNING: FactoryGirl::Sequence#next is deprecated.
Use #run instead.
当我用 #run 替换 #next 时,我收到无方法错误。 我在任何文档中都找不到新语法...任何人都可以指出我正确的方向吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该使用
Factory.create(...)
代替,例如I think you should use
Factory.create(...)
instead, e.g.