Skip to content

Instantly share code, notes, and snippets.

@squarism
Created March 25, 2011 16:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squarism/887121 to your computer and use it in GitHub Desktop.
Save squarism/887121 to your computer and use it in GitHub Desktop.
Watchr file for use with spork, rails, rspec2 and growl
# sometimes watchr freaks out when you view this file in textmate (hits timestamp?)
# ie: it prints "Watching..." over and over
# just hit Ctrl-\ to run all tests and it calms down
ENV["WATCHR"] = "1"
puts "Watching..."
def growl(result)
result_lines = result.split("\n")
message = result_lines[result_lines.size - 1]
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
passed = message.include?('0 failures')
image = passed ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
severity = passed ? "-1" : "1"
options = "-w -n Watchr --image '#{File.expand_path(image)}'"
options << " -m '#{message}' '#{title}' -p #{severity}"
system %(#{growlnotify} #{options} &)
end
def run(cmd)
puts(cmd)
`time #{cmd}`
end
def run_all_tests
system('clear')
result = run "rake spec"
growl result rescue nil
puts result
end
def run_suite
run_all_tests
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
result = run("rspec #{file}")
growl result rescue nil
puts result
end
watch("spec/.*/*_spec\.rb") do |match|
run_spec match[0]
end
watch("app/(.*/.*)\.rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end
# Ctrl-\
Signal.trap 'QUIT' do
puts " --- Running all tests ---\n\n"
run_all_tests
end
@interrupted = false
# Ctrl-C
Signal.trap 'INT' do
if @interrupted then
@wants_to_quit = true
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
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment