I am trying to test my signup and sign in through devise using rspec, capybara and factoryGirl
the problem is that the tests keep failing in the signin test with this message from activeRecord:
ActiveRecord::RecordInvalid: Validation failed: Email has already been taken
these are my tests:
describe "GET /users/sign_up" do
it "register user and send email" do
user = FactoryGirl.build(:user)
visit new_user_registration_path
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
fill_in "Password confirmation", :with => user.password
fill_in "Name", :with => user.name
click_button "Sign up"
ActionMailer::Base.deliveries.last.to.should include(user.email)
page.should_not have_content("Password confirmation")
end
end
and the signin test:
describe "GET /users/sign_in" do
it "try to login email password" do
user = FactoryGirl.create(:user)
visit new_user_session_path
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
page.should have_content("Signed in successfully.")
end
end
while searching for a solution I saw some people added database_cleaner and said that suppose to help. so i added the database_cleaner gem and added these lines to my spec_helper.rb file:
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
but it still not working.
would love some guidance or idea. thanks!
adding factory girl code:
require 'factory_girl'
FactoryGirl.define do
factory :user do |f|
f.sequence(:email) {|n| "dodo#{n}@gmail.com"}
f.password "secret123"
f.name "dodo"
end
factory :partner do |f|
f.company "spectoos"
end
end