2011-05-26 14:31:56 +00:00
|
|
|
require 'guard/notifier'
|
2011-09-03 11:50:05 +00:00
|
|
|
require 'jasmine-headless-webkit'
|
2011-05-26 14:31:56 +00:00
|
|
|
|
2011-05-24 01:28:01 +00:00
|
|
|
module Guard
|
|
|
|
class JasmineHeadlessWebkitRunner
|
|
|
|
class << self
|
2011-09-14 14:06:55 +00:00
|
|
|
def run(paths = [], options = {})
|
2011-05-29 17:11:11 +00:00
|
|
|
file = Tempfile.new('guard-jasmine-headless-webkit')
|
|
|
|
file.close
|
2011-05-26 14:31:56 +00:00
|
|
|
|
2011-09-14 14:06:55 +00:00
|
|
|
options.merge!(:report => file.path, :colors => true, :files => paths)
|
|
|
|
|
|
|
|
Jasmine::Headless::Runner.run(options)
|
2011-05-26 14:31:56 +00:00
|
|
|
|
2011-06-01 21:14:23 +00:00
|
|
|
notify(file.path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify(file)
|
2011-09-03 11:50:05 +00:00
|
|
|
if (report = Jasmine::Headless::Report.load(file)).valid?
|
|
|
|
Notifier.notify(message(report.total, report.failed, report.time, report.has_used_console?), :title => 'Jasmine results', :image => image(report.has_used_console?, report.failed))
|
2011-09-06 20:00:27 +00:00
|
|
|
report.failed_files
|
2011-06-01 21:14:23 +00:00
|
|
|
else
|
2011-09-27 18:30:49 +00:00
|
|
|
raise Jasmine::Headless::InvalidReport
|
2011-06-01 21:14:23 +00:00
|
|
|
end
|
2011-09-06 20:00:27 +00:00
|
|
|
rescue Jasmine::Headless::InvalidReport => e
|
2011-09-03 11:50:05 +00:00
|
|
|
Notifier.notify('Spec runner interrupted!', :title => 'Jasmine results', :image => :failed)
|
2011-09-26 15:48:14 +00:00
|
|
|
false
|
2011-05-26 15:26:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def message(total, fails, secs, any_console)
|
2011-06-01 21:14:23 +00:00
|
|
|
total_word = (total.to_i == 1) ? "test" : "tests"
|
|
|
|
|
|
|
|
"#{total} #{total_word}, #{fails} failures, #{secs} secs#{any_console ? ', console.log used' : ''}."
|
2011-05-26 15:26:47 +00:00
|
|
|
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
|
|
|
|
|