如何使用 Merb 和 Webrat 测试 AJAX 请求?
我将 merb 与 rspec 和 webrat 一起使用。如何保证rjs模板渲染成功?由于ajax,我不能只写have_xpath。
I am using merb with rspec and webrat. How to ensure that rjs template was successfully rendered? I cannot just write have_xpath because of ajax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不容易。您已经提到了selenium,它将从浏览器一路向下进行测试,但速度很慢。我的建议是将其分成几个部分。首先使用 rspec 检查原始页面请求的输出,以确保它具有您认为的 JavaScript,以及 ajax 响应,以确保它得到正确的服务。
现在的技巧是测试 JavaScript 本身。有许多 JavaScript 测试库。我建议jUnit。就像编写 rspec 一样编写测试,并分别测试 ajax 请求的功能和生成的 rjs。
最后使用 selenium 运行完整堆栈并证明一切都可以协同工作。如果存在错误,请返回您的单元测试之一并编写一个更简单的测试来暴露该错误。
This is not easy. You already mention selenium, which will test from the browser all the way down, but it is slow. My suggestion is to break this into a couple parts. First use rspec to check the output of both the original page request to make sure it has the JavaScript you think it does, and also the ajax response to ensure that it is being served correctly.
Now the trick is to test the JavaScript itself. There are a number of testing libraries for JavaScript. I suggest jUnit. write tests just like you would for rspec and test the function of your ajax request, and the resultant rjs separately.
Finally use selenium to run the full stack and prove everything works together. If there are bugs go back to one of your unit test and write a simpler test that will expose the bug.
嗯,我明白了。有selenium、watir和朋友。听起来很奇怪,因为我需要一个浏览器来测试:(
Well, I got it. There are selenium, watir and friends. Sounds weird because I need a browser for testing :(