Skip to content

Instantly share code, notes, and snippets.

@dedene
Forked from adragomir/rails-backbone-test-setup.md
Created September 2, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedene/3605304 to your computer and use it in GitHub Desktop.
Save dedene/3605304 to your computer and use it in GitHub Desktop.
Setting up a Rails backbone project with Jasmine, RSpec, Capybara, Guard and Spork

Rails backbone test setup

This gist describes how to setup a rails backbone project with testing frameworks.

Gemfile

Example Gemfile to start with.

source 'http://rubygems.org'

gem 'rails', '3.1.3'
gem 'sqlite3'

gem 'backbone-on-rails'
gem 'jquery-rails'
gem 'eco'

group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

group :development, :test do
  gem 'jasmine'
  gem 'jasminerice'
  gem 'database_cleaner'
  gem 'capybara'
  gem 'capybara-webkit'
  gem 'rspec', ">= 2.5.0"
  gem "rspec-rails", ">= 2.5.0"
  gem "factory_girl_rails", "~> 1.1.rc1"
  gem 'ruby_gntp'
  gem 'guard-rspec'
  gem 'spork', '~> 0.9.0.rc'
  gem 'guard-spork'
  gem 'guard-jasmine'
  gem 'turn', :require => false
end

Run bundle install

Setup

Now run the following commands from the Terminal to setup Backbone, RSpec, Capybara, Guard and Spork.

rails g rspec:install
guard init
guard init spork
guard init rspec
guard init jasmine
spork --bootstrap
rails g backbone:install

Open up the spec/spec_helper.rb file and follow the directions therein to setup Spork.

Also add the following lines to use Capybara with webkit as default JS driver.

# Add after require 'rspec/autorun'
require 'capybara/rspec'

# Setup capybara webkit as the driver for javascript-enabled tests.
Capybara.javascript_driver = :webkit

Jasmine

To setup Jasmine run the following from the Terminal:

mkdir -p spec/javascripts
echo -e "#=require application\n#=require_tree ./" > spec/javascripts/spec.js.coffee
echo -e "/*\n * add css using =require application\n */" > spec/javascripts/spec.css

This creates the directory spec/javascripts where your CoffeeScript tests go into. You define the Rails 3.1 asset pipeline manifest in spec/javascripts/spec.js.coffee:

#=require application
#=require_tree ./

It also creates an empty spec/javascripts/spec.css file as it is always requested when running specs.

Run

Now just fire up the test servers using:

guard

Et voila! You're good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment