你如何干燥子类制造商?
How do you DRY up subclassed fabricators?
所以我有一个父 class 和一个制造商,还有两个子 class。如何让子 class 引用父 class 的制造商来设置共享代码?
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
您可以像这样将 from
参数传递给 children:
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
您可以在制造文档中阅读更多相关信息。
所以我有一个父 class 和一个制造商,还有两个子 class。如何让子 class 引用父 class 的制造商来设置共享代码?
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
您可以像这样将 from
参数传递给 children:
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
您可以在制造文档中阅读更多相关信息。