Capybara 特性测试不提交数据库事务
Capybara feature tests does not commit database transactions
我正在使用 Machinist 创建我的测试用户,我想在每次测试之前登录,我是 运行 Capybara:
include Capybara::DSL
include ActionController::UrlWriter
before do
SslRequirement.disable_ssl_check = true
user = User.make
visit new_user_session_path
fill_in('username', with: user.email)
fill_in('password', with: '12345')
click_button('submit')
end
it "responds as expected" do
# ...
end
现在,当使用 User.make
创建用户时,我可以通过 User.all
访问它,而事实上它还没有保存在数据库中,这是因为
ActiveRecord::Base.connection.open_transactions == 1
我可以 fix/hack 通过
ActiveRecord::Base.connection.commit_db_transaction
在 User.make
之后,但我宁愿妥善解决这个问题。这是我缺少的 Capybara 配置吗?免责声明:使用 Rails 2.3
和 RSpec 1.3
你没有显示你在使用 Capybara 的驱动程序,但通常你不应该在使用 Capybara 时使用事务进行测试(是的,有潜在的变通方法允许它,但它们都有副作用) .参见 transactions and database setup and then look into the database_cleaner gem with truncation - here's a blog post about it that should be good with the age of gems you're using - http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
我正在使用 Machinist 创建我的测试用户,我想在每次测试之前登录,我是 运行 Capybara:
include Capybara::DSL
include ActionController::UrlWriter
before do
SslRequirement.disable_ssl_check = true
user = User.make
visit new_user_session_path
fill_in('username', with: user.email)
fill_in('password', with: '12345')
click_button('submit')
end
it "responds as expected" do
# ...
end
现在,当使用 User.make
创建用户时,我可以通过 User.all
访问它,而事实上它还没有保存在数据库中,这是因为
ActiveRecord::Base.connection.open_transactions == 1
我可以 fix/hack 通过
ActiveRecord::Base.connection.commit_db_transaction
在 User.make
之后,但我宁愿妥善解决这个问题。这是我缺少的 Capybara 配置吗?免责声明:使用 Rails 2.3
和 RSpec 1.3
你没有显示你在使用 Capybara 的驱动程序,但通常你不应该在使用 Capybara 时使用事务进行测试(是的,有潜在的变通方法允许它,但它们都有副作用) .参见 transactions and database setup and then look into the database_cleaner gem with truncation - here's a blog post about it that should be good with the age of gems you're using - http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/