Does anyone know how to reset the sequence method for FactoryGirl?
I have a factory that creates a list of tasks and I want to order to start at 1 every time. I use 'sequence' because the task list is a associated model, so I would need the order to increase every time I use FactoryGirl.create
until I call a reset.
You need to write FactoryGirl.reload
in the before/after callback of the test file.
Example code snippet
before do
FactoryGirl.reload
.
.
.
end
The '.' represents other code.
Preferably write FactoryGirl.reload unless FactoryGirl.factories.blank?
so that FactoryGirl does not reload, when it does not have to.
Doing a full reload of FactoryGirl might have some overhead on the time it takes to process the test(s); this is also what is described as Anti-Patterns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With