2011-05-26 14:31:56 +00:00
|
|
|
require 'guard/notifier'
|
2011-05-26 23:50:34 +00:00
|
|
|
require 'open3'
|
2011-05-26 14:31:56 +00:00
|
|
|
|
2011-05-24 01:28:01 +00:00
|
|
|
module Guard
|
|
|
|
class JasmineHeadlessWebkitRunner
|
|
|
|
class << self
|
|
|
|
def run(paths = [])
|
2011-05-26 15:26:47 +00:00
|
|
|
lines = [""]
|
2011-05-26 14:31:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-05-26 15:26:47 +00:00
|
|
|
if char.chr == "\n"
|
|
|
|
lines << ""
|
|
|
|
else
|
|
|
|
lines.last << char.chr
|
2011-05-26 14:31:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-26 15:26:47 +00:00
|
|
|
total, fails, secs = lines[-2].scan(%r{.* (\d+) tests, (\d+) failures, (.+) secs..*}).flatten
|
|
|
|
|
|
|
|
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
|
2011-05-24 01:28:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|