Deprecate getResults() (use results()). Add some unit test coverage for jasmine.Spec. Add some unit test coverage for JsApiReporterSpec.

This commit is contained in:
ragaskar
2009-09-28 11:13:44 -07:00
parent d09cacebc7
commit 2588368231
39 changed files with 2100 additions and 1518 deletions

View File

@@ -52,7 +52,7 @@ jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.getResults();
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
var message = results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
@@ -61,7 +61,7 @@ jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.getResults();
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
@@ -70,7 +70,7 @@ jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.getResults();
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';

View File

@@ -323,7 +323,7 @@ jasmine.createSpyObj = function(baseName, methodNames) {
};
jasmine.log = function(message) {
jasmine.getEnv().currentSpec.getResults().log(message);
jasmine.getEnv().currentSpec.log(message);
};
/**
@@ -517,7 +517,7 @@ jasmine.version_= {
"major": 0,
"minor": 9,
"build": 0,
"revision": 1252545255
"revision": 1254161532
};
/**
* @namespace
@@ -610,6 +610,9 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
/**
* @returns an object containing jasmine version build info, if set.
*/
jasmine.Env.prototype.version = function () {
if (jasmine.version_) {
return jasmine.version_;
@@ -618,6 +621,20 @@ jasmine.Env.prototype.version = function () {
}
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSpecId = function () {
return this.nextSpecId_++;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSuiteId = function () {
return this.nextSuiteId_++;
};
/**
* Register a reporter to receive status updates from Jasmine.
* @param {jasmine.Reporter} reporter An object which will receive status updates.
@@ -678,7 +695,7 @@ jasmine.Env.prototype.it = function(description, func) {
jasmine.Env.prototype.xit = function(desc, func) {
return {
id: this.nextSpecId_++,
id: this.nextSpecId(),
runs: function() {
}
};
@@ -820,14 +837,10 @@ jasmine.Block.prototype.execute = function(onComplete) {
try {
this.func.apply(this.spec);
} catch (e) {
this.fail(e);
this.spec.fail(e);
}
onComplete();
};
jasmine.Block.prototype.fail = function(e) {
this.spec.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null));
};
/** JavaScript API reporter.
*
* @constructor
@@ -835,8 +848,8 @@ jasmine.Block.prototype.fail = function(e) {
jasmine.JsApiReporter = function() {
this.started = false;
this.finished = false;
this.suites = [];
this.results = {};
this.suites_ = [];
this.results_ = {};
};
jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
@@ -844,10 +857,14 @@ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
this.suites.push(this.summarize_(suite));
this.suites_.push(this.summarize_(suite));
}
};
jasmine.JsApiReporter.prototype.suites = function() {
return this.suites_;
};
jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
var isSuite = suiteOrSpec instanceof jasmine.Suite
var summary = {
@@ -865,6 +882,14 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
return summary;
};
jasmine.JsApiReporter.prototype.results = function() {
return this.results_;
};
jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
return this.results_[specId];
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
this.finished = true;
@@ -876,9 +901,9 @@ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
this.results[spec.id] = {
messages: spec.results.getItems(),
result: spec.results.failedCount > 0 ? "failed" : "passed"
this.results_[spec.id] = {
messages: spec.results().getItems(),
result: spec.results().failedCount > 0 ? "failed" : "passed"
};
};
@@ -890,19 +915,24 @@ jasmine.Matchers = function(env, actual, results) {
this.env = env;
this.actual = actual;
this.passing_message = 'Passed.';
this.results = results || new jasmine.NestedResults();
this.results_ = results || new jasmine.NestedResults();
};
jasmine.Matchers.pp = function(str) {
return jasmine.util.htmlEscape(jasmine.pp(str));
};
/** @deprecated */
jasmine.Matchers.prototype.getResults = function() {
return this.results;
return this.results_;
};
jasmine.Matchers.prototype.results = function() {
return this.results_;
};
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
this.results.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details));
this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details));
return result;
};
@@ -1464,11 +1494,11 @@ jasmine.Queue.prototype.finish = function () {
}
};
jasmine.Queue.prototype.getResults = function () {
jasmine.Queue.prototype.results = function () {
var results = new jasmine.NestedResults();
for (var i = 0; i < this.blocks.length; i++) {
if (this.blocks[i].getResults) {
results.addResult(this.blocks[i].getResults());
if (this.blocks[i].results) {
results.addResult(this.blocks[i].results());
}
}
return results;
@@ -1556,8 +1586,13 @@ jasmine.Runner.prototype.suites = function() {
return this.suites_;
};
jasmine.Runner.prototype.results = function() {
return this.queue.results();
};
/** @deprecated */
jasmine.Runner.prototype.getResults = function() {
return this.queue.getResults();
return this.queue.results();
};
/**
* Internal representation of a Jasmine specification, or test.
@@ -1568,8 +1603,14 @@ jasmine.Runner.prototype.getResults = function() {
* @param {String} description
*/
jasmine.Spec = function(env, suite, description) {
if (!env) {
throw new Error('jasmine.Env() required');
};
if (!suite) {
throw new Error('jasmine.Suite() required');
};
var spec = this;
spec.id = env.nextSpecId_++;
spec.id = env.nextSpecId ? env.nextSpecId() : null;
spec.env = env;
spec.suite = suite;
spec.description = description;
@@ -1578,8 +1619,8 @@ jasmine.Spec = function(env, suite, description) {
spec.afterCallbacks = [];
spec.spies_ = [];
spec.results = new jasmine.NestedResults();
spec.results.description = description;
spec.results_ = new jasmine.NestedResults();
spec.results_.description = description;
spec.matchersClass = null;
};
@@ -1587,8 +1628,18 @@ jasmine.Spec.prototype.getFullName = function() {
return this.suite.getFullName() + ' ' + this.description + '.';
};
jasmine.Spec.prototype.results = function() {
return this.results_;
};
jasmine.Spec.prototype.log = function(message) {
return this.results_.log(message);
};
/** @deprecated */
jasmine.Spec.prototype.getResults = function() {
return this.results;
return this.results_;
};
jasmine.Spec.prototype.runs = function (func) {
@@ -1613,11 +1664,8 @@ jasmine.Spec.prototype.expects_that = function(actual) {
return this.expect(actual);
};
/**
* @private
*/
jasmine.Spec.prototype.expect = function(actual) {
return new (this.getMatchersClass_())(this.env, actual, this.results);
return new (this.getMatchersClass_())(this.env, actual, this.results_);
};
jasmine.Spec.prototype.waits = function(timeout) {
@@ -1632,8 +1680,8 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessag
return this;
};
jasmine.Spec.prototype.failWithException = function (e) {
this.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null));
jasmine.Spec.prototype.fail = function (e) {
this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null));
};
jasmine.Spec.prototype.getMatchersClass_ = function() {
@@ -1676,7 +1724,7 @@ jasmine.Spec.prototype.after = function(doAfter, test) {
jasmine.Spec.prototype.execute = function(onComplete) {
var spec = this;
if (!spec.env.specFilter(spec)) {
spec.results.skipped = true;
spec.results_.skipped = true;
spec.finish(onComplete);
return;
}
@@ -1759,7 +1807,7 @@ jasmine.Spec.prototype.removeAllSpies = function() {
*/
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
var self = this;
self.id = env.nextSuiteId_++;
self.id = env.nextSuiteId ? env.nextSuiteId() : null;
self.description = description;
self.queue = new jasmine.Queue(env);
self.parentSuite = parentSuite;
@@ -1795,8 +1843,13 @@ jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
this.afterQueue.push(afterEachFunction);
};
/** @deprecated */
jasmine.Suite.prototype.getResults = function() {
return this.queue.getResults();
return this.queue.results();
};
jasmine.Suite.prototype.results = function() {
return this.queue.results();
};
jasmine.Suite.prototype.add = function(block) {
@@ -1855,7 +1908,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
try {
latchFunctionResult = self.latchFunction.apply(self.spec);
} catch (e) {
self.fail(e);
self.spec.fail(e);
onComplete();
return;
}
@@ -1864,7 +1917,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
onComplete();
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
self.fail({
self.spec.fail({
name: 'timeout',
message: message
});