Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

guard-rspec

> 编程语言
Open source

Guard::RSpec automatically run your specs (much like autotest)

1.3K stars0 likes2 views
WebsiteGitHub

About

Guard::RSpec automatically run your specs (much like autotest)

Guard::RSpec

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

  • Compatible with RSpec >2.99 & 3
  • Tested against Ruby 2.2.x, JRuby 9.0.5.0 and Rubinius.

Install

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

ruby
 gem 'guard-rspec', require: false

Add guard definition to your Guardfile by running this command:

$ bundle exec guard init rspec

Installing with beta versions of RSpec

To install beta versions of RSpec, you need to set versions of all the dependencies, e.g:

ruby
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:

ruby
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.

Usage

Please read Guard usage doc.

Guardfile

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

Standard RubyGem project

ruby
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

Typical Rails app

…

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

Options

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:

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

NOTE: the above example assumes you have the spring rspec command installed - see here: https://github.com/jonleighton/spring-commands-rspec

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:

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

List of available options:

…

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:

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

Zeus Integration

You 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

Using parallel_tests

parallel_tests has a -o option for passing RSpec options, and here's a trick to make it work with Guard::RSpec:

ruby
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)

Development

  • Documentation hosted at RubyDoc.
  • Source hosted at GitHub.

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 (irc.freenode.net).

Author

Thibaud Guillaume-Gentil (@thibaudgg)

Contributors

https://github.com/guard/guard-rspec/contributors

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言