diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js
index a33e6c17..3d241f59 100644
--- a/lib/jasmine-core/jasmine-html.js
+++ b/lib/jasmine-core/jasmine-html.js
@@ -34,6 +34,45 @@ jasmineRequire.HtmlReporter = function(j$) {
elapsed: function() { return 0; }
};
+ function ResultsStateBuilder() {
+ this.topResults = new j$.ResultsNode({}, '', null);
+ this.currentParent = this.topResults;
+ this.specsExecuted = 0;
+ this.failureCount = 0;
+ this.pendingSpecCount = 0;
+ }
+
+ ResultsStateBuilder.prototype.suiteStarted = function(result) {
+ this.currentParent.addChild(result, 'suite');
+ this.currentParent = this.currentParent.last();
+ };
+
+ ResultsStateBuilder.prototype.suiteDone = function(result) {
+ if (this.currentParent !== this.topResults) {
+ this.currentParent = this.currentParent.parent;
+ }
+ };
+
+ ResultsStateBuilder.prototype.specStarted = function(result) {
+ this.currentParent.addChild(result, 'spec');
+ };
+
+ ResultsStateBuilder.prototype.specDone = function(result) {
+ if (result.status !== 'disabled') {
+ this.specsExecuted++;
+ }
+
+ if (result.status === 'failed') {
+ this.failureCount++;
+ }
+
+ if (result.status == 'pending') {
+ this.pendingSpecCount++;
+ }
+ };
+
+
+
function HtmlReporter(options) {
var env = options.env || {},
getContainer = options.getContainer,
@@ -46,9 +85,6 @@ jasmineRequire.HtmlReporter = function(j$) {
filterSpecs = options.filterSpecs,
timer = options.timer || noopTimer,
results = [],
- specsExecuted = 0,
- failureCount = 0,
- pendingSpecCount = 0,
htmlReporterMain,
symbols,
failedSuites = [];
@@ -77,12 +113,10 @@ jasmineRequire.HtmlReporter = function(j$) {
var summary = createDom('div', {className: 'jasmine-summary'});
- var topResults = new j$.ResultsNode({}, '', null),
- currentParent = topResults;
+ var stateBuilder = new ResultsStateBuilder();
this.suiteStarted = function(result) {
- currentParent.addChild(result, 'suite');
- currentParent = currentParent.last();
+ stateBuilder.suiteStarted(result);
};
this.suiteDone = function(result) {
@@ -90,27 +124,21 @@ jasmineRequire.HtmlReporter = function(j$) {
failedSuites.push(result);
}
- if (currentParent == topResults) {
- return;
- }
-
- currentParent = currentParent.parent;
+ stateBuilder.suiteDone(result);
};
this.specStarted = function(result) {
- currentParent.addChild(result, 'spec');
+ stateBuilder.specStarted(result);
};
var failures = [];
this.specDone = function(result) {
+ stateBuilder.specDone(result);
+
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
- if (result.status != 'disabled') {
- specsExecuted++;
- }
-
if (!symbols){
symbols = find('.jasmine-symbol-summary');
}
@@ -123,8 +151,6 @@ jasmineRequire.HtmlReporter = function(j$) {
));
if (result.status == 'failed') {
- failureCount++;
-
var failure =
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
createDom('div', {className: 'jasmine-description'},
@@ -142,10 +168,6 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failure);
}
-
- if (result.status == 'pending') {
- pendingSpecCount++;
- }
};
this.jasmineDone = function(doneResult) {
@@ -208,8 +230,8 @@ jasmineRequire.HtmlReporter = function(j$) {
}
};
- if (specsExecuted < totalSpecsDefined) {
- var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
+ if (stateBuilder.specsExecuted < totalSpecsDefined) {
+ var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
var skippedLink = addToExistingQueryString('spec', '');
alert.appendChild(
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
@@ -221,9 +243,9 @@ jasmineRequire.HtmlReporter = function(j$) {
var statusBarClassName = 'jasmine-bar ';
if (totalSpecsDefined > 0) {
- statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
- if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
- statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
+ statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
+ if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
+ statusBarClassName += (stateBuilder.failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
} else {
statusBarClassName += 'jasmine-skipped';
statusBarMessage += 'No specs found';
@@ -258,7 +280,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var results = find('.jasmine-results');
results.appendChild(summary);
- summaryList(topResults, summary);
+ summaryList(stateBuilder.topResults, summary);
function summaryList(resultsTree, domParent) {
var specListNode;
diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js
index 02a9e1ce..27baf7da 100644
--- a/src/html/HtmlReporter.js
+++ b/src/html/HtmlReporter.js
@@ -5,6 +5,45 @@ jasmineRequire.HtmlReporter = function(j$) {
elapsed: function() { return 0; }
};
+ function ResultsStateBuilder() {
+ this.topResults = new j$.ResultsNode({}, '', null);
+ this.currentParent = this.topResults;
+ this.specsExecuted = 0;
+ this.failureCount = 0;
+ this.pendingSpecCount = 0;
+ }
+
+ ResultsStateBuilder.prototype.suiteStarted = function(result) {
+ this.currentParent.addChild(result, 'suite');
+ this.currentParent = this.currentParent.last();
+ };
+
+ ResultsStateBuilder.prototype.suiteDone = function(result) {
+ if (this.currentParent !== this.topResults) {
+ this.currentParent = this.currentParent.parent;
+ }
+ };
+
+ ResultsStateBuilder.prototype.specStarted = function(result) {
+ this.currentParent.addChild(result, 'spec');
+ };
+
+ ResultsStateBuilder.prototype.specDone = function(result) {
+ if (result.status !== 'disabled') {
+ this.specsExecuted++;
+ }
+
+ if (result.status === 'failed') {
+ this.failureCount++;
+ }
+
+ if (result.status == 'pending') {
+ this.pendingSpecCount++;
+ }
+ };
+
+
+
function HtmlReporter(options) {
var env = options.env || {},
getContainer = options.getContainer,
@@ -17,9 +56,6 @@ jasmineRequire.HtmlReporter = function(j$) {
filterSpecs = options.filterSpecs,
timer = options.timer || noopTimer,
results = [],
- specsExecuted = 0,
- failureCount = 0,
- pendingSpecCount = 0,
htmlReporterMain,
symbols,
failedSuites = [];
@@ -48,12 +84,10 @@ jasmineRequire.HtmlReporter = function(j$) {
var summary = createDom('div', {className: 'jasmine-summary'});
- var topResults = new j$.ResultsNode({}, '', null),
- currentParent = topResults;
+ var stateBuilder = new ResultsStateBuilder();
this.suiteStarted = function(result) {
- currentParent.addChild(result, 'suite');
- currentParent = currentParent.last();
+ stateBuilder.suiteStarted(result);
};
this.suiteDone = function(result) {
@@ -61,27 +95,21 @@ jasmineRequire.HtmlReporter = function(j$) {
failedSuites.push(result);
}
- if (currentParent == topResults) {
- return;
- }
-
- currentParent = currentParent.parent;
+ stateBuilder.suiteDone(result);
};
this.specStarted = function(result) {
- currentParent.addChild(result, 'spec');
+ stateBuilder.specStarted(result);
};
var failures = [];
this.specDone = function(result) {
+ stateBuilder.specDone(result);
+
if(noExpectations(result) && typeof console !== 'undefined' && typeof console.error !== 'undefined') {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
- if (result.status != 'disabled') {
- specsExecuted++;
- }
-
if (!symbols){
symbols = find('.jasmine-symbol-summary');
}
@@ -94,8 +122,6 @@ jasmineRequire.HtmlReporter = function(j$) {
));
if (result.status == 'failed') {
- failureCount++;
-
var failure =
createDom('div', {className: 'jasmine-spec-detail jasmine-failed'},
createDom('div', {className: 'jasmine-description'},
@@ -113,10 +139,6 @@ jasmineRequire.HtmlReporter = function(j$) {
failures.push(failure);
}
-
- if (result.status == 'pending') {
- pendingSpecCount++;
- }
};
this.jasmineDone = function(doneResult) {
@@ -179,8 +201,8 @@ jasmineRequire.HtmlReporter = function(j$) {
}
};
- if (specsExecuted < totalSpecsDefined) {
- var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
+ if (stateBuilder.specsExecuted < totalSpecsDefined) {
+ var skippedMessage = 'Ran ' + stateBuilder.specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
var skippedLink = addToExistingQueryString('spec', '');
alert.appendChild(
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
@@ -192,9 +214,9 @@ jasmineRequire.HtmlReporter = function(j$) {
var statusBarClassName = 'jasmine-bar ';
if (totalSpecsDefined > 0) {
- statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount);
- if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); }
- statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
+ statusBarMessage += pluralize('spec', stateBuilder.specsExecuted) + ', ' + pluralize('failure', stateBuilder.failureCount);
+ if (stateBuilder.pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', stateBuilder.pendingSpecCount); }
+ statusBarClassName += (stateBuilder.failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed';
} else {
statusBarClassName += 'jasmine-skipped';
statusBarMessage += 'No specs found';
@@ -229,7 +251,7 @@ jasmineRequire.HtmlReporter = function(j$) {
var results = find('.jasmine-results');
results.appendChild(summary);
- summaryList(topResults, summary);
+ summaryList(stateBuilder.topResults, summary);
function summaryList(resultsTree, domParent) {
var specListNode;