I suspect that FactoryGirl is dropping this n on every call from autospec , but the database has not been emptied.
First, to verify this diagnosis, change the factory to the following:
Factory.define :email_address do |e| e.sequence(:address) { |n| puts "Email ##{n}"; "factory_#{n}@example.com" } e.validated true end
If my diagnosis is correct, two possible errors are possible:
- modify FactoryGirl to start with an index greater than the maximum identifier used. This will require a serious hack of
Factory::Sequence - you will probably have to turn Factory::Sequence.sequences from Hash[Symbol => Proc] into Hash[Symbol => [Proc, Integer] , which remembers the highest index that it used . Indeed, this may not even work, since autospec seems to correctly unload FactoryGirl classes (otherwise the sequence search will fail and create a new Factory::Sequence object). - find out why your database is not cleared between each run of autospec. Have you tested your tracking methods? Does your test database support transactions?
source share