better notification support
This commit is contained in:
parent
5b19b21042
commit
efa143697b
@ -20,5 +20,6 @@ Gem::Specification.new do |s|
|
||||
s.require_paths = ["lib"]
|
||||
|
||||
s.add_dependency 'guard', '>= 0.2.2'
|
||||
s.add_dependency 'POpen4'
|
||||
s.add_dependency 'jasmine-headless-webkit'
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ module Guard
|
||||
end
|
||||
|
||||
def run_on_change(paths)
|
||||
run_all if JasmineHeadlessWebkitRunner.run(paths) != 1
|
||||
run_all if JasmineHeadlessWebkitRunner.run(paths) == 0
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,8 +4,7 @@ module Guard
|
||||
class JasmineHeadlessWebkitRunner
|
||||
class << self
|
||||
def run(paths = [])
|
||||
passes = fails = 0
|
||||
capturing = 0
|
||||
lines = [""]
|
||||
|
||||
Open3.popen3(%{jasmine-headless-webkit -c #{paths.join(" ")}}) do |stdin, stdout, stderr|
|
||||
stdin.close
|
||||
@ -14,19 +13,37 @@ module Guard
|
||||
$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
|
||||
if char.chr == "\n"
|
||||
lines << ""
|
||||
else
|
||||
lines.last << char.chr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Notifier.notify("#{passes + fails} examples, #{fails} failures", :title => 'Jasmine results', :image => (fails == 0) ? :success : :failed)
|
||||
$?.exitstatus
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user