This project is intended to make it a little easier to integrate Jasmine into your workflow, particularly if you're working in Rails 3.1 or later. (If you're on earlier versions of Rails, I'd suggest directly using the combination of Pivotal's jasmine gem and jasmine-headless-webkit.)
By bundling this gem and configuring your project, you can expect to:
- Be able to run Jasmine specs from the command line (and fast) with John Bintz's excellent jasmine-headless-webkit
- Be able to run Jasmine specs in a browser (wherever you choose to mount the jasmine-rails engine)
- Write specs or source in CoffeeScript, leveraging the asset pipeline to pre-process it
Install qt for its headless webkit widget. The easiest way (on a Mac) that I've found is to use homebrew:
brew install qt
For help installing the qt libs on other platforms, the I'd recommend perusing capybara-webkit driver's documentation, becuse it has the same dependency.
Adding & configuring the gem
First, add jasmine-rails to your Gemfile, like so
group :test, :development do gem 'jasmine-rails' end
Writing asset manifests
I prefer to have just one asset manifest per project, as the
jasmine.yml file above suggests. One way to accomplish that is to require your
vendor (and, if necessary,
lib) manifests within your application manifest. For an example, check out the repo's dummy project.
//= require vendor //= require_tree .
//= require jquery //= require jquery_ujs //= require_tree .
Running from the command line
If you were to run:
bundle exec jasmine-headless-webkit --color
You'd hopefully see something like:
Running Jasmine specs... PASS: 0 tests, 0 failures, 0.001 secs.
I encourage you to explore John Bintz's excellent jasmine-headless-webkit's documentation for more ideas, like creating a Rake task or running it on a display-less CI server.
Running from your browser
Just mount jasmine-rails by adding something like this to your routes.rb:
mount JasmineRails::Engine => "/specs" unless Rails.env.production?
Now when you run
bundle exec rails s, and navigate to http://localhost:3000/specs, you should see a Jasmine spec runner in your browser.
In your browser
[When debugging, if you've disabled the asset pipeline's debug mode in dev/test, you may need to append the query param
?debug_assets=true like so: http://localhost:3000/specs?debug_assets=true. The asset pipeline will include individual
script tags for each of your scripts when in debug mode, which migh tmake debugging easier.]
From the command line
Even though they both read from the same config file, it's certainly possible that your specs will pass in the browser and fail from the command line. In this case, you can try to debug or analyze what's going on by using the "--keep" flag from jasmine-headless-webkit.
bundle exec jasmine-headless-webkit --keep
If the tests fail, jasmine-headless-webkit will leave its generated spec runner HTML file persisted in your rails root folder. It'll be named something like "jhw.48160.html".
Guard is a great tool for triggering spec runs when files change. To use it, you can bundle these gems:
group :development do ... gem 'guard-jasmine-headless-webkit' ... end
In my Guardfile, this configuration is working well for me:
Finally, to run guard, just:
bundle exec guard