2016-10-20 75 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