简体   繁体   English

Rails 3.1和资产管道的Javascript单元测试

[英]Javascript unit-testing for Rails 3.1 and asset pipeline

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. 我正在寻找最简单的Rails 3.1 Javascript单元测试系统,该系统特别能够处理现成的资产管道。

I've tried various incarnations of the jasmine gem, including jasmine-rice, headless-jasmine-webkit. 我尝试过各种茉莉花宝石的化身,包括茉莉花米,无头茉莉花webkit。 Jasmine gem does not appear to work with rails 3.1 out of the box, requiring tweaking of various config files. Jasmine gem似乎无法与Rails 3.1一起使用,需要对各种配置文件进行调整。 Jasmine-rice and headless-jasmine-webkit both have complicated dependencies and require more tweaking of the config file. Jasmine-rice和headless-jasmine-webkit都具有复杂的依赖关系,并且需要对配置文件进行更多调整。

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. 理想情况下,我将需要包括HTML / HAML固定装置,并且没有头,但是在这一点上,我将对允许我以最少的配置测试我的javascript的一切感到满意。

Jasmine is the best solution. 茉莉花是最好的解决方案。 We're using this to test all our JS code. 我们正在使用它来测试我们所有的JS代码。 It works beautifully with CoffeeScript as well. 它也可以与CoffeeScript完美配合。

But don't install the version of RubyGems.org (it's not been updated in a while), just get the latest from github, eg add to your Gemfile : 但是不要安装RubyGems.org的版本(暂时不会更新),只需从github获取最新版本即可,例如,添加到您的Gemfile

group :test do    
  gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git'
end

Then you can run rake jasmine and go to http://localhost:8888 to run your tests. 然后,您可以运行rake jasmine并转到http://localhost:8888来运行测试。 Headless webkit also works. 无头Webkit也可以使用。

Hopefully late is better than never... I just wrote a small library that should solve your problem: https://github.com/proxv/qlive-rails 希望迟到总比没有好...我只是写了一个小图书馆,应该可以解决您的问题: https : //github.com/proxv/qlive-rails

It injects qunit and your qunit tests into live server responses. 它将qunit和qunit测试注入实时服务器响应中。 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. 如果您使用的是rspec,那么还有一个附加组件,它将与您的其他rspec示例一起无头运行qunit测试。

I was looking for something that would allow me to unit and functional test my javascript within MS Test in visual studio. 我一直在寻找可以让我在Visual Studio中的MS Test中对JavaScript进行单元测试和功能测试的东西。 Took me forever but I found WatiN . 永远带我过去,但我发现了WatiN What WatiN will do is open internet explorer and run a web page. WatiN将要做的是打开Internet浏览器并运行一个网页。 If you run your IDE as an administrator you can even open local HTML files. 如果您以管理员身份运行IDE,甚至可以打开本地HTML文件。

I am currently using it with Visual Studio to run functional and unit tests on all my javascript. 我目前正在将它与Visual Studio一起使用,以在所有JavaScript上运行功能测试和单元测试。 I think that so far this is the best solution out of the box for running javascript functional tests from your IDE. 我认为到目前为止,这是从IDE中运行javascript功能测试的最佳解决方案。 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). 对于我的单元测试,我使用了YUI测试,但是由于您正在打开浏览器并在浏览器中运行javascript,因此可以使用所需的任何javascript测试框架(例如qUnit)。

I've been using QUnit, a simple yet effective Unit Testing library built on jQuery: 我一直在使用QUnit,这是一个基于jQuery构建的简单而有效的单元测试库:

http://docs.jquery.com/QUnit http://docs.jquery.com/QUnit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM