Jasmine in Rails 3

UPDATE: We’ve released a new version of the Jasmine Gem and these steps are no longer required. Please see the announcement here

Bad news, everyone! At the moment, the released Jasmine gem is not yet Rails 3 compatible.

Good news, everyone! We now have a short term workaround while we deal with the work needed to work seamlessly with Rails 3.

The Jasmine gem is the easiest way to integrate Jasmine into your web project, including Rails. It adds auto discovery of source & spec files, a tiny Rack app for running them, and a Continuous Integration task (using Selenium) to run your tests on every check in. We use this gem on all of our Rails projects today.

It uses RSpec to gather results from JavaScript making them available at the command line or part of your build results. And RSpec 2, which is required for Rails 3, has changed its interface. So the Jasmine gem is broken with Rails 3. We know what we need to do to fix the this, but until then here’s the workaround.

But what if I’m not using Rails?

This fix is only for Rails 3. If you project is not using Rails or does not require RSpec 2, then you can ignore this post.

How the fix works

We’re going to use Bundler to install the Jasmine gem from a local repo copy of a branched version of what’s on Github. Got it?

The Fix

Once you’ve already created your Rails 3 project, here’s a script that does the right things to vendor the Jasmine gem: