2016-10-20 95 views
0

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

E. 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

你可以通过一个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

+0

欢快,我阅读文档。不知何故,错过了这个。 – RonLugge

+1

该文档站点也是开源的,所以如果你认为他们可以改进使PR:) https://github.com/paulelliott/fabrication-site –

+0

那,只是我没有看到什么是正确的前面我 - 应该搜索“继承”而不是“子类”,即使我的大脑不会放弃它,这也是正确的词。 – RonLugge