I am learning how to use fabrication in Rails and we have decided to replace all our factory_girl code with fabrication.
Suppose we have this code in factory_girl
FactoryGirl.define do
factory :user do
trait(:no_credits) { credits 0 }
trait(:with_credits) { credits 300 }
How will you define this in Fabrication? I have gone through their website but couldn't find anything regarding this. Will appreciate your help
Seems that your are looking for Fabricator inheritance, this is what the docs says:
You can inherit attributes from other fabricators by using the
:fromattribute.Setting the
:fromoption will inherit the class and all the attributes from the named Fabricator.You can also explicitly specify the class being fabricated with the
:class_nameparameter.