Gem Version Build Status Dependency Status Code Climate Coverage Status

Guard::RSpec allows to automatically & intelligently launch specs when files are modified.

  • Compatible with RSpec >2.14 & 3
  • Tested against Ruby 1.9.3, 2.0.0, 2.1.2, JRuby and Rubinius.


Add the gem to your Gemfile (inside development group):

 gem 'guard-rspec', require: false

Add guard definition to your Guardfile by running this command:

$ guard init rspec


Please read Guard usage doc.


Guard::RSpec can be adapted to all kinds of projects, some examples:

Standard RubyGem project

guard :rspec, cmd: 'rspec' do
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

Typical Rails app

guard :rspec, cmd: 'bundle exec rspec' do
  watch('spec/spec_helper.rb')                        { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_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"] }

Please read Guard doc for more information about the Guardfile DSL.


Guard::RSpec 4.0 now uses a simpler approach with the new cmd option that let you precisely define which rspec command will be launched on each run. This option is required due to the number of different ways possible to invoke rspec, the template now includes a default that should work for most applications but may not be optimal for all. As example if you want to support Spring with a custom formatter (progress by default) use:

guard :rspec, cmd: 'spring rspec -f doc' do
  # ...

Running with bundler

Running bundle exec guard will not run the specs with bundler. You need to change the cmd option to bundle exec rspec:

guard :rspec, cmd: 'bundle exec rspec' do
  # ...

List of available options:

cmd: 'zeus rspec'      # Specify a custom rspec command to run, default: 'rspec'
cmd_additional_args: '-f progress' # Any arguments that should be added after the default
                                   # arguments are applied but before the spec list
spec_paths: ['spec']   # Specify a custom array of paths that contain spec files
failed_mode: :focus    # What to do with failed specs
                       # Available values:
                       #  :focus - focus on the first 10 failed specs, rerun till they pass
                       #  :keep - keep failed specs until they pass (add them to new ones)
                       #  :none (default) - just report
all_after_pass: true   # Run all specs after changed specs pass, default: false
all_on_start: true     # Run all the specs at startup, default: false
launchy: nil           # Pass a path to an rspec results file, e.g. ./tmp/spec_results.html
notification: false    # Display notification after the specs are done running, default: true
run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs
title: 'My project'    # Display a custom title for the notification, default: 'RSpec results'
chdir: 'directory'     # run rspec from within a given subdirectory (useful if project has separate specs for submodules)

Using Launchy to view rspec results

guard-rspec can be configured to launch a results file in lieu of outputing rspec results to the terminal. Configure your Guardfile with the launchy option:

guard :rspec, cmd: 'rspec -f html -o ./tmp/spec_results.html', launchy: './tmp/spec_results.html' do
  # ...


Pull requests are very welcome! Please try to follow these simple rules if applicable:

  • Please create a topic branch for every separate change you make.
  • Make sure your patches are well tested. All specs run with rake spec:portability must pass.
  • Update the README.
  • Please do not change the version number.

For questions please join us in our Google group or on #guard (


Thibaud Guillaume-Gentil (@thibaudgg)