Created
November 16, 2011 16:30
-
-
Save pubis/1370554 to your computer and use it in GitHub Desktop.
Rails 3.1 + Mongoid + rspec2 + guard + spork + factory girl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is my take on a rails 3.1 setup with mongoid, rspec2, guard, spork | |
# and factory girl. | |
# | |
# Thanks to: | |
# http://gist.github.com/568754/ (inspiration) | |
# http://railscasts.com/episodes/275-how-i-test (rspec and guard) | |
# http://railscasts.com/episodes/285-spork (spork and guard) | |
# http://github.com/diaspora/diaspora (.rvmrc) | |
# http://stackoverflow.com/questions/7801073/spork-timer-not-resetting-between-runs | |
# and others... | |
$ rails new appname -O -T --skip-bundle | |
$ cd appname | |
$ touch .rvmrc | |
$ mate . | |
edit Gemfile | |
edit .rvmrc | |
$ . .rvmrc | |
$ gem install bundler | |
$ bundle install | |
$ rails g mongoid:config | |
$ rails g rspec:install | |
$ mkdir -v spec/{support,models,routing} | |
$ spork --bootstrap | |
$ guard init spork | |
$ guard init rspec | |
edit spec/spec_helper.rb | |
edit Guardfile | |
# On Mac OSX | |
$ gem install rb-fsevent | |
# TODO: On Linux | |
$ | |
# Quickstart with Twitter bootstrap | |
$ cd .. | |
$ git clone git://github.com/twitter/bootstrap.git | |
$ cd appname | |
$ cp ../bootstrap/bootstrap.min.css app/assets/stylesheets/ | |
$ cp ../bootstrap/js/bootstrap-* app/assets/javascripts/ | |
$ guard | |
# Start TDD'ing... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -e '.rvmrc_custom' ]; then | |
source .rvmrc_custom; | |
else | |
rvm --create use 1.9.2@appname; | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org' | |
gem 'rails', '3.1.1' | |
# gem 'rails', :git => 'git://github.com/rails/rails.git' | |
gem 'mongoid' | |
gem 'bson_ext' | |
gem 'therubyracer' | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.1.4' | |
gem 'coffee-rails', '~> 3.1.1' | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' | |
# To use ActiveModel has_secure_password | |
# gem 'bcrypt-ruby', '~> 3.0.0' | |
# To use debugger | |
# gem 'ruby-debug19', :require => 'ruby-debug' | |
gem 'rspec-rails', :group => [:test, :development] | |
group :test do | |
# Pretty printed test output | |
gem 'turn', :require => false | |
gem 'factory_girl_rails' | |
gem 'guard-rspec' | |
gem 'spork', '~> 0.9.0.rc' | |
gem 'guard-spork' | |
gem 'mongoid-rspec' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Make sure spork is loaded before rspec | |
# 2. Around line 15 change | |
guard 'rspec', :version => 2 do | |
# to (all on start and pass are of course optional) | |
guard 'rspec', :version => 2, :cli => "--drb", :all_on_start => false, :all_after_pass => false do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'spork' | |
Spork.prefork do | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'factory_girl' | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
RSpec.configure do |config| | |
include Mongoid::Matchers | |
# config.mock_with :mocha | |
# config.mock_with :flexmock | |
# config.mock_with :rr | |
config.mock_with :rspec | |
config.infer_base_class_for_anonymous_controllers = false | |
end | |
end | |
Spork.each_run do | |
# reset spork/rspec timer | |
# you are advised that this may break in future versions of rspec | |
$rspec_start_time = Time.now | |
clear_db | |
end | |
# Apparently there is no way to _not_ have persistence on the test database when using Mongo | |
# so here is a convenient helper for it that also gets called before each run. | |
def clear_db | |
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment