From b373b3ced75365cff4f456dcbf2e5e0b6f493384 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 26 May 2011 10:31:56 -0400 Subject: [PATCH] initial work on notifier --- lib/guard/jasmine-headless-webkit/runner.rb | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/guard/jasmine-headless-webkit/runner.rb b/lib/guard/jasmine-headless-webkit/runner.rb index d2761e3..e7ee617 100644 --- a/lib/guard/jasmine-headless-webkit/runner.rb +++ b/lib/guard/jasmine-headless-webkit/runner.rb @@ -1,8 +1,31 @@ +require 'guard/notifier' + module Guard class JasmineHeadlessWebkitRunner class << self def run(paths = []) - system %{jasmine-headless-webkit -c #{paths.join(" ")}} + passes = fails = 0 + capturing = 0 + + Open3.popen3(%{jasmine-headless-webkit -c #{paths.join(" ")}}) do |stdin, stdout, stderr| + stdin.close + stderr.close + while !stdout.eof? + $stdout.print (char = stdout.getc) + $stdout.flush + + case char.chr + when "\n" + capturing += 1 + when '.' + passes += 1 if capturing == 1 + when "F" + fails += 1 if capturing == 1 + end + end + end + + Notifier.notify("#{passes + fails} examples, #{fails} failures", :title => 'Jasmine results', :image => (fails == 0) ? :success : :failes) $?.exitstatus end end