Skip to content

Instantly share code, notes, and snippets.

@JayK31
Forked from phlco/guard_setup.md
Created April 6, 2014 17:40
Show Gist options
  • Save JayK31/10009196 to your computer and use it in GitHub Desktop.
Save JayK31/10009196 to your computer and use it in GitHub Desktop.

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
@JayK31
Copy link
Author

JayK31 commented Apr 6, 2014

Note

guard init:rspec should be guard init spec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment