Created
February 9, 2012 09:51
-
-
Save marugoshi/1778935 to your computer and use it in GitHub Desktop.
My .watchr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run(cmd) | |
`#{cmd}` | |
end | |
def run_spec(file) | |
unless File.exist?(file) | |
puts "#{file} does not exist" | |
return | |
end | |
puts "Running #{file}" | |
system "clear" | |
result = run("bundle exec rspec -fs --color --tty #{file}") | |
growl result.split("\n").last rescue nil | |
puts result | |
end | |
def growl(message) | |
growlnotify = `which growlnotify`.chomp | |
title = "Watchr Test Results" | |
options = "-w -n Watchr -m '#{strip_ansi(message)}' '#{title}'" | |
run("#{growlnotify} #{options} &") | |
end | |
def strip_ansi(m) | |
m.gsub(/\e\[[^m]*m/, '') | |
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 | |
watch("config/.*\.rb|spec/spec_helper.rb|spec/support/.*/.*\.rb") do |match| | |
Process.kill(:TERM, `ps -ef | grep spork | grep -v grep | awk '{ print $2 }'`.to_i) | |
spawn('spork') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment