This gist describes how to setup a rails backbone project with testing frameworks.
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
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
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.
Now just fire up the test servers using:
guard
Et voila! You're good to go.