Skip to content

searls/jasmine-headless-webkit-rails-skeleton

Repository files navigation

This is a skeleton app demonstrating jasmine-headless-webkit. Be sure to check out its page for detailed instructions.

Check this out if you want to:

  • write Jasmine specs
  • use CoffeeScript
  • leverage the asset pipeline in Rails 3.1
  • run specs headless & quickly enough to remove browser-refreshing from your workflow
  • (optional) getting growl notifications via Guard as your specs run

##Prerequisites

This was put together running Mac OS X Lion (10.7). I'm sure the details will differ slightly on other platforms.

Install XCode & Growl.

Install QT with homebrew. (Full disclosure: upon running brew update, I needed to git stash in /usr/local then git pull to get the latest recipes.)

brew update
brew install qt

##Try it out

Once you've cloned this repository and changed into the directory, you should be able to run the Jasmine specs like so:

bundle install
bundle exec guard

When you run guard, it first compiles your assets, run your specs and then monitors for changes.

Note: if you don't care for the Growl, make sure you remove growl_notify from the Gemfile to prevent exceptions.

##Running specs in your browser

If you'd like to run your specs in a browser, which is obviously very helpful when debugging, you can do so by visiting http://localhost:3000/jasmine.

The browser runner is generated by a rails engine by a jasmine-rails gem (which I'm hoping to also add some generator magic to)

##The play-by-play

If you're looking to recreate a similar setup for your existing project, here are most of the steps I took.

###Dependencies

Added to your Gemfile:

group :test, :development do
  gem 'jasmine-rails'

  if RUBY_PLATFORM =~ /darwin/i
    gem 'growl_notify'
    gem 'rb-fsevent', :require => false 
  end
  gem 'guard-rails-assets'
  gem 'guard-jasmine-headless-webkit'
end

###Jasmine config Next, Run:

jasmine init

This will create a little structure, most importantly your spec/javascripts/support/jasmine.yml configuration file. You can safely remove lib/tasks/jasmine.rake, though.

Then, update your jasmine.yml file to look for CoffeeScript in the assets directories. Mine looks something like this.

src_files:
  - "vendor/**/*.{js,coffee}"
  - "lib/**/*.{js,coffee}"
  - "public/**/*.{js,coffee}"
helpers:
  - "helpers/**/*.{js,coffee}"
spec_files:
  - "**/*[Ss]pec.{js,coffee}"
src_dir:
spec_dir: spec/javascripts

###Guard I set guard up by running

bundle exec guard init rails-assets
bundle exec jasmine-headless-webkit

And changed these lines in my Guardfile to monitor all of my assets directories (under app, lib, and vendor):

guard 'rails-assets' do
  watch(%r{^*/assets/.+$})
  ...
end

guard 'jasmine-headless-webkit' do
  ...
  watch(%r{^.*/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
  ...
end

Notes

Many thanks to John Bintz for making jasmine-headless-webkit, it's a wonderful tool.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published