Skip to content

Instantly share code, notes, and snippets.

@koko-u
Created May 13, 2011 17:45
Show Gist options
  • Save koko-u/970977 to your computer and use it in GitHub Desktop.
Save koko-u/970977 to your computer and use it in GitHub Desktop.
ファイルの更新に伴い、実行した spec の結果を gnome に通知する watchr
def notify(title, message, image)
system "notify-send '#{title}' '#{message}' -i '#{image}' -t 2000"
end
def run_withnotify(*files)
image_root = File.expand_path("~/.autotest_images")
puts "Running: #{files.join(' ')}"
puts results = `bundle exec rspec -f p -c #{files.join(' ')}`
output, _, fail_count, _, pending_count =
*/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spendings?)?/.match(results)
if fail_count.to_i > 0
notify "FAIL", "#{output}", "#{image_root}/fail.png"
elsif pending_count.to_i > 0
notify "Pending", "#{output}", "#{image_root}/pending.png"
else
notify "Pass", "#{output}", "#{image_root}/pass.png"
end
no_int_for_you
end
def run_all_specs
run_withnotify *Dir["spec/**/*_spec.rb"]
end
watch("spec/.*/*_spec\.rb") do |match|
run_withnotify match[0]
end
watch("app/(.*/.*)\.rb") do |match|
run_withnotify %{spec/#{match[1]}_spec.rb}
end
watch("app/views/(.*)/.*\.html\.erb") do |match|
if match[1] == "layouts"
run_withnotify *Dir["spec/requests/*_spec.rb"]
else
run_withnotify %{spec/requests/#{match[1]}_spec.rb}
end
end
watch("config/routes.rb") do |match|
run_withnotify *Dir["spec/routing/*_spec.rb"]
end
# ----------------------------------------------------------------------
# Signal Hacking
# ----------------------------------------------------------------------
def no_int_for_you
@sent_an_int = nil
end
Signal.trap 'INT' do
if @sent_an_int
puts " A second INT? ok, I get the message, Shutting down now..."
exit
else
puts " Did you just send me an INT Ugh. I'll quit for real if you do it again."
@sent_an_int = true
Kernel.sleep 1.5
run_all_specs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment