Skip to content

Instantly share code, notes, and snippets.

@kulesa
Created January 24, 2010 12:02
Show Gist options
  • Save kulesa/285171 to your computer and use it in GitHub Desktop.
Save kulesa/285171 to your computer and use it in GitHub Desktop.
# use watchr watchr.rb
require 'fileutils'
require 'growl'
$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
def report_to_growl(file)
output = %x(spec #{file} --drb --colour --format progress)
summary = output.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
puts output
if summary
if $~[2].to_i > 0
Growl.notify_error "Failed: #{summary}\n#{output}"
else
Growl.notify_ok "Passed: #{summary}"
end
end
end
watch( '^spec/(.*)/(.*)\.rb' ) { |md|
modified?(md[0]) && report_to_growl(md[0])
}
watch( '^app/(.*)/(.*)\.rb' ) { |md|
modified?(md[0]) && report_to_growl("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