带JS的RSpec + Capybara请求规格不起作用 [英] RSpec+Capybara request specs w/ JS not working

查看:53
本文介绍了带JS的RSpec + Capybara请求规格不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Javascript时,我无法获得要求规范。
我的规格通过,如果我在不使用Javascript的情况下运行它们(该页面构建为可以使用JS或不使用JS)。

I cannot get request specs working when using Javascript. My specs pass if I run them without Javascript (the page is built to work with or without JS).

具体来说,当我执行诸如 Post。应该具有(1).record 之类的断言时,规范将失败。
Capybara只是不从数据库中获取记录,并且两次运行之间都不会清除数据库。

Specifically, the specs fail when I do assertions like Post.should have(1).record. Capybara just doesn't pick up the records from the DB, and the database is not cleaned between runs.

我尝试在禁用事务固定装置的情况下使用DatabaseCleaner-我想这是常用的方法。没有骰子。

I've tried using DatabaseCleaner with transactional fixtures disabled - the common approach to this, I guess. No dice.

我也尝试(并且最好是在没有DatabaseCleaner的情况下)运行,使用事务性固定装置并强制AR在线程之间共享相同的连接(由JoséValim )。再次,没有骰子。

I've also tried (and, would ideally prefer) running without DatabaseCleaner, using transactional fixtures and forcing AR to share the same connection between threads (a patch described by José Valim). Again, no dice.

此外,我还尝试过在Capybara-webkit和Selenium之间进行切换-问题仍然存在。

Additionally, I've also tried switching between Capybara-webkit and Selenium - the issue persists.

我建立了一个带有基本Post支架的示例应用程序,该应用程序可以复制问题: https ://github.com/cabgfx/js-specs
有一个带有事务性固定装置和AR共享连接的spec_helper.rb,另一个场景是一个spec_helper_database_cleaner.rb。

I've put up a sample app with just a basic Post scaffold, that replicates the problem: https://github.com/cabgfx/js-specs There's a spec_helper.rb with transactional fixtures and AR shared connection, and a spec_helper_database_cleaner.rb for the other scenario.

我通常使用Spork,但是我已经在两个spec_helper.rb文件中将其禁用,只是为了消除潜在的故障点(在两个应用程序中;在真实应用程序和示例应用程序中)。

I normally use Spork, but I've disabled it in both spec_helper.rb files, just to eliminate a potential point of failure (in both apps; the "real" one and the sample app).

我在Macbook Air上使用Pow在本地开发,运行OS X 10.7.3和MRI 1.9.3并通过RVM。 (我也在1.9.2上尝试过)。

I develop locally using Pow on a Macbook Air, running OS X 10.7.3 with MRI 1.9.3 thru RVM. (I also tried on 1.9.2).

希望我有道理-任何指导/帮助/指针非常感谢! / p>

Hope I'm making sense - any guidance/help/pointers are greatly appreciated!

推荐答案

马特-非常感谢您抽出宝贵时间为我提供帮助!
我尝试使用Selenium作为javascript驱动程序使用您的spec_helper进行设置。

Matt - thanks a lot for taking time to assist me! I tried setting it up with your spec_helper, using Selenium as the javascript driver.

该规范仍然失败-但我可以看到正在执行正确的行为Firefox ...
然后我突然意识到,可能是由于Capybara不等待AJAX​​请求完成而出现问题。

The spec still failed - but I could see the correct behavior being executed in Firefox... Then it dawned on me, that the problem might occur because of Capybara not waiting for AJAX requests to finish.

然后我恢复了我的状态最初的spec_helper(带有Spork,没有DatabaseCleaner),并且仅使用了Capybara的 wait_until {page.has_content? }

I then reverted to my initial spec_helper (with Spork and no DatabaseCleaner), and simply used Capybara's wait_until { page.has_content? "text I'm inserting with JS" }.

我更新了示例应用,并添加了 sleep 1 ,因此您可以自己查看。现在无论有没有Spork,它都可以使用,而AR猴子补丁似乎可以完美地工作。

I updated the sample app, and just added sleep 1 in the request spec, so you can see for yourself. It now works with and without Spork, and the AR monkey patch seems to work perfectly.

这篇关于带JS的RSpec + Capybara请求规格不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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