Created
May 13, 2011 17:45
-
-
Save koko-u/970977 to your computer and use it in GitHub Desktop.
ファイルの更新に伴い、実行した spec の結果を gnome に通知する watchr
This file contains hidden or 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 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