guard: Ruby DSL for creating filesystem watchers

Watching the filesystem and re-running test suites have long been the sweet spot for Autotest and Watchr. As more and more preprocessed tools like CoffeeScript and Sass are more widely adopted, there are a growing number of scenarios where you may want to watch the file system and act on the changes.

Rémy Coutable and Thibaud Guillaume-Gentil are developing Guard, a Ruby-based utility and DSL for building filesystem watchers. Guard uses FSEvent on OS X and lnotify on Linux to watch the filesystem and Growl on OS X and libnotify on Linux for notifications.

Guard is a gem so install with RubyGems:

gem install guard

To create a new Guard, just derive from the provided Guard base class, as in the Rspec example:

require 'guard'
require 'guard/guard'

module Guard
  class RSpec < Guard

    autoload :Runner, 'guard/rspec/runner'
    autoload :Inspector, 'guard/rspec/inspector'

    def start

    def run_all ["spec"], :message => "Running all specs"

    def run_on_change(paths)
      paths = Inspector.clean(paths) unless paths.empty?


Now you can use the guard using the Guard DSL

guard 'rspec' do
  watch('^lib/(.*).rb')                              { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('^spec/spec_helper.rb')                       { "spec" }

Currently, Guard has released guard-rspec and guard-livereload, but is looking for the community to pile on perhaps with some of the following:

  • guard-spork
  • guard-cucumber
  • guard-test
  • guard-sass
  • guard-bundler

Why not fork the project and contribute?

[Source on GitHub]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

0:00 / 0:00