Ruby on rails rspec和水豚测试装置注册,用户已存在故障

Ruby on rails rspec和水豚测试装置注册,用户已存在故障,ruby-on-rails,rspec,ruby-on-rails-4,capybara,Ruby On Rails,Rspec,Ruby On Rails 4,Capybara,我正在尝试使用rspec、水豚和factoryGirl通过Desive测试我的注册和登录 问题在于,使用activeRecord中的以下消息进行登录测试时,测试一直失败: ActiveRecord::RecordInvalid: 验证失败:电子邮件已被接收 以下是我的测试: describe "GET /users/sign_up" do it "register user and send email" do user = FactoryGirl.build(:user) visit

我正在尝试使用rspec、水豚和factoryGirl通过Desive测试我的注册和登录

问题在于,使用activeRecord中的以下消息进行登录测试时,测试一直失败:

ActiveRecord::RecordInvalid: 验证失败:电子邮件已被接收

以下是我的测试:

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
和signin测试:

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
在寻找解决方案的过程中,我看到一些人添加了database_cleaner,并说这会有所帮助。所以我添加了数据库 并将以下行添加到我的spec_helper.rb文件中:

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
但它仍然不起作用

我想要一些指导或想法。谢谢

添加工厂女孩代码:

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
我发现了我的问题。 测试失败,因为我用factoryGirl创建的用户未得到确认。我有一个可确认的设计

这一行之后的任何一行:

user = FactoryGirl.create(:user)
user.confirm!
我加了一行:

user = FactoryGirl.create(:user)
user.confirm!
现在好了


谢谢

您能为用户提供出厂代码吗?只是一个健康检查,但用户是否可能存在于以前的测试中?您是否尝试过从测试数据库中删除所有用户?清理不应该这样做吗?。。。我没有其他的测试可以接受这两个。我认为它通过了第一个寄存器测试,然后没有通过登录测试