2016-10-20 6 views
0

그래서 fabricator와 두 개의 하위 클래스가있는 상위 클래스가 있습니다. 공유 코드 설정을 위해 상위 클래스의 제작자를 참조하도록 하위 클래스를 얻으려면 어떻게해야합니까?서브 클래 싱 된 fabricator는 어떻게 건조합니까?

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

doc 사이트도 오픈 소스이므로 PR을 향상시킬 수 있다고 생각한다면 https://github.com/paulelliott/fabrication-site –

+0

아니, 바로 앞에있는 것이 보이지 않는 것입니다. 나 - '하위 클래스'대신 '상속'을 검색 했어야합니다. 내 머리가 포기하지 않아도 올바른 단어였습니다. – RonLugge