Skip to content

Instantly share code, notes, and snippets.

@janx
Created November 5, 2009 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janx/226978 to your computer and use it in GitHub Desktop.
Save janx/226978 to your computer and use it in GitHub Desktop.
require 'fileutils'
$cache_dir = File.join('tmp', 'watchr')
FileUtils.mkdir_p($cache_dir) unless File.exist?($cache_dir)
def modified?(file)
cache_file = File.join $cache_dir, file
`diff #{file} #{cache_file} >/dev/null 2>&1`
if $? != 0
cache_file_dir = File.dirname cache_file
FileUtils.mkdir_p(cache_file_dir) unless File.exist?(cache_file_dir)
FileUtils.cp file, cache_file
return true
end
false
end
watch( '^spec/(.*)/(.*)\.rb' ) { |md|
modified?(md[0]) && system("spec #{md[0]} --drb --colour --format progress")
}
watch( '^app/(.*)/(.*)\.rb' ) { |md|
modified?(md[0]) && system("spec --drb --colour --format progress spec/#{md[1]}/#{md[2]}_spec.rb")
}
Signal.trap('INT') {
FileUtils.rm_r $cache_dir
abort("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment