我正在尝试使用 javascript 驱动程序(w/Webkit 或 Poltergeist)获取一些与 Capybara 一起使用的 RSpec 示例,但是在更新表时数据库存在锁定问题。以下是相关示例的一部分:
scenario 'by changing the contract attributes', js: true do
login_as @admin, scope: :user
contract = Contract.create(number: '123',
start_at: Date.today,
end_at: Date.today + 1.month)
visit "/contracts/#{contract.id}/edit"
我正在使用设计和Warden::Test::Helpers
登录。
运行 RSpec 需要一段时间,我得到的只是:
Failure/Error: visit "/contracts/#{contract.id}/edit"
Capybara::Driver::Webkit::WebkitInvalidResponseError:
Unable to load URL: http://127.0.0.1:46520/contracts/1/edit
日志显示存在数据库锁定问题:
Started GET "/contracts/1/edit" for 127.0.0.1 at 2012-06-01 12:10:26 -0400
(0.2ms) BEGIN
(51083.3ms) UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
Mysql2::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `users` SET `last_sign_in_at` = '2012-06-01 16:10:26', `current_sign_in_at` = '2012-06-01 16:10:26', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2012-06-01 16:10:26' WHERE `users`.`id` = 1
(0.8ms) ROLLBACK
我已经尝试了很多事情(这个问题似乎最接近实际的解决方案:Capybara with :js => true 导致测试失败)但没有任何效果,甚至摆脱了 DatabaseCleaner。还有什么我可以尝试的吗?
编辑:这是spec_helper.rb
所要求的文件:https ://gist.github.com/2855631