带有Rails 3.2.12的Ajax调用的capybara集成测试错误 [英] Integration test error with capybara for ajax call with rails 3.2.12

查看:52
本文介绍了带有Rails 3.2.12的Ajax调用的capybara集成测试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个集成测试案例,在3.2.12的栏上有水豚。 click_link新日志 是ajax调用。但是打开的页面以$()开头,并且有一堆js逸出,如\n和\log-log。

Here is a integration test case with capybara in rails 3.2.12. click_link 'New Log' is an ajax call. However the page opened starts with $() and has a bunch of js escape like \n and \log-log.

it "should work with link on show customer_comm_record page" do
      visit customer_customer_comm_records_path(@cust)
      #visit customer_customer_comm_record_path(@cust, @crecord)
      click_link @crecord.id.to_s     
      click_link 'New Log'
      save_and_open_page
end

我们也尝试用 describe,:js =>确实如此,怎么会出现错误提示

We also tried to wrap the case with describe "", :js => true do, how there is an error saying

`An error occurred in an after hook   ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked:`

代码执行没有错误。 rspec案件怎么了?谢谢。

There is no error out of code execution. What's wrong with the rspec case? Thanks for help.

推荐答案

您的服务器似乎正在锁定数据库,因此测试运行后无法清理。

It looks like your server is locking the database so that the test cannot clean up after it has run.

在不使用JavaScript的情况下使用Capybara时,测试和服务器都在单个进程和线程中运行。这意味着他们可以共享相同的数据库连接和事务。这意味着RSpec可以使用简单的数据库事务在测试结束时回滚更改,以及为什么看不到测试和服务器之间的任何锁争用。

When you use Capybara without JavaScript the tests and server are all running in a single process and thread. This means they can share the same database connection and transaction. This means that RSpec can use a simple database transaction to roll back changes at the end of the test and why you don't see any lock contention between test and server.

当您使用:js =>运行时,确实情况有所不同,服务器在您的测试的单独线程或进程中启动,因此它们将各自使用单独的数据库连接和事务。这意味着RSpec默认使用清理的数据库事务策略将不起作用。

When you run with :js => true things are a little different, the server starts up in a separate thread or process to your tests so they will each be using a separate database connection and transaction. This means that the database transaction strategy that RSpec uses by default to clean up won't work. It is also causing lock errors in your case.

Capybara 自述文件讨论了此问题,并建议在这种情况下使用 database_cleaner gem作为替代方法。您将需要配置数据库清理程序以使用截断策略而不是事务

The Capybara readme talks about this problem and recommends database_cleaner gem as an alternative in this situation. You will need to configure database cleaner to use the truncation strategy rather than transactions

这篇关于带有Rails 3.2.12的Ajax调用的capybara集成测试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆