From 5b695d3debc19e9de4fbf7b28950e95fc4245ad3 Mon Sep 17 00:00:00 2001 From: Christian Williams & Aaron Peckham Date: Fri, 10 Jul 2009 14:35:24 -0700 Subject: [PATCH] Report spec results properly. --- contrib/ruby/jasmine_runner.rb | 5 ++- contrib/ruby/jasmine_spec_builder.rb | 34 +++++++++++----- contrib/ruby/run.html | 5 ++- lib/jasmine.js | 60 +++++++++++++++++++++++++++- src/JsApiReporter.js | 58 +++++++++++++++++++++++++++ src/Reporter.js | 2 +- 6 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 src/JsApiReporter.js diff --git a/contrib/ruby/jasmine_runner.rb b/contrib/ruby/jasmine_runner.rb index 109fa43..72c76c9 100644 --- a/contrib/ruby/jasmine_runner.rb +++ b/contrib/ruby/jasmine_runner.rb @@ -29,7 +29,7 @@ module Jasmine class SimpleServer def self.start(port, spec_dir, mappings) - require "thin" + require 'thin' config = { '/run.html' => Jasmine::RunAdapter.new(spec_dir) @@ -83,7 +83,8 @@ module Jasmine def eval_js(script) escaped_script = "'" + script.gsub(/(['\\])/) { '\\' + $1 } + "'" - @driver.get_eval("window.eval(#{escaped_script})") + result = @driver.get_eval("window.eval(#{escaped_script})") + JSON.parse("[#{result}]")[0] end end diff --git a/contrib/ruby/jasmine_spec_builder.rb b/contrib/ruby/jasmine_spec_builder.rb index a1ce80d..31cf26c 100644 --- a/contrib/ruby/jasmine_spec_builder.rb +++ b/contrib/ruby/jasmine_spec_builder.rb @@ -8,13 +8,18 @@ module Jasmine def initialize(spec_files, runner) @spec_files = spec_files @runner = runner - + end + + def start guess_example_locations @runner.start load_suite_info @spec_results = {} + end + def stop + @runner.stop end def script_path @@ -46,21 +51,21 @@ module Jasmine end def load_suite_info - while !eval_js('jasmine.getEnv().currentRunner.finished') do + while !eval_js('jsApiReporter.started') do sleep 0.1 end - @suites = eval_js('Object.toJSON(reportingBridge.suiteInfo)') + @suites = eval_js('JSON.stringify(jsApiReporter.suites)') end def results_for(spec_id) spec_id = spec_id.to_s return @spec_results[spec_id] if @spec_results[spec_id] - @spec_results[spec_id] = eval_js("Object.toJSON(reportingBridge.specResults[#{spec_id}])") + @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.results[#{spec_id}])") while @spec_results[spec_id].nil? do sleep 0.1 - @spec_results[spec_id] = eval_js("Object.toJSON(reportingBridge.specResults[#{spec_id}])") + @spec_results[spec_id] = eval_js("JSON.stringify(jsApiReporter.results[#{spec_id}])") end @spec_results[spec_id] @@ -83,7 +88,7 @@ module Jasmine elsif type == "spec" me.declare_spec(self, suite_or_spec) else - raise "unknown type #{type}" + raise "unknown type #{type} for #{suite_or_spec.inspect}" end end end @@ -102,9 +107,20 @@ module Jasmine def report_spec(spec_id) spec_results = results_for(spec_id) - messages = spec_results['messages'].join "\n---\n" - puts messages - fail messages if (spec_results['result'] != 'passed') + out = "" + messages = spec_results['messages'].each do |message| + out << message["message"] + out << "\n" + + unless message["passed"] + stack_trace = message["trace"]["stack"] + out << stack_trace.gsub(/\(.*\)@http:\/\/localhost:[0-9]+\/specs\//, "/spec/") + out << "\n" + end + + end + fail out unless spec_results['result'] == 'passed' + puts out end private diff --git a/contrib/ruby/run.html b/contrib/ruby/run.html index 5387918..7ddbe80 100644 --- a/contrib/ruby/run.html +++ b/contrib/ruby/run.html @@ -4,13 +4,16 @@ Jasmine suite +