Rails: Avoiding duplication errors in Factory Girl…am I doing it wrong?

Simple answer: use factory.sequence If you have a field that needs to be unique you can add a sequence in factory_girl to ensure that it is never the same: Factory.define :user do |user| sequence(:email){|n| “user#{n}@factory.com” } user.password{ “secret” } end This will increment n each time in order to produce a unique email address such …

Read more