你如何干燥子类制造商?

时间:2016-10-20 23:36:29

标签: fabrication-gem

所以我有一个带有制作者的父类和两个子类。如何让子类引用父类的构造器来设置共享代码?

电子。 -G。

Fabricator(:parent) do
    important_variable "Foo"
    lesser_variable "Bar
end

Fabricator(:child1) do
    //Not sure I actually need anything in here
end


Fabricator(:child2) do
    //Again, not sure I actually need anything in here
end

Fabricate(:child).important_variable #Foo
Fabricate(:child).lesser_variable #Bar

1 个答案:

答案 0 :(得分:1)

您可以将from参数传递给子项,如下所示:

Fabricator(:child1, from: :parent) do
  //Not sure I actually need anything in here
end


Fabricator(:child2, from: :parent) do
  //Again, not sure I actually need anything in here
end

您可以在制作文档中阅读更多相关信息。

https://www.fabricationgem.org/#defining-fabricators