Search code examples
ruby-on-railsruby-on-rails-3rspecautotest

ruby on rails tutorial TDD "Email has already been taken"


I have been going through Michael Hartl's tutorial http://railstutorial.org/ and for the most part it has been a huge help in getting started with Rails. The book is very focused on TDD, which is great because I wanted to learn TDD, but the problem is 90% of my tests fail with the error "Email has already been taken". I think what is happening is that when the test runs it creates a user with email "[email protected]" as suggested in the book. The problem is when the second test runs which needs to create a user, it is using the same "[email protected]" email address. I know there are workarounds I've seen using factory girl to create a sequence of email addresses but I shouldn't have to do this to get the example from the tutorial working properly.

Has anyone else run into this problem? Judging by the lack of questions on this particular topic I am thinking it is a bug in my code but maybe someone else encountered this.


Solution

  • Doh! The problem was a commented line:

    config.use_transactional_fixtures = true
    

    in spec_helper.rb!

    Newbie mistake.