Rails 3.1 和资产管道的 Javascript 单元测试
我正在为 Rails 3.1 寻找最简单的 Javascript 单元测试系统,该系统特别能够与开箱即用的资产管道一起使用。
我尝试过 jasmine gem 的各种版本,包括 jasmine-rice、headless-jasmine-webkit。 Jasmine gem 似乎不能直接与 Rails 3.1 一起使用,需要调整各种配置文件。 Jasmine-rice 和 headless-jasmine-webkit 都有复杂的依赖关系,需要对配置文件进行更多调整。
有什么建议吗?理想情况下,我需要包含 HTML/HAML 固定装置,并且是无头的,但此时我会对任何允许我以最少的配置测试我的 javascript 的东西感到满意。
I'm looking for the easiest possible Javascript unit-testing system for Rails 3.1 that is specifically capable of working with the asset pipeline out of the box.
I've tried various incarnations of the jasmine gem, including jasmine-rice, headless-jasmine-webkit. Jasmine gem does not appear to work with rails 3.1 out of the box, requiring tweaking of various config files. Jasmine-rice and headless-jasmine-webkit both have complicated dependencies and require more tweaking of the config file.
Any suggestions? Ideally I would need to include HTML/HAML fixtures, and be headless, but at this point I would be happy with anything that allows me to test my javascript with minimal configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
茉莉花是最好的解决方案。我们用它来测试我们所有的 JS 代码。它与 CoffeeScript 也能完美配合。
但是不要安装 RubyGems.org 的版本(已经有一段时间没有更新了),只需从 github 获取最新版本,例如添加到您的
Gemfile
中:然后您就可以运行
rake jasmine
并转到http://localhost:8888
运行测试。 Headless webkit 也可以工作。Jasmine is the best solution. We're using this to test all our JS code. It works beautifully with CoffeeScript as well.
But don't install the version of RubyGems.org (it's not been updated in a while), just get the latest from github, e.g. add to your
Gemfile
:Then you can run
rake jasmine
and go tohttp://localhost:8888
to run your tests. Headless webkit also works.我一直在寻找一些东西,可以让我在 Visual Studio 的 MS Test 中对我的 javascript 进行单元测试和功能测试。我花了很长时间,但我找到了WatiN。 WatiN 要做的是打开 Internet Explorer 并运行一个网页。如果您以管理员身份运行 IDE,您甚至可以打开本地 HTML 文件。
我目前正在将它与 Visual Studio 一起使用,对我的所有 javascript 运行功能和单元测试。我认为到目前为止,这是从 IDE 运行 javascript 功能测试的最佳解决方案。对于我的单元测试,我使用 YUI 测试,但由于您打开浏览器并在浏览器中运行 javascript,因此您可以使用任何您想要的 javascript 测试框架(如 qUnit)。
I was looking for something that would allow me to unit and functional test my javascript within MS Test in visual studio. Took me forever but I found WatiN. What WatiN will do is open internet explorer and run a web page. If you run your IDE as an administrator you can even open local HTML files.
I am currently using it with Visual Studio to run functional and unit tests on all my javascript. I think that so far this is the best solution out of the box for running javascript functional tests from your IDE. For my unit tests I used YUI test, but since you are opening a browser and running javascript within the browser you can use any javascript test framework you want (like qUnit).
我一直在使用 QUnit,这是一个基于 jQuery 构建的简单而有效的单元测试库:
http://docs.jquery.com /QUnit
I've been using QUnit, a simple yet effective Unit Testing library built on jQuery:
http://docs.jquery.com/QUnit
希望迟到总比不到好......我刚刚写了一个小库,应该可以解决你的问题:
https://github.com/proxv/qlive-rails
它将 qunit 和您的 qunit 测试注入到实时服务器响应。它还允许您在测试之前设置状态服务器端(例如登录用户和设置页面内容)以减少客户端模拟。
如果您使用 rspec,还有一个附加组件可以与其他 rspec 示例一起无头运行 qunit 测试。
Hopefully late is better than never... I just wrote a small library that should solve your problem:
https://github.com/proxv/qlive-rails
It injects qunit and your qunit tests into live server responses. It also lets you set state server-side in advance of the tests (like logging in a user and setting content for the page) to reduce client-side mocking.
If you are using rspec, there's also an add-on that will run the qunit tests headlessly along with your other rspec examples.