Skip to content

Instantly share code, notes, and snippets.

@CH-JesseMa
Forked from phlco/guard_setup.md
Created April 6, 2014 15:08
Show Gist options
  • Save CH-JesseMa/10007270 to your computer and use it in GitHub Desktop.
Save CH-JesseMa/10007270 to your computer and use it in GitHub Desktop.
How to Setup Guard

Setting up Guard with Rspec

Guard watches a directory and runs commands when it sees changes to files.

This is great for automating your rspec tests!

Set up

Add guard and guard-rspec to your Gemfile

# Gemfile
group :development do
    gem 'rspec'
    gem 'guard'
    gem 'guard-rspec'
end

Remember to run bundle!

Guard and Rspec need to be configured before you can use them.

$ rails g rspec:install
$ guard init:rspec

guard init:rspec creates a Guardfile in your app's root.

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

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

Now Run it!

$ bundle exec guard

Keep Guard open in one Terminal window. Anytime you save your files it should rerun your tests.

Terminal Notifier

To receive a MacOSx Notitication when your tests pass or fail add the following to your Gemfile

# Gemfile
group :development, :test do
    gem 'rspec'
    gem 'guard'
    gem 'guard-rspec'
    gem 'terminal-notifier-guard'  # Add this
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment