Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

like image 982
Allyl Isocyanate Avatar asked Jan 24 '12 17:01

Allyl Isocyanate


1 Answers

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:

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. Headless webkit also works.

like image 58
Wolfram Arnold Avatar answered Nov 10 '22 01:11

Wolfram Arnold