Guard watches a directory and runs commands when it sees changes to files.
This is great for automating your rspec tests!
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
$ bundle exec guard
Keep Guard open in one Terminal window. Anytime you save your files it should rerun your tests.
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
Note
guard init:rspec
should beguard init spec