Skip to main content

rails testing always raise the same error

Rails • Asked by Larry Qu

No matter which test file does I run, it always raise this error.
I don't konw how to fix this, thanks!

$rails test test/integration/about_test.rb
Running via Spring preloader in process 5244
Run options: --seed 35591

# Running:


ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_admin_users_on_email"
DETAIL:  Key (email)=() already exists.
: INSERT INTO "admin_users" ("created_at", "updated_at", "id") VALUES ('2017-03-10 07:58:35.156623', '2017-03-10 07:58:35.156623', 298486374)

bin/rails test test/integration/about_test.rb:8

Finished in 0.298578s, 3.3492 runs/s, 0.0000 assertions/s.

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

If you notice the INSERT INTO statement does not include an email which means your tests probably aren't generating random email addresses for the AdminUser objects it's trying to create. You should make sure that those are being generated on your own or with something like factory_girl so that you won't have conflicting user objects in your tests. I'm pretty sure that'll solve your problem once you get that fixed up.

Hey Larry, I had a similar issue so I (quick) fixed it by deleting the




Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.