From 5f34be446c0a8048cfb40a04636dcd49851452f6 Mon Sep 17 00:00:00 2001 From: Alex Treppass Date: Mon, 14 Apr 2014 14:23:50 +0100 Subject: [PATCH] keeping track of passed expectations --- lib/jasmine-core/jasmine.js | 9 ++++++--- spec/core/SpecSpec.js | 20 +++++++++++++++++++- spec/html/HtmlReporterSpec.js | 6 ++++-- src/core/Spec.js | 9 ++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 1d3561bd..c6c8464f 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -263,16 +263,19 @@ getJasmineRequireObj().Spec = function(j$) { id: this.id, description: this.description, fullName: this.getFullName(), - failedExpectations: [] + failedExpectations: [], + passedExpectations: [] }; } Spec.prototype.addExpectationResult = function(passed, data) { this.expectCalled = true; + var expectationResult = this.expectationResultFactory(data); if (passed) { - return; + this.result.passedExpectations.push(expectationResult); + } else { + this.result.failedExpectations.push(expectationResult); } - this.result.failedExpectations.push(this.expectationResultFactory(data)); }; Spec.prototype.expect = function(actual) { diff --git a/spec/core/SpecSpec.js b/spec/core/SpecSpec.js index 9719d1b9..0481348d 100644 --- a/spec/core/SpecSpec.js +++ b/spec/core/SpecSpec.js @@ -175,7 +175,8 @@ describe("Spec", function() { status: 'pending', description: 'with a spec', fullName: 'a suite with a spec', - failedExpectations: [] + failedExpectations: [], + passedExpectations: [] }); }); @@ -212,6 +213,23 @@ describe("Spec", function() { expect(spec.status()).toBe('failed'); }); + it("keeps track of passed and failed expectations", function() { + var resultCallback = jasmine.createSpy('resultCallback'), + spec = new j$.Spec({ + fn: jasmine.createSpy("spec body"), + expectationResultFactory: function (data) { return data; }, + queueRunnerFactory: function(attrs) { attrs.onComplete(); }, + resultCallback: resultCallback + }); + spec.addExpectationResult(true, 'expectation1'); + spec.addExpectationResult(false, 'expectation2'); + + spec.execute(); + + expect(resultCallback.calls.first().args[0].passedExpectations).toEqual(['expectation1']); + expect(resultCallback.calls.first().args[0].failedExpectations).toEqual(['expectation2']); + }); + it("can return its full name", function() { var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val'); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 0ae2cdf2..b46a4e75 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -165,7 +165,8 @@ describe("New HtmlReporter", function() { reporter.specDone({ id: 345, status: "failed", - failedExpectations: [] + failedExpectations: [], + passedExpectations: [] }); var specEl = container.querySelector(".symbol-summary li"); @@ -289,7 +290,8 @@ describe("New HtmlReporter", function() { description: "with a failing spec", fullName: "A Suite inner with a failing spec", status: "failed", - failedExpectations: [] + failedExpectations: [], + passedExpectations: [] }; reporter.specStarted(specResult); reporter.specDone(specResult); diff --git a/src/core/Spec.js b/src/core/Spec.js index c714ef17..4808dea8 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -23,16 +23,19 @@ getJasmineRequireObj().Spec = function(j$) { id: this.id, description: this.description, fullName: this.getFullName(), - failedExpectations: [] + failedExpectations: [], + passedExpectations: [] }; } Spec.prototype.addExpectationResult = function(passed, data) { this.expectCalled = true; + var expectationResult = this.expectationResultFactory(data); if (passed) { - return; + this.result.passedExpectations.push(expectationResult); + } else { + this.result.failedExpectations.push(expectationResult); } - this.result.failedExpectations.push(this.expectationResultFactory(data)); }; Spec.prototype.expect = function(actual) {