0

So I have a parent class with a fabricator, and two subclasses. How do I get the subclasses to reference the parent class's fabricator for setting up shared code?

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
RonLugge
  • 5,086
  • 5
  • 33
  • 61

1 Answers1

1

You can pass a from parameter to the children like so:

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

You can read more about it in the fabrication docs.

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

Paul Elliott
  • 1,174
  • 8
  • 9
  • 1
    The doc site is open source too so if you think they can be improved make a PR :) https://github.com/paulelliott/fabrication-site – Paul Elliott Dec 04 '16 at 13:35
  • Nah, was just me not seeing what was right in front of me -- should have searched 'inheritance' instead of 'subclass', it was the right word even if my brain wouldn't give it up. – RonLugge Dec 05 '16 at 22:53