You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jasmine headless testing on Rails 3 asset pipeline
assets and specs can be CoffeeScript
3rd party JS can be placed to vendor/assets/javascripts or vendor gems
detects gem-vendored JS via application.js require
uses jasmine-headless-webkit to run the suite outside the browser
this requires Qt4.7 installation
Gemfile
group :development, :test do
# jasmine 1.2.0.rc2 and jhw 0.9.0.rc1
gem 'jasmine', :git => "git://github.com/pivotal/jasmine-gem.git"
gem 'jasmine-headless-webkit', :git => "git://github.com/johnbintz/jasmine-headless-webkit.git"
end
# add gems that vendor 3rd party JS
gem "jquery-rails"
app/assets/javascripts/application.js
//= require jquery
Jasmine init
$ bundle install
$ bundle exec rails g jasmine:install
spec/javascripts/support/jasmine.yml
# src_files
#
# An array of filepaths relative to asset_paths to include.
#
src_files:
- application.js # require gem vendored assets (such as jQuery) in application.js
- some.plugin.js # loaded from vendor/assets/javascripts
- app/assets/javascripts/*.js.coffee # load all custom CS files
- my.custom.js.coffee # ..or individually without path prefix
# asset_paths
#
# Paths you would like to be served by the Sprockets asset pipeline.
#
# If you include your spec_dir (eg: - spec/javascripts ) here,
# Jasmine will use the Sprockets asset pipeline to build your spec files.
#
asset_paths:
- app/assets/javascripts
- vendor/assets/javascripts
spec_dir: spec/javascripts
spec_files:
- "**/*[sS]pec.js.coffee"
# helpers
#
# Spec helpers relative to spec_dir to include.
#
helpers:
- helpers/**/*.js.coffee
spec/javascripts/example_spec.js.coffee
describe 'example', ->
it 'should have jQuery', ->
expect(jQuery).toBeDefined()
Yes, jquery-rails assets incl. jquery.js is reported by the -l switch.
Still, jquery.js will not load if given explicitly in src_files, it needs to be required through application.js.
That sounds like a bug more than anything, probably a good one for me to squash before 0.9 release. Can you write up a quick issue on the JHW project? I'll look at it later today.
I replaced headless gem with this one. It fixed an issue I was having with jasmine referencing jquery-rails installed jquery. Thank you for these instructions.
Great! I think the only change is that the asset paths key in
jasmine.yml
should beasset_paths
instead ofasset_pipeline_paths
.