[rspec-users] Validation Failed: Userkey has already been taken, Email has already been taken

David Chelimsky dchelimsky at gmail.com
Thu Feb 28 18:55:22 UTC 2013

On Thu, Feb 28, 2013 at 12:57 PM, ruby rails <lists at ruby-forum.com> wrote:
> Hi,
> I am using Factory girl with rspec and capybara for testing my rails
> appliction. I have the below code
> FactoryGirl.define do
>   factory :user do |f|
>   f.email "sss1 at gmail.com"
>   f.userkey "12ssd345q62"
>   end
> end
> When I run the test it is failing as "Validation Failed: Userkey has
> already been taken, Email has already been taken".
> What could be the reason for this. I am new to Rspec.

If you have unique validations on email and userkey, you'll want the
factory to generate diff values every time. Take a look at

I appreciate that you're new to RSpec, and lists like this exist to
provide help, but this is the 2nd time you've asked FactoryGirl
questions that could be answered by reading the FactoryGirl docs.
Please do so before the next question about FactoryGirl and, if it's
about FactoryGirl, you probably want to hit up
https://groups.google.com/forum/?fromgroups#!forum/factory_girl, and
restrict your questions on this list to those actually about rspec. If
you're not sure what the cause is, and can't figure out where else to
send your question, we can point you in the right direction.


More information about the rspec-users mailing list