Wynn Netherland changelog.com/posts

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
      Runner.set_rspec_version(options)
    end

    def run_all
      Runner.run ["spec"], :message => "Running all specs"
    end

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

  end
end

Now you can use the guard using the Guard DSL

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

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]


Discussion

Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00