如何使用制造来定义特征 [英] How do you define trait using Fabrication
问题描述
我正在学习如何在Rails
中使用制造,我们已决定替换我们所有的factory_girl
代码都带有伪造.
I am learning how to use fabrication in Rails
and we have decided to replace all our factory_girl
code with fabrication.
假设我们在factory_girl
FactoryGirl.define do
factory :user do
trait(:no_credits) { credits 0 }
trait(:with_credits) { credits 300 }
您将如何在Fabrication中对此进行定义?我浏览了他们的网站,但找不到任何有关此的信息.感谢您的帮助
How will you define this in Fabrication? I have gone through their website but couldn't find anything regarding this. Will appreciate your help
推荐答案
Seems that your are looking for Fabricator inheritance, this is what the docs says:
您可以使用:from
属性从其他制造商继承属性.
You can inherit attributes from other fabricators by using the :from
attribute.
Fabricator(:llc, from: :company) do
type "LLC"
end
设置:from
选项将继承命名的制造者的类和所有属性.
Setting the :from
option will inherit the class and all the attributes from the named Fabricator.
您还可以显式指定使用:class_name
参数构造的类.
You can also explicitly specify the class being fabricated with the :class_name
parameter.
Fabricator(:llc, class_name: :company) do
type "LLC"
end
这篇关于如何使用制造来定义特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!