From cd3a0c854b454241661cce609bbf1d54c96d1ba7 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank & Rajan Agaskar" Date: Thu, 29 Nov 2012 15:29:45 -0800 Subject: [PATCH] buildExpectationResult now returns a data object. - Meant for passing to reporters. --- GOALS_2.0.md | 3 +- lib/jasmine-core/jasmine-html.js | 9 +++--- lib/jasmine-core/jasmine.js | 28 ++++++++--------- spec/core/ExceptionsSpec.js | 6 ++-- spec/core/ExpectationResultSpec.js | 32 +++++++------------- spec/core/JsApiReporterSpec.js | 2 +- spec/core/MatchersSpec.js | 48 +++++++++++++++--------------- spec/core/NestedResultsSpec.js | 12 ++++---- spec/core/SpecRunningSpec.js | 42 +++++++++++++------------- spec/core/SpecSpec.js | 8 ++--- spec/html/MatchersHtmlSpec.js | 6 ++-- spec/html/TrivialReporterSpec.js | 4 +-- src/console/ConsoleReporter.js | 2 +- src/core/ExpectationResult.js | 20 ++++--------- src/core/JsApiReporter.js | 7 +++-- src/core/Matchers.js | 2 +- src/core/NestedResults.js | 3 +- src/core/Spec.js | 2 +- src/html/SpecView.js | 4 +-- src/html/TrivialReporter.js | 4 +-- 20 files changed, 112 insertions(+), 132 deletions(-) diff --git a/GOALS_2.0.md b/GOALS_2.0.md index 09956b90..98fa6193 100644 --- a/GOALS_2.0.md +++ b/GOALS_2.0.md @@ -1,9 +1,10 @@ -# Jasmine 2.0 Goals +# (Vague) Jasmine 2.0 Goals/(Guidelines) 1. No globals! * jasmine library is entirely inside `jasmine` namespace * globals required for backwards compatibility should be added in `boot.js` (EG, var describe = jasmine.getCurrentEnv().describe lives in boot.js) 1. Don't use properties as getters. Use methods. * Properties aren't encapsulated -- can be mutated, unsafe. +1. Reporters get data objects (no methods). * easier to refactor as needed diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 543d5696..d4364bee 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -450,7 +450,7 @@ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() { if (result.type == 'log') { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); - } else if (result.type == 'expect' && result.passed && !result.passed()) { + } else if (result.type == 'expect' && !result.passed) { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); if (result.trace.stack) { @@ -465,7 +465,8 @@ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() { } }; -jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) { +jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView); +jasmine.HtmlReporter.SuiteView = function(suite, dom, views) { this.suite = suite; this.dom = dom; this.views = views; @@ -615,7 +616,7 @@ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) { jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { var results = spec.results(); - var status = results.passed() ? 'passed' : 'failed'; + var status = results.passed ? 'passed' : 'failed'; if (results.skipped) { status = 'skipped'; } @@ -635,7 +636,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { if (result.type == 'log') { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); - } else if (result.type == 'expect' && result.passed && !result.passed()) { + } else if (result.type == 'expect' && !result.passed) { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); if (result.trace.stack) { diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index e0516c74..0892ee37 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -509,24 +509,18 @@ jasmine.util.extend = function(destination, source) { }; //TODO: expectation result may make more sense as a presentation of an expectation. -jasmine.ExpectationResult = function(params) { - var self = this; +jasmine.buildExpectationResult = function(params) { var trace = (params.trace || new Error(this.message)); var message = params.passed ? 'Passed.' : params.message; - return jasmine.util.extend(self, { + return { type: 'expect', matcherName: params.matcherName, expected: params.expected, actual: params.actual, message: message, trace: params.passed ? '' : trace, - toString: function() { - return message; - }, - passed: function() { - return params.passed; - } - }); + passed: params.passed + }; }; /** * Environment for Jasmine @@ -918,7 +912,7 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { type: isSuite ? 'suite' : 'spec', children: [] }; - + if (isSuite) { var children = suiteOrSpec.children(); for (var i = 0; i < children.length; i++) { @@ -973,11 +967,12 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ var resultMessage = result.messages[messageIndex]; summaryMessages.push({ text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, - passed: resultMessage.passed ? resultMessage.passed() : true, + //TODO: wat? in theory this is saying non-expect results should always be considered passed, but that's weird. + passed: resultMessage.passed || true, type: resultMessage.type, message: resultMessage.message, trace: { - stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined + stack: !resultMessage.passed ? resultMessage.trace.stack : jasmine.undefined } }); } @@ -1050,7 +1045,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { message += "."; } } - var expectationResult = new jasmine.ExpectationResult({ + var expectationResult = jasmine.buildExpectationResult({ matcherName: matcherName, passed: result, expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], @@ -1668,13 +1663,14 @@ jasmine.NestedResults.prototype.getItems = function() { * Adds a result, tracking counts (total, passed, & failed) * @param {jasmine.ExpectationResult|jasmine.NestedResults} result */ +//TODO: Results are meant for consumption by reporters, not internally. jasmine.NestedResults.prototype.addResult = function(result) { if (result.type != 'log') { if (result.items_) { this.rollupCounts(result); } else { this.totalCount++; - if (result.passed()) { + if (result.passed) { this.passedCount++; } else { this.failedCount++; @@ -2135,7 +2131,7 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag }; jasmine.Spec.prototype.fail = function (e) { - var expectationResult = new jasmine.ExpectationResult({ + var expectationResult = jasmine.buildExpectationResult({ passed: false, message: e ? jasmine.util.formatException(e) : 'Exception', trace: { stack: e.stack } diff --git a/spec/core/ExceptionsSpec.js b/spec/core/ExceptionsSpec.js index 315aa1bf..a7aa8aeb 100644 --- a/spec/core/ExceptionsSpec.js +++ b/spec/core/ExceptionsSpec.js @@ -111,14 +111,14 @@ describe('Exceptions:', function() { expect(specResults.length).toEqual(5); expect(specResults[0].passed()).toMatch(false); var blockResults = specResults[0].getItems(); - expect(blockResults[0].passed()).toEqual(false); + expect(blockResults[0].passed).toEqual(false); expect(blockResults[0].message).toMatch(/fake error 1/); expect(specResults[1].passed()).toEqual(false); blockResults = specResults[1].getItems(); - expect(blockResults[0].passed()).toEqual(false); + expect(blockResults[0].passed).toEqual(false); expect(blockResults[0].message).toMatch(/fake error 2/); - expect(blockResults[1].passed()).toEqual(true); + expect(blockResults[1].passed).toEqual(true); expect(specResults[2].passed()).toEqual(true); diff --git a/spec/core/ExpectationResultSpec.js b/spec/core/ExpectationResultSpec.js index 03f52036..36c4e49c 100644 --- a/spec/core/ExpectationResultSpec.js +++ b/spec/core/ExpectationResultSpec.js @@ -1,57 +1,47 @@ -describe("ExpectationResult", function() { +describe("buildExpectationResult", function() { it("defaults to passed", function() { - var result = new jasmine.ExpectationResult({passed: 'some-value'}); - expect(result.passed()).toBe('some-value'); - }); - - it("#toString returns message when failing", function() { - var result = new jasmine.ExpectationResult({passed: false, message: 'some-value'}); - expect(result.toString()).toBe('some-value'); - }); - - it("#toString returns Passed when passing", function() { - var result = new jasmine.ExpectationResult({passed: true, message: 'some-value'}); - expect(result.toString()).toBe('Passed.'); + var result = jasmine.buildExpectationResult({passed: 'some-value'}); + expect(result.passed).toBe('some-value'); }); it("has a type of expect", function() { - var result = new jasmine.ExpectationResult({}); + var result = jasmine.buildExpectationResult({}); expect(result.type).toBe('expect'); }); it("message defaults to Passed for passing specs", function() { - var result = new jasmine.ExpectationResult({passed: true, message: 'some-value'}); + var result = jasmine.buildExpectationResult({passed: true, message: 'some-value'}); expect(result.message).toBe('Passed.'); }); it("message returns the message for failing specs", function() { - var result = new jasmine.ExpectationResult({passed: false, message: 'some-value'}); + var result = jasmine.buildExpectationResult({passed: false, message: 'some-value'}); expect(result.message).toBe('some-value'); }); it("trace passes trace if exists", function() { - var result = new jasmine.ExpectationResult({trace: 'some-value'}); + var result = jasmine.buildExpectationResult({trace: 'some-value'}); expect(result.trace).toBe('some-value'); }); it("trace returns a new error if trace is falsy", function() { - var result = new jasmine.ExpectationResult({trace: false}); + var result = jasmine.buildExpectationResult({trace: false}); expect(result.trace).toEqual(jasmine.any(Error)); }); it("matcherName returns passed matcherName", function() { - var result = new jasmine.ExpectationResult({matcherName: 'some-value'}); + var result = jasmine.buildExpectationResult({matcherName: 'some-value'}); expect(result.matcherName).toBe('some-value'); }); it("expected returns passed expected", function() { - var result = new jasmine.ExpectationResult({expected: 'some-value'}); + var result = jasmine.buildExpectationResult({expected: 'some-value'}); expect(result.expected).toBe('some-value'); }); it("actual returns passed actual", function() { - var result = new jasmine.ExpectationResult({actual: 'some-value'}); + var result = jasmine.buildExpectationResult({actual: 'some-value'}); expect(result.actual).toBe('some-value'); }); diff --git a/spec/core/JsApiReporterSpec.js b/spec/core/JsApiReporterSpec.js index cca70674..953d7307 100644 --- a/spec/core/JsApiReporterSpec.js +++ b/spec/core/JsApiReporterSpec.js @@ -100,4 +100,4 @@ describe('jasmine.jsApiReporter', function() { }); }); }); -}); \ No newline at end of file +}); diff --git a/spec/core/MatchersSpec.js b/spec/core/MatchersSpec.js index 97c9fd69..8b088e0c 100644 --- a/spec/core/MatchersSpec.js +++ b/spec/core/MatchersSpec.js @@ -13,10 +13,10 @@ describe("jasmine.Matchers", function() { this.addMatchers({ toPass: function() { - return lastResult().passed(); + return lastResult().passed; }, toFail: function() { - return !lastResult().passed(); + return !lastResult().passed; } }); }); @@ -98,7 +98,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toEqual"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.expected).toEqual(expected); @@ -113,7 +113,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toNotEqual"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(str)); expect(result.message).toMatch('not'); expect(result.expected).toEqual(str); @@ -142,7 +142,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBe"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.expected).toEqual(expected); @@ -157,7 +157,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toNotBe"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(str); expect(result.expected).toEqual(str); expect(result.actual).toEqual(str); @@ -186,7 +186,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toMatch"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch(expected.toString()); expect(result.expected).toEqual(expected); @@ -202,7 +202,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toMatch"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toEqual("Expected 'a' to match 'b'."); expect(result.expected).toEqual(expected); expect(result.actual).toEqual(actual); @@ -217,7 +217,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toNotMatch"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toEqual("Expected 'a' to not match /a/."); expect(result.expected).toEqual(expected); expect(result.actual).toEqual(actual); @@ -231,7 +231,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toNotMatch"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toEqual("Expected 'a' to not match 'a'."); expect(result.expected).toEqual(str); expect(result.actual).toEqual(str); @@ -249,7 +249,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeDefined"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toEqual('Expected undefined to be defined.'); expect(result.actual).toEqual(jasmine.undefined); }); @@ -273,7 +273,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeNull"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch('null'); expect(result.actual).toEqual(actual); @@ -287,7 +287,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeNull"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch('null'); expect(result.actual).toEqual(actual); @@ -311,7 +311,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeNaN"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch("Expected 'a' to be NaN."); expect(result.actual).toMatch(actual); }); @@ -332,7 +332,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeFalsy"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch('falsy'); expect(result.actual).toEqual(actual); @@ -356,7 +356,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeTruthy"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toEqual("Expected false to be truthy."); expect(result.actual).toFail(); }); @@ -459,7 +459,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toContain"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch('contain'); expect(result.message).toMatch(jasmine.pp(expected)); @@ -476,7 +476,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toNotContain"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual)); expect(result.message).toMatch('not contain'); expect(result.message).toMatch(jasmine.pp(expected)); @@ -499,7 +499,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeLessThan"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); @@ -521,7 +521,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toBeGreaterThan"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than'); expect(result.message).toMatch(jasmine.pp(expected)); expect(result.actual).toEqual(actual); @@ -780,7 +780,7 @@ describe("jasmine.Matchers", function() { var expected = match(TestClass.spyFunction); expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail(); var result = lastResult(); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.expected).toEqual(['c', 'b', 'a']); expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); expect(result.message).toContain(jasmine.pp(result.expected)); @@ -791,7 +791,7 @@ describe("jasmine.Matchers", function() { var expected = match(TestClass.spyFunction); expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail(); var result = lastResult(); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.expected).toEqual(['c', 'b', 'a']); expect(result.actual.argsForCall).toEqual([]); expect(result.message).toContain(jasmine.pp(result.expected)); @@ -849,7 +849,7 @@ describe("jasmine.Matchers", function() { var result = lastResult(); expect(result.matcherName).toEqual("toHaveBeenCalledWith"); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.message).toContain(jasmine.pp(['a', 'b'])); expect(result.message).toContain(jasmine.pp(['a', 'c'])); expect(result.actual).toEqual(TestClass.someFunction); @@ -879,7 +879,7 @@ describe("jasmine.Matchers", function() { var expected = match(TestClass.spyFunction); expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail(); var result = lastResult(); - expect(result.passed()).toBe(false); + expect(result.passed).toBe(false); expect(result.expected).toEqual(['a', 'b', 'c']); expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']); expect(result.message).toContain(jasmine.pp(result.expected)); diff --git a/spec/core/NestedResultsSpec.js b/spec/core/NestedResultsSpec.js index e4bc9190..fc1e5607 100644 --- a/spec/core/NestedResultsSpec.js +++ b/spec/core/NestedResultsSpec.js @@ -3,7 +3,7 @@ describe('jasmine.NestedResults', function() { // Leaf case var results = new jasmine.NestedResults(); - results.addResult(new jasmine.ExpectationResult({ + results.addResult(jasmine.buildExpectationResult({ matcherName: "foo", passed: true, message: 'Passed.', actual: 'bar', expected: 'bar'} )); @@ -12,7 +12,7 @@ describe('jasmine.NestedResults', function() { expect(results.passedCount).toEqual(1); expect(results.failedCount).toEqual(0); - results.addResult(new jasmine.ExpectationResult({ + results.addResult(jasmine.buildExpectationResult({ matcherName: "baz", passed: false, message: 'FAIL.', actual: "corge", expected: "quux" })); @@ -25,19 +25,19 @@ describe('jasmine.NestedResults', function() { it('should roll up counts for nested results', function() { // Branch case var leafResultsOne = new jasmine.NestedResults(); - leafResultsOne.addResult(new jasmine.ExpectationResult({ + leafResultsOne.addResult(jasmine.buildExpectationResult({ matcherName: "toSomething", passed: true, message: 'message', actual: '', expected:'' })); - leafResultsOne.addResult(new jasmine.ExpectationResult({ + leafResultsOne.addResult(jasmine.buildExpectationResult({ matcherName: "toSomethingElse", passed: false, message: 'message', actual: 'a', expected: 'b' })); var leafResultsTwo = new jasmine.NestedResults(); - leafResultsTwo.addResult(new jasmine.ExpectationResult({ + leafResultsTwo.addResult(jasmine.buildExpectationResult({ matcherName: "toSomething", passed: true, message: 'message', actual: '', expected: '' })); - leafResultsTwo.addResult(new jasmine.ExpectationResult({ + leafResultsTwo.addResult(jasmine.buildExpectationResult({ matcherName: "toSomethineElse", passed: false, message: 'message', actual: 'c', expected: 'd' })); diff --git a/spec/core/SpecRunningSpec.js b/spec/core/SpecRunningSpec.js index 377e5812..98e7146b 100644 --- a/spec/core/SpecRunningSpec.js +++ b/spec/core/SpecRunningSpec.js @@ -68,10 +68,10 @@ describe("jasmine spec running", function () { expect(specWithNoBody.description).toEqual('new spec'); expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed" - expect(specWithExpectation.results().getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true" + expect(specWithExpectation.results().getItems()[0].passed).toEqual(true); // "Results has a result, but it's true" expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description" - expect(specWithFailingExpectations.results().getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed" + expect(specWithFailingExpectations.results().getItems()[0].passed).toEqual(false); // "Expectation that failed, passed" expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations" }); @@ -90,8 +90,8 @@ describe("jasmine spec running", function () { another_spec.done = true; expect(another_spec.results().getItems().length).toEqual(2); - expect(another_spec.results().getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false" - expect(another_spec.results().getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true"; + expect(another_spec.results().getItems()[0].passed).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false" + expect(another_spec.results().getItems()[1].passed).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true"; expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description"; }); @@ -142,7 +142,7 @@ describe("jasmine spec running", function () { a_spec.execute(); expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions'; - expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed'; + expect(a_spec.results().getItems()[0].passed).toEqual(true); // 'No call to waits(): Queued expectation failed'; foo = 0; env.describe('test async spec', function() { @@ -169,7 +169,7 @@ describe("jasmine spec running", function () { fakeTimer.tick(500); expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions'; - expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed'; + expect(a_spec.results().getItems()[0].passed).toEqual(true); // 'Calling waits(): Queued expectation failed'; var bar = 0; var another_spec; @@ -200,7 +200,7 @@ describe("jasmine spec running", function () { fakeTimer.tick(1000); expect(another_spec.results().getItems().length).toEqual(1); - expect(another_spec.results().getItems()[0].passed()).toEqual(true); + expect(another_spec.results().getItems()[0].passed).toEqual(true); var baz = 0; var yet_another_spec; @@ -226,7 +226,7 @@ describe("jasmine spec running", function () { expect(yet_another_spec.results().getItems().length).toEqual(1); - expect(yet_another_spec.results().getItems()[0].passed()).toEqual(false); + expect(yet_another_spec.results().getItems()[0].passed).toEqual(false); }); it("testAsyncSpecsWithMockSuite", function () { @@ -255,7 +255,7 @@ describe("jasmine spec running", function () { another_spec.execute(); fakeTimer.tick(2000); expect(another_spec.results().getItems().length).toEqual(1); - expect(another_spec.results().getItems()[0].passed()).toEqual(true); + expect(another_spec.results().getItems()[0].passed).toEqual(true); }); describe("waitsFor", function() { @@ -901,8 +901,8 @@ describe("jasmine spec running", function () { expect(report).toEqual("firstsecond"); var suiteResults = suite.results(); - expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false); - expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true); + expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false); + expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true); }); it("testAfterExecutesSafely", function() { @@ -942,14 +942,14 @@ describe("jasmine spec running", function () { var suiteResults = suite.results(); expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs'); - expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass"); - expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd spec should pass"); - expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd spec should pass"); + expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st spec should pass"); + expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd spec should pass"); + expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd spec should pass"); - expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass"); - expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed"); - expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass"); - expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass"); + expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass"); + expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed"); + expect(suiteResults.getItems()[1].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass"); + expect(suiteResults.getItems()[2].getItems()[0].passed).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass"); }); it("should permit nested describes", function() { @@ -1178,8 +1178,8 @@ describe("jasmine spec running", function () { expect(spec.foo).toEqual(2); var suiteResults = suite.results(); expect(suiteResults.getItems()[0].getItems().length).toEqual(2); - expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false); - expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true); + expect(suiteResults.getItems()[0].getItems()[0].passed).toEqual(false); + expect(suiteResults.getItems()[0].getItems()[1].passed).toEqual(true); }); it("shouldn't run disabled tests", function() { @@ -1239,7 +1239,7 @@ describe("jasmine spec running", function () { var results = spec.results().getItems(); for (var i = 0; i < results.length; i++) { var result = results[i]; - specs.push("Result: " + result); + specs.push("Result: " + result.message); } }; diff --git a/spec/core/SpecSpec.js b/spec/core/SpecSpec.js index 0c96be84..a1cf547b 100644 --- a/spec/core/SpecSpec.js +++ b/spec/core/SpecSpec.js @@ -112,11 +112,9 @@ describe('Spec', function () { }); spec.execute(); var items = results.getItems(); - expect(items).toEqual([ - originalJasmine.any(jasmine.ExpectationResult), - originalJasmine.any(jasmine.ExpectationResult), - originalJasmine.any(jasmine.MessageResult) - ]); + expect(items[0].type).toBe('expect'); + expect(items[1].type).toBe('expect'); + expect(items[2].type).toBe('log'); var logResult = items[2]; expect(logResult.values).toEqual(["here's some log message", {key: 'value'}, 123]); }); diff --git a/spec/html/MatchersHtmlSpec.js b/spec/html/MatchersHtmlSpec.js index b528753a..5bc83dac 100644 --- a/spec/html/MatchersHtmlSpec.js +++ b/spec/html/MatchersHtmlSpec.js @@ -13,10 +13,10 @@ describe("MatchersSpec - HTML Dependent", function () { this.addMatchers({ toPass: function() { - return lastResult().passed(); + return lastResult().passed; }, toFail: function() { - return !lastResult().passed(); + return !lastResult().passed; } }); }); @@ -35,4 +35,4 @@ describe("MatchersSpec - HTML Dependent", function () { expect((match(nodeA).toEqual(nodeA))).toPass(); expect((match(nodeA).toEqual(nodeB))).toFail(); }); -}); \ No newline at end of file +}); diff --git a/spec/html/TrivialReporterSpec.js b/spec/html/TrivialReporterSpec.js index 8462f0c6..5cfe5e21 100644 --- a/spec/html/TrivialReporterSpec.js +++ b/spec/html/TrivialReporterSpec.js @@ -130,7 +130,7 @@ describe("TrivialReporter", function() { }); it("should add the failure message to the DOM (non-toEquals matchers)", function() { - expectationResult = new jasmine.ExpectationResult({ + expectationResult = jasmine.buildExpectationResult({ matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not" }); @@ -144,7 +144,7 @@ describe("TrivialReporter", function() { }); it("should add the failure message to the DOM (non-toEquals matchers) html escaping", function() { - expectationResult = new jasmine.ExpectationResult({ + expectationResult = jasmine.buildExpectationResult({ matcherName: "toBeNull", passed: false, message: "Expected '1 < 2' to e null, & it was not" }); diff --git a/src/console/ConsoleReporter.js b/src/console/ConsoleReporter.js index e65be81b..b026af9f 100644 --- a/src/console/ConsoleReporter.js +++ b/src/console/ConsoleReporter.js @@ -174,4 +174,4 @@ jasmine.ConsoleReporter = function(print, doneCallback, showColors) { summaryFunction(runner.specs().length, results.failedCount); doneCallback(runner); }; -}; \ No newline at end of file +}; diff --git a/src/core/ExpectationResult.js b/src/core/ExpectationResult.js index b33dd01a..bc783ede 100644 --- a/src/core/ExpectationResult.js +++ b/src/core/ExpectationResult.js @@ -1,20 +1,12 @@ //TODO: expectation result may make more sense as a presentation of an expectation. -jasmine.ExpectationResult = function(params) { - var self = this; - var trace = (params.trace || new Error(this.message)); - var message = params.passed ? 'Passed.' : params.message; - return jasmine.util.extend(self, { +jasmine.buildExpectationResult = function(params) { + return { type: 'expect', matcherName: params.matcherName, expected: params.expected, actual: params.actual, - message: message, - trace: params.passed ? '' : trace, - toString: function() { - return message; - }, - passed: function() { - return params.passed; - } - }); + message: params.passed ? 'Passed.' : params.message, + trace: params.passed ? '' : (params.trace || new Error(this.message)), + passed: params.passed + }; }; diff --git a/src/core/JsApiReporter.js b/src/core/JsApiReporter.js index 44f1802a..5a9e6790 100644 --- a/src/core/JsApiReporter.js +++ b/src/core/JsApiReporter.js @@ -30,7 +30,7 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { type: isSuite ? 'suite' : 'spec', children: [] }; - + if (isSuite) { var children = suiteOrSpec.children(); for (var i = 0; i < children.length; i++) { @@ -85,11 +85,12 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ var resultMessage = result.messages[messageIndex]; summaryMessages.push({ text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, - passed: resultMessage.passed ? resultMessage.passed() : true, + //TODO: wat? in theory this is saying non-expect results should always be considered passed, but that's weird. + passed: resultMessage.passed || true, type: resultMessage.type, message: resultMessage.message, trace: { - stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined + stack: !resultMessage.passed ? resultMessage.trace.stack : jasmine.undefined } }); } diff --git a/src/core/Matchers.js b/src/core/Matchers.js index 09f449d8..634564a7 100644 --- a/src/core/Matchers.js +++ b/src/core/Matchers.js @@ -60,7 +60,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { message += "."; } } - var expectationResult = new jasmine.ExpectationResult({ + var expectationResult = jasmine.buildExpectationResult({ matcherName: matcherName, passed: result, expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], diff --git a/src/core/NestedResults.js b/src/core/NestedResults.js index 374e5e46..61d34f58 100644 --- a/src/core/NestedResults.js +++ b/src/core/NestedResults.js @@ -56,13 +56,14 @@ jasmine.NestedResults.prototype.getItems = function() { * Adds a result, tracking counts (total, passed, & failed) * @param {jasmine.ExpectationResult|jasmine.NestedResults} result */ +//TODO: Results are meant for consumption by reporters, not internally. jasmine.NestedResults.prototype.addResult = function(result) { if (result.type != 'log') { if (result.items_) { this.rollupCounts(result); } else { this.totalCount++; - if (result.passed()) { + if (result.passed) { this.passedCount++; } else { this.failedCount++; diff --git a/src/core/Spec.js b/src/core/Spec.js index 469345b4..8733d5bd 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -118,7 +118,7 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag }; jasmine.Spec.prototype.fail = function (e) { - var expectationResult = new jasmine.ExpectationResult({ + var expectationResult = jasmine.buildExpectationResult({ passed: false, message: e ? jasmine.util.formatException(e) : 'Exception', trace: { stack: e.stack } diff --git a/src/html/SpecView.js b/src/html/SpecView.js index b9bcf08a..8af30cb5 100644 --- a/src/html/SpecView.js +++ b/src/html/SpecView.js @@ -61,7 +61,7 @@ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() { if (result.type == 'log') { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); - } else if (result.type == 'expect' && result.passed && !result.passed()) { + } else if (result.type == 'expect' && !result.passed) { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); if (result.trace.stack) { @@ -76,4 +76,4 @@ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() { } }; -jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView); \ No newline at end of file +jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView); diff --git a/src/html/TrivialReporter.js b/src/html/TrivialReporter.js index 167ac506..05e08bc7 100644 --- a/src/html/TrivialReporter.js +++ b/src/html/TrivialReporter.js @@ -126,7 +126,7 @@ jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) { jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { var results = spec.results(); - var status = results.passed() ? 'passed' : 'failed'; + var status = results.passed ? 'passed' : 'failed'; if (results.skipped) { status = 'skipped'; } @@ -146,7 +146,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { if (result.type == 'log') { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); - } else if (result.type == 'expect' && result.passed && !result.passed()) { + } else if (result.type == 'expect' && !result.passed) { messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); if (result.trace.stack) {