better notification support

This commit is contained in:
John Bintz 2011-05-26 11:26:47 -04:00
parent 5b19b21042
commit efa143697b
3 changed files with 30 additions and 12 deletions

View File

@ -20,5 +20,6 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.add_dependency 'guard', '>= 0.2.2' s.add_dependency 'guard', '>= 0.2.2'
s.add_dependency 'POpen4'
s.add_dependency 'jasmine-headless-webkit' s.add_dependency 'jasmine-headless-webkit'
end end

View File

@ -21,7 +21,7 @@ module Guard
end end
def run_on_change(paths) def run_on_change(paths)
run_all if JasmineHeadlessWebkitRunner.run(paths) != 1 run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
end end
end end

View File

@ -4,8 +4,7 @@ module Guard
class JasmineHeadlessWebkitRunner class JasmineHeadlessWebkitRunner
class << self class << self
def run(paths = []) def run(paths = [])
passes = fails = 0 lines = [""]
capturing = 0
Open3.popen3(%{jasmine-headless-webkit -c #{paths.join(" ")}}) do |stdin, stdout, stderr| Open3.popen3(%{jasmine-headless-webkit -c #{paths.join(" ")}}) do |stdin, stdout, stderr|
stdin.close stdin.close
@ -14,19 +13,37 @@ module Guard
$stdout.print (char = stdout.getc) $stdout.print (char = stdout.getc)
$stdout.flush $stdout.flush
case char.chr if char.chr == "\n"
when "\n" lines << ""
capturing += 1 else
when '.' lines.last << char.chr
passes += 1 if capturing == 1
when "F"
fails += 1 if capturing == 1
end end
end end
end end
Notifier.notify("#{passes + fails} examples, #{fails} failures", :title => 'Jasmine results', :image => (fails == 0) ? :success : :failed) total, fails, secs = lines[-2].scan(%r{.* (\d+) tests, (\d+) failures, (.+) secs..*}).flatten
$?.exitstatus
any_console = lines.any? { |line| line['[console] '] }
Notifier.notify(message(total, fails, secs, any_console), :title => 'Jasmine results', :image => image(any_console, fails))
fails.to_i
end
private
def message(total, fails, secs, any_console)
"#{total} tests, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
end
def image(any_console, fails)
if any_console
:pending
else
if fails.to_i == 0
:success
else
:failed
end
end
end end
end end
end end