UPDATE – as of Rails 3.1.rc8 nothing in this post works at all. Once I figure it out I’ll post the results here.
To start, we looked into several existing solutions, including the following:
After looking through them, we decided:
- we didn’t want to add a route to our app just to run tests
- we didn’t want to add Barista just for Jasmine (since we already had the ‘blessed’ asset pipeline)
- we didn’t want to have to run our Rails app in order to run jasmine tests, since setting that up on CI is a pain.
So we decided to roll our own. At a high level, we hooked into the Jasmine::Config class to clear and regenerate the rails assets into a tmp directory, compile the coffee script specs into a tmp directory, then run jasmine off of the compiled files.
# Gemfile group :development, :test do gem 'jasmine', '22.214.171.124' gem 'headless', '0.1.0' end
At this point you can delete the generated js example files and specs.
Write a spec in coffeescript
The Rails internals are likely to change, so we decided to only use the high-level rake tasks provided.
Make it pass
Making that spec pass is pretty simple, and looks something like this:
Make it run headlessly in CI
To get the specs to run headlessly, we added the following task (thanks to Mike Gehard for the pointers):
# lib/tasks/headless_jasmine.rake namespace :jasmine do namespace :ci do desc "Run Jasmine CI build headlessly" task :headless do Headless.ly do puts "Running Jasmine Headlessly" Rake::Task['jasmine:ci'].invoke end end end end
And we added the following to our build script:
# build.sh bundle exec rake jasmine:ci:headless
Git ignore the generated files
One final step before committing was to ignore those generated files:
About the Author