Skip to content

Instantly share code, notes, and snippets.

@darylf
Created August 27, 2011 22:01
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 darylf/1175908 to your computer and use it in GitHub Desktop.
Save darylf/1175908 to your computer and use it in GitHub Desktop.
Combining Watchr, Spork, and Growl for Ruby on Rails testing.
# Combined from:
# [1] http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html
# [2] https://gist.github.com/600976
unless defined?(GROWL)
$stderr.sync=true
$stdout.sync=true
ENV["WATCHR"] = "1"
GROWL=`which growlnotify`.chomp
IMAGE_DIR=File.expand_path("~/.watchr_images/")
SPORK=true
#assumes we are running from the rails root
#Dir.chdir(File.dirname(__FILE__))
end
def growl(message,title=nil,image=nil)
return if GROWL.empty?
title ||= "Watchr Test Results"
message.gsub! /\[[0-9]+?m/, ''
image ||= message.include?('0 failures, 0 errors') ? "#{IMAGE_DIR}/pass.png" : "#{IMAGE_DIR}/fail.png"
options = "-n Watchr --image '#{image}' -m '#{message}' '#{title}'"
puts "#{GROWL} #{options}"
run "#{GROWL} #{options}"
end
def run(cmd,verbose=false)
# puts
puts("# #{cmd}")
# puts
ret=[]
IO.popen(cmd) do |output|
while line = output.gets do
puts line if verbose
ret << line
end
end
ret #join("\n")
end
def generate_message(result)
#result.last
#we have messages turned off
#need to parse results to get something close
failures=result.count { |s| s =~/Failure/ }
errors=result.count { |s| s =~/Error/ }
"#{failures} failures, #{errors} errors"
end
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
results = run "bundle exec rspec #{file}"
growl generate_message(results)
puts
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
@bwobst
Copy link

bwobst commented Feb 4, 2013

Growl works great, but the images aren't showing up even though they're in the "~/.watchr_images/" folder. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment