Skip to content

Instantly share code, notes, and snippets.

@kurbmedia
Created January 13, 2011 02:17
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 kurbmedia/777291 to your computer and use it in GitHub Desktop.
Save kurbmedia/777291 to your computer and use it in GitHub Desktop.
.watchr for spec files. if anyone knows how to show result #s in growl AND keep color output <3
# vim:set filetype=ruby:
def growl
title = "Watchr Test Results"
image = $?.success? ? "~/.watchr/images/passed.png" : "~/.watchr/images/failed.png"
message = $?.success? ? "success" : "failed"
growlnotify = `which growlnotify`.chomp
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
end
def run(cmd)
puts cmd
system(cmd)
end
def spec(file)
if File.exists?(file)
run("rspec #{file}")
growl
else
puts("Spec: #{file} does not exist.")
end
end
def run_all_specs
run "rake spec"
growl
end
def run_suite
system "clear"
run_all_specs
end
watch("spec/.*/*_spec\.rb") do |match|
puts(match[0])
spec(match[0])
end
watch("lib/(.*/.*)\.rb") do |match|
puts(match[1])
spec("spec/#{match[1]}_spec.rb")
end
# Ctrl-\
Signal.trap 'QUIT' do
puts " --- Running all tests ---\n\n"
run_suite
end
# Ctrl-C
Signal.trap 'INT' do
if @interrupted then
abort("\n")
else
puts "Interrupt a second time to quit"
@interrupted = true
Kernel.sleep 1.5
# raise Interrupt, nil # let the run loop catch it
run_suite
@interrupted = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment