The Fabrication gem allows us to pass custom arguments to the constructor of the class we are fabricating:
on_init { init_with('something', true) }
But how can I pass custom values for init_with
in object generation time?
For the object fields, I can do like the following, but is there a way to pass the values to init_with
?
Fabricate(:foobar, attr1: 'something', attr2: true)
As far as I can see, this is not possible.
def build_instance_with_init_callback(callback)
self._instance = _klass.new(*callback.call)
set_attributes
end
You are stuck with what you used in the fabricator definition.