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.
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
Once you’ve already created your Rails 3 project, here’s a script that does the right things to vendor the Jasmine gem:
What you see above:
- making a
vendor/gemsdirectory if you don’t already have one
- getting the Jasmine gem code: cloning the Jasmine gem, getting Jasmine itself (as a submodule), then getting & checking out the correct branch
- copying some files from the Jasmine repo up into the gem’s directories (a step Bundler can’t do for us)
Once this is done, you need to add this line to your
Gemfile, likely in a test group (if you have one):
gem 'jasmine', :path => 'vendor/gems/jasmine'
Run a bundle install to get the Jasmine gem installed.
cd ../../.. bundle install
Now you can run the generator to make your Rails project a Jasmine project.
bundle exec jasmine init
Try running the example Jasmine specs:
http://localhost:8888. You should see 5 specs pass.
Now you’ll need to edit
jasmine.yml and point to your source, spec, and helper files. Delete the example files once you get your specs up and working.
Lastly, you need to check in the Jasmine gem source into your project so that other development machines and your CI box can run your Jasmine specs.
- Remove the
- Remove the
vendor/gems/jasmineto your repo directly (
git add vendor/gems/jasmine)
That should do it.
UPDATE: There was an issue in the repo branch that has been fixed.
Using these instructions the first time, you should be fine.
If you’ve already run them, then you need to:
cd vendor/gems/jasmine git pull cd ../../.. bundle install
rake jasmine:ci should work fine.
About the AuthorMore Content by Davis W. Frank