From 98ae076f0c11385406e1c019c49ca689a7672ba9 Mon Sep 17 00:00:00 2001 From: "Dan Hansen and Davis W. Frank" Date: Tue, 26 Feb 2013 12:24:59 -0800 Subject: [PATCH] * JsApiReporter - better inteface for getting spec results (it's a slice!) * Removed RSpec dependency from running self_test/CI - includes using new Jasmine::Formatter::Console from the gem * --- Rakefile | 10 ++----- lib/jasmine-core/jasmine-html.js | 2 +- lib/jasmine-core/jasmine.css | 2 +- lib/jasmine-core/jasmine.js | 19 +++++------- spec/core/JsApiReporterSpec.js | 51 +++++++++++++++++++++++++------- spec/jasmine_self_test_spec.rb | 14 ++++++--- src/core/JsApiReporter.js | 17 ++++------- src/html/jasmine.css | 2 +- 8 files changed, 69 insertions(+), 48 deletions(-) diff --git a/Rakefile b/Rakefile index c2f7160d..60f004dc 100644 --- a/Rakefile +++ b/Rakefile @@ -43,13 +43,9 @@ task :list_dev_tasks do system "thor list" end -require "jasmine" -require 'rspec' -require 'rspec/core/rake_task' - -desc "Run all examples" -RSpec::Core::RakeTask.new(:jasmine_core_spec) do |t| - t.pattern = 'spec/jasmine_self_test_spec.rb' +# TODO: Is there better way to invoke this using Jasmine gem??? +task :core_spec do + exec "ruby spec/jasmine_self_test_spec.rb" end namespace :jasmine do diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index a2714df4..02906847 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -252,7 +252,7 @@ jasmine.HtmlReporter = function(options) { this.last = function() { return this.children[this.children.length-1]; - } + }; };jasmine.QueryString = function(options) { this.setParam = function(key, value) { diff --git a/lib/jasmine-core/jasmine.css b/lib/jasmine-core/jasmine.css index 91147778..603ac73b 100644 --- a/lib/jasmine-core/jasmine.css +++ b/lib/jasmine-core/jasmine.css @@ -50,4 +50,4 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } .html-reporter .failures .spec-detail .description { display: block; color: white; background-color: #b03911; } .html-reporter .result-message { padding-top: 14px; color: #333333; } .html-reporter .result-message span.result { display: block; } -.html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } +.html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #dddddd; background: white; white-space: pre; } diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 62c50503..0e4821ac 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -439,7 +439,7 @@ jasmine.util.argsToArray = function(args) { var arrayOfArgs = []; for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); return arrayOfArgs; -};jasmine.exceptionMessageFor = function(e) { +};jasmine.exceptionFormatter = function(e) { var message = e.name + ': ' + e.message @@ -938,8 +938,6 @@ jasmine.JsApiReporter = function(jasmine) { this.jasmine = jasmine || {}; this.started = false; this.finished = false; - this.suites_ = []; - this.results_ = {}; var status = 'loaded'; @@ -975,19 +973,16 @@ jasmine.JsApiReporter = function(jasmine) { return suites; }; - var specs = {}; - + var specs = []; this.specStarted = function(result) { - storeSpec(result); + specs.push(result); }; - this.specDone = function(result) { - storeSpec(result); - }; + this.specDone = function(result) { }; - function storeSpec(result) { - specs[result.id] = result; - } + this.specResults = function(index, length) { + return specs.slice(index, index + length); + }; this.specs = function() { return specs; diff --git a/spec/core/JsApiReporterSpec.js b/spec/core/JsApiReporterSpec.js index bf7f9f5a..baa77f21 100644 --- a/spec/core/JsApiReporterSpec.js +++ b/spec/core/JsApiReporterSpec.js @@ -150,23 +150,52 @@ describe("JsApiReporter", function() { }); it("tracks a spec", function() { - var reporter = new jasmine.JsApiReporter(); + var reporter = new jasmine.JsApiReporter(), + result = { + id: 123, + description: "A spec" + }; - reporter.specStarted({ - id: 123, - description: "A spec" - }); + reporter.specStarted(result); var specs = reporter.specs(); - expect(specs).toEqual({123: {id: 123, description: "A spec"}}); + expect(specs).toEqual([result]); - reporter.specDone({ - id: 123, - description: "A spec", - status: 'passed' + result.status = "passed"; + + reporter.specDone(result); + + expect(specs).toEqual([result]); + }); + + describe("#specResults", function() { + var reporter, specResult1, specResult2; + beforeEach(function() { + reporter = new jasmine.JsApiReporter(); + specResult1 = { + id: 1, + description: "A spec" + }; + specResult2 = { + id: 2, + description: "Another spec" + }; + + reporter.specStarted(specResult1); + reporter.specStarted(specResult2); }); - expect(specs).toEqual({123: {id: 123, description: "A spec", status: 'passed'}}); + it("should return a slice of results", function() { + expect(reporter.specResults(0, 1)).toEqual([specResult1]); + expect(reporter.specResults(1, 1)).toEqual([specResult2]); + }); + + describe("when the results do not exist", function() { + it("should return a slice of shorter length", function() { + expect(reporter.specResults(0, 3)).toEqual([specResult1, specResult2]); + expect(reporter.specResults(2, 3)).toEqual([]); + }); + }); }); }); diff --git a/spec/jasmine_self_test_spec.rb b/spec/jasmine_self_test_spec.rb index 1d36c211..a1699b5c 100644 --- a/spec/jasmine_self_test_spec.rb +++ b/spec/jasmine_self_test_spec.rb @@ -1,3 +1,5 @@ +require 'rubygems' +require 'bundler/setup' require 'jasmine' Jasmine.load_configuration_from_yaml(File.join(Dir.pwd, 'spec', 'jasmine.yml')) @@ -16,8 +18,12 @@ t.abort_on_exception = true Jasmine::wait_for_listener(config.port, "jasmine server") puts "jasmine server started." -results_processor = Jasmine::ResultsProcessor.new(config) -results = Jasmine::Runners::HTTP.new(driver, results_processor, config.result_batch_size).run -formatter = Jasmine::RspecFormatter.new -formatter.format_results(results) +reporter = Jasmine::Runners::ApiReporter.new(driver, config.result_batch_size) +raw_results = Jasmine::Runners::HTTP.new(driver, reporter).run +results = Jasmine::Results.new(raw_results) +formatter = Jasmine::Formatters::Console.new(results) +puts formatter.failures +puts formatter.summary + +exit results.failures.size \ No newline at end of file diff --git a/src/core/JsApiReporter.js b/src/core/JsApiReporter.js index 01f41e97..02a4e57d 100644 --- a/src/core/JsApiReporter.js +++ b/src/core/JsApiReporter.js @@ -2,8 +2,6 @@ jasmine.JsApiReporter = function(jasmine) { this.jasmine = jasmine || {}; this.started = false; this.finished = false; - this.suites_ = []; - this.results_ = {}; var status = 'loaded'; @@ -39,19 +37,16 @@ jasmine.JsApiReporter = function(jasmine) { return suites; }; - var specs = {}; - + var specs = []; this.specStarted = function(result) { - storeSpec(result); + specs.push(result); }; - this.specDone = function(result) { - storeSpec(result); - }; + this.specDone = function(result) { }; - function storeSpec(result) { - specs[result.id] = result; - } + this.specResults = function(index, length) { + return specs.slice(index, index + length); + }; this.specs = function() { return specs; diff --git a/src/html/jasmine.css b/src/html/jasmine.css index 91147778..603ac73b 100644 --- a/src/html/jasmine.css +++ b/src/html/jasmine.css @@ -50,4 +50,4 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } .html-reporter .failures .spec-detail .description { display: block; color: white; background-color: #b03911; } .html-reporter .result-message { padding-top: 14px; color: #333333; } .html-reporter .result-message span.result { display: block; } -.html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } +.html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #dddddd; background: white; white-space: pre; }