I am using the following code to generate an email address:
sequence :email do |n|
"person#{n}@example.com"
end
Then to generate a user, I use the following code:
factory :user do
sequence(:username) {|n| "person#{n}"}
email { generate :email }
password 'password'
password_confirmation { |u| u.password }
end
However, when I run the test, it always generates “person1@example.com”. It never increases to ‘2’.
I get the error message “person1@example.com” already exists in the database.
How do I get FactoryGirl to increment up?
If you get this message when generating users within single test, then yes, it’s the problem with generating unique emails. But you can receive that kind of error message because of test database not being clean (user left over from a former test). If in doubt, check test log.