Guard::RSpec automatically run your specs (much like autotest)
Guard::RSpec automatically run your specs (much like autotest)
Guard::RSpec allows to automatically & intelligently launch specs when files are modified.
Add the gem to your Gemfile (inside development group):
gem 'guard-rspec', require: falseAdd guard definition to your Guardfile by running this command:
$ bundle exec guard init rspecTo install beta versions of RSpec, you need to set versions of all the dependencies, e.g:
gem 'rspec', '= 3.5.0.beta3'
gem 'rspec-core', '= 3.5.0.beta3'
gem 'rspec-expectations', '= 3.5.0.beta3'
gem 'rspec-mocks', '= 3.5.0.beta3'
gem 'rspec-support', '= 3.5.0.beta3'
gem 'guard-rspec', '~> 4.7'and for Rails projects this also means adding:
gem 'rspec-rails', '= 3.5.0.beta3'and then running bundle update rspec rspec-core rspec-expectations rspec-mocks rspec-support rspec-rails or just bundle update to update all the gems in your project.
Please read Guard usage doc.
Guard::RSpec can be adapted to all kinds of projects, some examples:
guard :rspec, cmd: 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end…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
# ...
endNOTE: the above example assumes you have the spring rspec command installed - see here: https://github.com/jonleighton/spring-commands-rspec
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
# ...
end…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
# ...
endYou can use plain Zeus or you can use Guard::Zeus for managing the Zeus server (but you'll want to remove the spec watchers from Guard::Zeus, or you'll have tests running multiple times).
Also, if you get warnings about empty environment, be sure to read about this workaround
parallel_tests has a -o option for passing RSpec options, and here's a trick to make it work with Guard::RSpec:
rspec_options = {
cmd: "bundle exec rspec",
run_all: {
cmd: "bundle exec parallel_rspec -o '",
cmd_additional_args: "'"
}
}
guard :rspec, rspec_options do
# (...)(Notice where the ' characters are placed)
Pull requests are very welcome! Please try to follow these simple rules if applicable:
rake spec:portability must pass.For questions please join us in our Google group or on
#guard (irc.freenode.net).
Thibaud Guillaume-Gentil (@thibaudgg)
No open issues yet, or sync has not completed.