Guard::Jasmine automatically tests your Jasmine specs when files are modified.
Tested on MRI Ruby 1.8.7, 1.9.2, REE and the latest versions of JRuby & Rubinius.
If you have any questions please join us on our Google group or on
Continuous testing based on file modifications by Guard, manifold configuration by writing rules with RegExp and Ruby.
Fast headless testing on PhantomJS, a full featured WebKit browser with native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
Runs on Mac OS X, Linux and Windows.
How it works
- Guard is triggered by a file modification.
- Guard::Jasmine executes the PhantomJS script.
- The PhantomJS script requests the Jasmine test runner via HTTP.
- Rails uses the asset pipeline to get the Jasmine runner, the code to be tested and the specs.
- The asset pipeline prepares the assets, compiles the CoffeeScripts if necessary.
- The asset pipeline has finished to prepare the needed assets.
- Rails returns the Jasmine runner HTML.
- PhantomJS requests linked assets and runs the Jasmine tests headless.
- The PhantomJS script extracts the result from the DOM and returns a JSON report.
- Guard::Jasmine reports the results to the console and system notifications.
Guard and Guard::Jasmine
Please be sure to have Guard installed.
Install the gem:
$ gem install guard-jasmine
Add it to your
Gemfile, preferably inside the development group:
Add guard definition to your
Guardfile by running this command:
$ guard init jasmine
Please read the detailed installation and configuration instructions at Jasminerice.
In short, you add it to your
group :development, :test do gem 'jasminerice' end
and add a route for the Jasmine Test Runner to
if ["development", "test"].include? Rails.env mount Jasminerice::Engine => "/jasmine" end
Next you create the directory
asset pipeline manifest in
You need the PhantomJS browser installed on your system. You can download binaries for Mac OS X and Windows from the PhantomJS download section.
Alternatively you can install Homebrew on Mac OS X and install it with:
$ brew install phantomjs
If you are using Ubuntu 10.10, you can install it with apt:
$ sudo add-apt-repository ppa:jerome-etienne/neoip $ sudo apt-get update $ sudo apt-get install phantomjs
You can also build it from source for several other operating systems, please consult the PhantomJS build instructions.
Please read the Guard usage documentation.
Guard::Jasmine can be adapted to all kind of projects. Please read the Guard documentation for more information about the Guardfile DSL.
There are many options that can customize Guard::Jasmine to your needs. Options are simply supplied as hash when
defining the Guard in your
guard 'jasmine', :all_on_start => false, :specdoc => :always do ... end
The general options configures the environment that is needed to run Guard::Jasmine:
:jasmine_url => 'http://192.168.1.5/jasmine' # URL where Jasmine is served. # default: http://127.0.0.1/jasmine :phantomjs_bin => '~/bin/phantomjs' # Path to phantomjs. # default: '/usr/local/bin/phantomjs'
Spec runner options
The spec runner options configures the behavior driven development (or BDD) cycle:
:all_on_start => false # Run all suites on start. # default: true :keep_failed => false # Keep failed suites and add them to the next run again. # default: true :all_after_pass => false # Run all suites after a suite has passed again after failing. # default: true
:keep_failed failed option remembers failed suites and not failed specs. The reason for this decision is to
avoid additional round trip time to request the Jasmine test runner for each single spec, which is mostly more expensive
than running a whole suite.
Guard::Jasmine can generate an RSpec like specdoc in the console after running the specs and you can set when it will be shown in the console:
:specdoc => :always # Specdoc output options, either :always, :never or :failure # default: :failure
With the option set to
:always, the specdoc is shown with and without errors in your spec, whereas on with the option
:never, there is no output at all, instead just a summary of the spec run is shown. The default option
:failure shows the specdoc when at least one spec failed.
System notifications options
These options affects what system notifications (growl, libnotify or notifu) are shown after a spec run:
:notifications => false # Show success and error notifications. # default: true :hide_success => true # Disable successful spec run notification. # default: false :max_error_notify => 5 # Maximum error notifications to show. # default: 3
A note on Rails 2 and 3
This readme describes the use of Guard::Jasmine with Jasminerice through the asset pipeline, but it is not really a requirement for Guard::Jasmine. As long as you serve the Jasmine test runner under a certain url, it's freely up to you how you'll prepare the assets and serve the Jasmine runner.
You can use the Jasmine Gem, configure the test suite in
jasmine.yml and start the Jasmine test runner with
the supplied Rake task:
$ rake jasmine
Next follows an example on how to configure your
Guardfile with the Jasmine gem:
It is also possible to use CoffeeScript in this setup, by using Guard::CoffeeScript to compile your code and even specs. Just add something like this before Guard::Jasmine:
- guard-jasmine-headless-webkit, a Guard for jasmine-headless-webkit, but doesn't run on JRuby.
- Evergreen, runs CoffeeScript specs headless, but has no continuous testing support.
- Jezebel a Node.js REPL and continuous test runner for Jessie, a Node runner for Jasmine, but has no full featured browser environment.
- Documentation hosted at RubyDoc.
- Source hosted at GitHub.
- Report issues and feature requests to GitHub Issues.
Pull requests are very welcome! Please try to follow these simple "rules", though:
- Please create a topic branch for every separate change you make.
- Make sure your patches are well tested.
- Update the README (if applicable).
- Please do not change the version number.
For questions please join us on our Google group or on
The guard-jasmine executable
This Guard comes with a small executable
guard-jasmine that can be used to run the Jasmine test runner on PhantomJS
and see the JSON result that gets evaluated by Guard::Jasmine. This comes handy when there is an issue with your specs
and you want to see the output of the PhantomJS script.
The only argument that the script takes is the URL to the Jasmine runner, which defaults to
http://127.0.0.1:3000/Jasmine. So you can for example just run a subset of the specs by changing the URL:
$ guard-jasmine http://127.0.0.1:3000/Jasmine?spec=YourSpec
- Ariya Hidayat for PhantomJS, a powerful headless WebKit browser.
- Brad Phelan for Jasminerice, an elegant solution for Jasmine in the Rails 3.1 asset pipeline.
- The Guard Team for giving us such a nice piece of software that is so easy to extend, one has to make a plugin for it!
- All the authors of the numerous Guards available for making the Guard ecosystem so much growing and comprehensive.
(The MIT License)
Copyright (c) 2011 Michael Kessler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.