Remove 'empty' as an option as a spec result

- Having the 'empty' state for a spec result can be considered a
breaking change to the reporter interface
- Instead, we determine if a spec has no expectations using the added
key of 'passedExpectations' in combination of the 'failedExpectations'
to determine that there a spec is 'empty'

[fixes #73741032]
This commit is contained in:
Sheel Choksi
2014-06-27 23:48:19 -07:00
parent 5f34be446c
commit f7ff47706c
6 changed files with 52 additions and 42 deletions

View File

@@ -96,7 +96,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var failures = []; var failures = [];
this.specDone = function(result) { this.specDone = function(result) {
if(result.status == 'empty' && console && console.error) { if(noExpectations(result) && console && console.error) {
console.error('Spec \'' + result.fullName + '\' has no expectations.'); console.error('Spec \'' + result.fullName + '\' has no expectations.');
} }
@@ -105,7 +105,7 @@ jasmineRequire.HtmlReporter = function(j$) {
} }
symbols.appendChild(createDom('li', { symbols.appendChild(createDom('li', {
className: result.status, className: noExpectations(result) ? 'empty' : result.status,
id: 'spec_' + result.id, id: 'spec_' + result.id,
title: result.fullName title: result.fullName
} }
@@ -203,7 +203,7 @@ jasmineRequire.HtmlReporter = function(j$) {
domParent.appendChild(specListNode); domParent.appendChild(specListNode);
} }
var specDescription = resultNode.result.description; var specDescription = resultNode.result.description;
if(resultNode.result.status == 'empty') { if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
} }
specListNode.appendChild( specListNode.appendChild(
@@ -298,6 +298,11 @@ jasmineRequire.HtmlReporter = function(j$) {
function setMenuModeTo(mode) { function setMenuModeTo(mode) {
htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
} }
function noExpectations(result) {
return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
result.status === 'passed';
}
} }
return HtmlReporter; return HtmlReporter;

View File

@@ -253,7 +253,6 @@ getJasmineRequireObj().Spec = function(j$) {
this.expectationResultFactory = attrs.expectationResultFactory || function() { }; this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
this.expectCalled = false;
if (!this.fn) { if (!this.fn) {
this.pend(); this.pend();
@@ -269,7 +268,6 @@ getJasmineRequireObj().Spec = function(j$) {
} }
Spec.prototype.addExpectationResult = function(passed, data) { Spec.prototype.addExpectationResult = function(passed, data) {
this.expectCalled = true;
var expectationResult = this.expectationResultFactory(data); var expectationResult = this.expectationResultFactory(data);
if (passed) { if (passed) {
this.result.passedExpectations.push(expectationResult); this.result.passedExpectations.push(expectationResult);
@@ -343,10 +341,6 @@ getJasmineRequireObj().Spec = function(j$) {
return 'pending'; return 'pending';
} }
if(!this.expectCalled) {
return 'empty';
}
if (this.result.failedExpectations.length > 0) { if (this.result.failedExpectations.length > 0) {
return 'failed'; return 'failed';
} else { } else {

View File

@@ -194,10 +194,9 @@ describe("Spec", function() {
expect(done).toHaveBeenCalled(); expect(done).toHaveBeenCalled();
}); });
it("#status returns empty by default", function(){ it("#status returns passing by default", function(){
var emptySpec = new j$.Spec({ fn: function () {} }); var spec = new j$.Spec({ fn: function () {} });
emptySpec.execute(); expect(spec.status()).toBe("passed");
expect(emptySpec.status()).toBe("empty");
}); });
it("#status returns passed if all expectations in the spec have passed", function() { it("#status returns passed if all expectations in the spec have passed", function() {

View File

@@ -64,7 +64,7 @@ describe("New HtmlReporter", function() {
}); });
describe("when a spec is done", function() { describe("when a spec is done", function() {
it("logs errors to the console if it is an empty spec", function() { it("logs errors to the console and prints a special symbol if it is an empty spec", function() {
if (!window.console) { if (!window.console) {
window.console = { error: function(){} }; window.console = { error: function(){} };
} }
@@ -84,10 +84,14 @@ describe("New HtmlReporter", function() {
reporter.initialize(); reporter.initialize();
reporter.specDone({ reporter.specDone({
status: "empty", status: "passed",
fullName: 'Some Name' fullName: 'Some Name',
passedExpectations: [],
failedExpectations: []
}); });
expect(console.error).toHaveBeenCalledWith("Spec \'Some Name\' has no expectations."); expect(console.error).toHaveBeenCalledWith("Spec \'Some Name\' has no expectations.");
var specEl = container.querySelector('.symbol-summary li');
expect(specEl.getAttribute("class")).toEqual("empty");
}); });
it("reports the status symbol of a disabled spec", function() { it("reports the status symbol of a disabled spec", function() {
@@ -102,7 +106,7 @@ describe("New HtmlReporter", function() {
}); });
reporter.initialize(); reporter.initialize();
reporter.specDone({id: 789, status: "disabled", fullName: "symbols should have titles"}); reporter.specDone({id: 789, status: "disabled", fullName: "symbols should have titles", passedExpectations: [], failedExpectations: []});
var specEl = container.querySelector('.symbol-summary li'); var specEl = container.querySelector('.symbol-summary li');
expect(specEl.getAttribute("class")).toEqual("disabled"); expect(specEl.getAttribute("class")).toEqual("disabled");
@@ -122,7 +126,7 @@ describe("New HtmlReporter", function() {
}); });
reporter.initialize(); reporter.initialize();
reporter.specDone({id: 789, status: "pending"}); reporter.specDone({id: 789, status: "pending", passedExpectations: [], failedExpectations: []});
var specEl = container.querySelector('.symbol-summary li'); var specEl = container.querySelector('.symbol-summary li');
expect(specEl.getAttribute("class")).toEqual("pending"); expect(specEl.getAttribute("class")).toEqual("pending");
@@ -141,7 +145,7 @@ describe("New HtmlReporter", function() {
}); });
reporter.initialize(); reporter.initialize();
reporter.specDone({id: 123, status: "passed"}); reporter.specDone({id: 123, status: "passed", passedExpectations: [{passed: true}], failedExpectations: []});
var statuses = container.querySelector(".symbol-summary"); var statuses = container.querySelector(".symbol-summary");
var specEl = statuses.querySelector("li"); var specEl = statuses.querySelector("li");
@@ -195,15 +199,13 @@ describe("New HtmlReporter", function() {
reporter.initialize(); reporter.initialize();
reporter.jasmineStarted({}); reporter.jasmineStarted({});
reporter.suiteStarted({id: 1}); reporter.suiteStarted({id: 1});
reporter.specStarted({ reporter.specStarted({id: 1, status: 'passed', passedExpectations: [], failedExpectations: []});
status: "empty",
id: 1,
description: 'Spec Description'
});
reporter.specDone({ reporter.specDone({
status: "empty",
id: 1, id: 1,
description: 'Spec Description' status: 'passed',
description: 'Spec Description',
passedExpectations: [],
failedExpectations: []
}); });
reporter.suiteDone({id: 1}); reporter.suiteDone({id: 1});
reporter.jasmineDone({}); reporter.jasmineDone({});
@@ -263,7 +265,9 @@ describe("New HtmlReporter", function() {
id: 123, id: 123,
description: "with a spec", description: "with a spec",
fullName: "A Suite with a spec", fullName: "A Suite with a spec",
status: "passed" status: "passed",
failedExpectations: [],
passedExpectations: [{passed: true}]
}; };
reporter.specStarted(specResult); reporter.specStarted(specResult);
reporter.specDone(specResult); reporter.specDone(specResult);
@@ -278,7 +282,9 @@ describe("New HtmlReporter", function() {
id: 124, id: 124,
description: "with another spec", description: "with another spec",
fullName: "A Suite inner suite with another spec", fullName: "A Suite inner suite with another spec",
status: "passed" status: "passed",
failedExpectations: [],
passedExpectations: [{passed: true}]
}; };
reporter.specStarted(specResult); reporter.specStarted(specResult);
reporter.specDone(specResult); reporter.specDone(specResult);
@@ -290,7 +296,7 @@ describe("New HtmlReporter", function() {
description: "with a failing spec", description: "with a failing spec",
fullName: "A Suite inner with a failing spec", fullName: "A Suite inner with a failing spec",
status: "failed", status: "failed",
failedExpectations: [], failedExpectations: [{}],
passedExpectations: [] passedExpectations: []
}; };
reporter.specStarted(specResult); reporter.specStarted(specResult);
@@ -447,13 +453,17 @@ describe("New HtmlReporter", function() {
id: 123, id: 123,
description: "with a spec", description: "with a spec",
fullName: "A Suite with a spec", fullName: "A Suite with a spec",
status: "passed" status: "passed",
passedExpectations: [{passed: true}],
failedExpectations: []
}); });
reporter.specDone({ reporter.specDone({
id: 124, id: 124,
description: "with another spec", description: "with another spec",
fullName: "A Suite inner suite with another spec", fullName: "A Suite inner suite with another spec",
status: "passed" status: "passed",
passedExpectations: [{passed: true}],
failedExpectations: []
}); });
reporter.jasmineDone({}); reporter.jasmineDone({});
}); });
@@ -498,7 +508,9 @@ describe("New HtmlReporter", function() {
id: 123, id: 123,
description: "with a spec", description: "with a spec",
fullName: "A Suite with a spec", fullName: "A Suite with a spec",
status: "pending" status: "pending",
passedExpectations: [],
failedExpectations: []
}); });
reporter.jasmineDone({}); reporter.jasmineDone({});
}); });
@@ -533,7 +545,7 @@ describe("New HtmlReporter", function() {
reporter.jasmineStarted({ totalSpecsDefined: 1 }); reporter.jasmineStarted({ totalSpecsDefined: 1 });
var passingResult = {id: 123, status: "passed"}; var passingResult = {id: 123, status: "passed", passedExpectations: [{passed: true}], failedExpectations: []};
reporter.specStarted(passingResult); reporter.specStarted(passingResult);
reporter.specDone(passingResult); reporter.specDone(passingResult);
@@ -542,6 +554,7 @@ describe("New HtmlReporter", function() {
status: "failed", status: "failed",
description: "a failing spec", description: "a failing spec",
fullName: "a suite with a failing spec", fullName: "a suite with a failing spec",
passedExpectations: [],
failedExpectations: [ failedExpectations: [
{ {
message: "a failure message", message: "a failure message",

View File

@@ -13,7 +13,6 @@ getJasmineRequireObj().Spec = function(j$) {
this.expectationResultFactory = attrs.expectationResultFactory || function() { }; this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
this.expectCalled = false;
if (!this.fn) { if (!this.fn) {
this.pend(); this.pend();
@@ -29,7 +28,6 @@ getJasmineRequireObj().Spec = function(j$) {
} }
Spec.prototype.addExpectationResult = function(passed, data) { Spec.prototype.addExpectationResult = function(passed, data) {
this.expectCalled = true;
var expectationResult = this.expectationResultFactory(data); var expectationResult = this.expectationResultFactory(data);
if (passed) { if (passed) {
this.result.passedExpectations.push(expectationResult); this.result.passedExpectations.push(expectationResult);
@@ -103,10 +101,6 @@ getJasmineRequireObj().Spec = function(j$) {
return 'pending'; return 'pending';
} }
if(!this.expectCalled) {
return 'empty';
}
if (this.result.failedExpectations.length > 0) { if (this.result.failedExpectations.length > 0) {
return 'failed'; return 'failed';
} else { } else {

View File

@@ -67,7 +67,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var failures = []; var failures = [];
this.specDone = function(result) { this.specDone = function(result) {
if(result.status == 'empty' && console && console.error) { if(noExpectations(result) && console && console.error) {
console.error('Spec \'' + result.fullName + '\' has no expectations.'); console.error('Spec \'' + result.fullName + '\' has no expectations.');
} }
@@ -76,7 +76,7 @@ jasmineRequire.HtmlReporter = function(j$) {
} }
symbols.appendChild(createDom('li', { symbols.appendChild(createDom('li', {
className: result.status, className: noExpectations(result) ? 'empty' : result.status,
id: 'spec_' + result.id, id: 'spec_' + result.id,
title: result.fullName title: result.fullName
} }
@@ -174,7 +174,7 @@ jasmineRequire.HtmlReporter = function(j$) {
domParent.appendChild(specListNode); domParent.appendChild(specListNode);
} }
var specDescription = resultNode.result.description; var specDescription = resultNode.result.description;
if(resultNode.result.status == 'empty') { if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
} }
specListNode.appendChild( specListNode.appendChild(
@@ -269,6 +269,11 @@ jasmineRequire.HtmlReporter = function(j$) {
function setMenuModeTo(mode) { function setMenuModeTo(mode) {
htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode);
} }
function noExpectations(result) {
return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
result.status === 'passed';
}
} }
return HtmlReporter; return HtmlReporter;