Skip to content

Instantly share code, notes, and snippets.

@jeffcole
Last active August 29, 2015 14:00
Show Gist options
  • Save jeffcole/812300b0695dd044f7d1 to your computer and use it in GitHub Desktop.
Save jeffcole/812300b0695dd044f7d1 to your computer and use it in GitHub Desktop.
Guard and Spork Setup for Rails 3.x
# Instructions
# 1. Add the following to the indicated files
# 2. $ bundle
# 3. $ guard
# 4. Specs should run automatically on file save
#
# Note that some finagling of gem versions might be necessary depending on the
# project.
# .rspec
--drb
# Gemfile
group :test do
gem "childprocess"
gem "rb-fsevent", require: false
gem "guard", '>=2.1.0'
gem "guard-rspec"
gem "guard-spork"
gem "spork", "~> 1.0.0rc4"
end
# spec/spec_helper.rb
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# Routes reload
require 'rails/application'
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# Existing spec_helper here
end
# Guardfile
guard 'spork', rspec_env: { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('spec/support/')
end
guard 'rspec', all_on_start: false, all_after_pass: false, cmd: 'rspec --drb' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment