你如何使用Fabrication定义特征
我正在学习如何在Rails
使用制造 ,我们决定用制造代替所有的factory_girl
代码。
假设我们在factory_girl
有这个代码
FactoryGirl.define do factory :user do trait(:no_credits) { credits 0 } trait(:with_credits) { credits 300 }
你将如何在Fabrication中定义这个? 我已经浏览了他们的网站,但找不到任何相关的内容。 非常感谢您的帮助
似乎您正在寻找Fabricatorinheritance ,这是文档所说的:
您可以使用:from
属性从其他制造商inheritance属性。
Fabricator(:llc, from: :company) do type "LLC" end
设置:from
选项将inheritance命名的Fabricator中的类和所有属性。
您还可以使用:class_name
参数显式指定要制作的类。
Fabricator(:llc, class_name: :company) do type "LLC" end