I was running tests, and first time round, they all pass green. If I run the test again, some fail with the following message:
Failure/Error: @user = Factory :user
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
I am really confused as to why this is happening. I thought rspec did not push values to the database. If I purge the test database, this is fixed, but then, on second round of test execution, some fail with the same error.
Any ideas how I can fix this? Note, I installed cancan gem recently, maybe it has to do something with it?
Factory Girl is not what is supposed to be deleting the data, it’s usually RSpec (by way of the
use_transactional_fixturesoption) or another tool likedatabase_cleaner.If your test database is not being cleaned out correctly, then I would recommend using the
database_cleaner.