1
0
Fork 1
mirror of https://github.com/wezm/wezm.net.git synced 2024-12-26 14:09:55 +00:00
wezm.net/v1/content/technical/2011/01/automatically-build-and-test-with-guard.markdown

1.5 KiB

I'm currently working on a node.js module (node-genx) with a C++ component. Each time a change was made to the code its necessary to rebuild the module then run the tests. This was getting tiring so I decided to use guard to automate the process.

guard is a ruby gem that provides a DSL for performing actions when a set of watched files change. There a bunch of "guards" available that provide out of the box support for things like rspec, jammit, sass and CoffeeScript. For simple custom cases like mine there is also guard-shell, which will run a shell command when one of its watched files changes.

guard uses a Guardfile akin to a Makefile in you project directory to configure the guards. Mine looks like this:

guard 'shell' do
  watch(%r".*\.(?:cc|h)") { |m| `node-waf build && jasbin` }
  watch(%r"spec/.*_spec\..*") {|m| `jasbin --verbose` }
end

This runs node-waf build && jasbin to rebuild the module and run the tests when any of the C++ source files or headers change. It just runs the the tests when any of the spec files change.

Once your Guardfile is setup simply run guard in you project directory and it will start watching for changes.