It is very easy to integrate Jasmine into Rails, since the team provides the
jasmine gem. The jasmine gem also supports assets pipeline, just prepend
assets/ to file path. For example,
spec_files does not support assets pipeline, so the files in
src_files in jasmine.yml.
I also created a demo repository, see its commits for integration steps.
Jasmine 1.3.1 removes the
ability to load
jasmine_config.rb before executing specs. Although it is
possible to load the file by
adding a rake dependency, but the trick
does not work for
rake jasmine:ci. So please use Jasmine 1.3.0 until a new
version is released.
First add jasmine in Gemfile
group :development, :test do gem "jasmine", "1.3.0" end
Then generate config files:
rails g jasmine:install
Rails.application.assets.append_path File.expand_path('../..', __FILE__)
src_files. Also set
src_files: - assets/application.js - assets/specs.js stylesheets: - stylesheets/**/*.css helpers:  spec_files:  src_dir: spec_dir:
Create the file
// Ensure helpers are loaded first. Remove the following line if // helpers directory is not created yet. //= require_tree ./helpers //= require_tree ./
Create a spec file to test the integration, e.g.,
Start jasmine server by
rake jasmineand visit the test page http://localhost:8888.
Add guard and guard-jasmine in Gemfile.
group :development do gem 'guard' gem 'guard-jasmine' end
Add following jasmine guard config in Guardfile
guard-jasmine will start the server provided by
jasmine-gem and visit
the test page using phantomjs.
The jasmine gem has another task
rake jasmine:ci for continuous integration
environments. To run the test on server without GUI,
xvfb can be used.
See the following
xvfb is started and
DISPLAY is set so GUI applications know where to render their window.
language: ruby script: bundle exec rake jasmine:ci before_install: - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16" - "export DISPLAY=:99.0" - "export JASMINE_BROWSER=firefox"