Javascript Testing for Rails 3.1 and the Asset Pipeline

I am looking for the easiest Javascript testing system for Rails 3.1, which is specifically capable of working with an asset pipeline out of the box.

I have tried various incarnations of pearl pearls, including jasmine rice, headless jasmine-webkit. Jasmine gem does not seem to work with 3.1 rails out of the box, requiring the configuration of various configuration files. Jasmine rice and eyeless-jasmine-web kit have complex dependencies and require more configuration file configuration.

Any suggestions? Ideally, I would need to include the HTML / HAML tools and be headless, but at this point I would be happy to let me test my javascript with a minimal configuration.

+8
javascript ruby-on-rails unit-testing asset-pipeline
source share
4 answers

Jasmine is the best solution. We use this to test all of our JS code. It works great with CoffeeScript.

But do not install the version of RubyGems.org (it does not update after a while), just get the latest version from github, for example. add to your 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 the tests. Mute webkit works.

+1
source share

I was looking for something that would allow me to run a unit and functional test of my javascript in MS Test in visual studio. Took me forever, but I found WatiN . What WatiN will do is open an Internet Explorer and launch 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 throughout my javascript. I think this is still the best solution out of the box to run javascript functional tests from your development environment. For my unit tests, I used the YUI test, but since you open the browser and run javascript in the browser, you can use any javascript validation infrastructure that you need (e.g. qUnit).

0
source share

I used QUnit, a simple but effective Unit Testing library built on jQuery:

http://docs.jquery.com/QUnit

0
source share

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 real-time server responses. It also allows you to set the status of the server on the side before testing (for example, register the user and set the content for the page) to reduce mockery on the client side.

If you use rspec, there is also an add-in that runs qunit tests without problems along with your other rspec examples.

0
source share

All Articles