Cleanup of Exception formatting (incl. better Browser support re:

toString;
NestedResults is dead, remove it from jasmine.yml
This commit is contained in:
Davis W. Frank
2012-12-10 08:14:39 -08:00
committed by Dan Hansen and Davis W. Frank
parent a9eaa66da5
commit 05977203a6
3 changed files with 257 additions and 147 deletions

View File

@@ -1,113 +1,225 @@
describe('Suite', function() { //describe('Suite', function() {
var env; // var env;
//
// beforeEach(function() {
// env = new jasmine.Env();
// env.updateInterval = 0;
// });
//
// describe('Specs', function () {
// var suite;
//
// beforeEach(function() {
// suite = env.describe('Suite 1', function () {
// env.it('Spec 1', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.it('Spec 2', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.describe('Suite 2', function () {
// env.it('Spec 3', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// });
// env.it('Spec 4', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// });
// });
//
// it('#specs should return all immediate children that are specs.', function () {
// var suiteSpecs = suite.specs();
// expect(suiteSpecs.length).toEqual(3);
// expect(suiteSpecs[0].description).toEqual('Spec 1');
// expect(suiteSpecs[1].description).toEqual('Spec 2');
// expect(suiteSpecs[2].description).toEqual('Spec 4');
// });
//
// it("#suites should return all immediate children that are suites.", function() {
// var nestedSuites = suite.suites();
// expect(nestedSuites.length).toEqual(1);
// expect(nestedSuites[0].description).toEqual('Suite 2');
// });
//
// it("#children should return all immediate children including suites and specs.", function() {
// var children = suite.children();
// expect(children.length).toEqual(4);
// expect(children[0].description).toEqual('Spec 1');
// expect(children[1].description).toEqual('Spec 2');
// expect(children[2].description).toEqual('Suite 2');
// expect(children[3].description).toEqual('Spec 4');
// });
// });
//
// describe('SpecCount', function () {
//
// it('should keep a count of the number of specs that are run', function() {
// var suite = env.describe('one suite description', function () {
// env.it('should be a test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.it('should be another test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.it('should be a third test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// });
//
// expect(suite.specs().length).toEqual(3);
// });
//
// it('specCount should be correct even with runs/waits blocks', function() {
// var suite = env.describe('one suite description', function () {
// env.it('should be a test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.it('should be another test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// this.waits(10);
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// env.it('should be a third test', function() {
// this.runs(function () {
// this.expect(true).toEqual(true);
// });
// });
// });
//
// expect(suite.specs().length).toEqual(3);
// });
// });
//});
beforeEach(function() { describe("Suite (unit tests)", function() {
env = new jasmine.Env();
env.updateInterval = 0;
});
describe('Specs', function () { it("keeps its id", function() {
var suite; var env = new jasmine.Env(),
suite = new jasmine.Suite({
beforeEach(function() { env: env,
suite = env.describe('Suite 1', function () { id: 456,
env.it('Spec 1', function() { description: "I am a suite"
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('Spec 2', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.describe('Suite 2', function () {
env.it('Spec 3', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
env.it('Spec 4', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
});
});
it('#specs should return all immediate children that are specs.', function () {
var suiteSpecs = suite.specs();
expect(suiteSpecs.length).toEqual(3);
expect(suiteSpecs[0].description).toEqual('Spec 1');
expect(suiteSpecs[1].description).toEqual('Spec 2');
expect(suiteSpecs[2].description).toEqual('Spec 4');
});
it("#suites should return all immediate children that are suites.", function() {
var nestedSuites = suite.suites();
expect(nestedSuites.length).toEqual(1);
expect(nestedSuites[0].description).toEqual('Suite 2');
});
it("#children should return all immediate children including suites and specs.", function() {
var children = suite.children();
expect(children.length).toEqual(4);
expect(children[0].description).toEqual('Spec 1');
expect(children[1].description).toEqual('Spec 2');
expect(children[2].description).toEqual('Suite 2');
expect(children[3].description).toEqual('Spec 4');
});
});
describe('SpecCount', function () {
it('should keep a count of the number of specs that are run', function() {
var suite = env.describe('one suite description', function () {
env.it('should be a test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be another test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be a third test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
}); });
expect(suite.specs().length).toEqual(3); expect(suite.id).toEqual(456);
}); });
it('specCount should be correct even with runs/waits blocks', function() { it("returns its full name", function() {
var suite = env.describe('one suite description', function () { var env = new jasmine.Env(),
env.it('should be a test', function() { suite = new jasmine.Suite({
this.runs(function () { env: env,
this.expect(true).toEqual(true); description: "I am a suite"
});
});
env.it('should be another test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
this.waits(10);
this.runs(function () {
this.expect(true).toEqual(true);
});
});
env.it('should be a third test', function() {
this.runs(function () {
this.expect(true).toEqual(true);
});
});
}); });
expect(suite.specs().length).toEqual(3); expect(suite.getFullName()).toEqual("I am a suite");
});
}); });
it("returns its full name when it has parent suites", function() {
var env = new jasmine.Env(),
parentSuite = new jasmine.Suite({
env: env,
description: "I am a suite"
});
suite = new jasmine.Suite({
env: env,
description: "I am a suite"
});
expect(suite.getFullName()).toEqual("I am a suite");
});
it("adds before functions in order of needed execution", function() {
var env = new jasmine.Env(),
suite = new jasmine.Suite({
env: env,
description: "I am a suite"
}),
outerBefore = jasmine.createSpy('outerBeforeEach'),
innerBefore = jasmine.createSpy('insideBeforeEach');
suite.beforeEach(outerBefore);
suite.beforeEach(innerBefore);
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
});
it("adds after functions in order of needed execution", function() {
var env = new jasmine.Env(),
suite = new jasmine.Suite({
env: env,
description: "I am a suite"
}),
outerAfter = jasmine.createSpy('outerAfterEach'),
innerAfter = jasmine.createSpy('insideAfterEach');
suite.afterEach(outerAfter);
suite.afterEach(innerAfter);
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
});
it("adds specs", function() {
var env = new jasmine.Env(),
suite = new jasmine.Suite({
env: env,
description: "I am a suite"
}),
fakeSpec = {};
expect(suite.specs.length).toEqual(0);
suite.addSpec(fakeSpec);
expect(suite.specs.length).toEqual(1);git
});
}); });
// TODO:
describe("Suite (acceptance)", function() {
it("can execute and run all of its befores, specs, and afters", function() {
var env = new jasmine.Env(),
calls = [];
env.describe("A suite", function() {
env.beforeEach(function() {
calls.push('before');
});
env.it("with a spec", function() {
calls.push('spec');
});
env.afterEach(function() {
calls.push('after');
});
});
env.execute();
expect(calls).toEqual(['before', 'spec', 'after']);
});
});

View File

@@ -74,7 +74,7 @@
} }
}; };
var exceptionFormatter = jasmine.exceptionMessageFor; var exceptionFormatter = jasmine.exceptionFormatter;
var specConstructor = jasmine.Spec; var specConstructor = jasmine.Spec;
@@ -89,11 +89,11 @@
this.catchExceptions = function(value) { this.catchExceptions = function(value) {
return catchExceptions = !!value; return catchExceptions = !!value;
} };
this.catchingExceptions = function(value) { this.catchingExceptions = function(value) {
return catchExceptions; return catchExceptions;
} };
this.specFactory = function(description, fn, suite) { this.specFactory = function(description, fn, suite) {
var spec = new specConstructor({ var spec = new specConstructor({
@@ -103,7 +103,9 @@
expectationFactory: expectationFactory, expectationFactory: expectationFactory,
exceptionFormatter: exceptionFormatter, exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback, resultCallback: specResultCallback,
getSpecName: function(spec) { return getSpecName(spec, suite) }, getSpecName: function(spec) {
return getSpecName(spec, suite)
},
startCallback: startCallback, startCallback: startCallback,
description: description, description: description,
catchingExceptions: this.catchingExceptions, catchingExceptions: this.catchingExceptions,
@@ -131,12 +133,19 @@
var queueFactory = function() { var queueFactory = function() {
return new queueConstructor(self); return new queueConstructor(self);
}; };
this.suiteFactory = function(description, specDefinitions) { this.suiteFactory = function(description) {
return new suiteConstructor(self, description, specDefinitions, self.currentSuite, queueFactory, isSuite); return new suiteConstructor({
env: self,
description: description,
currentSuite: self.currentSuite,
queueFactory: queueFactory,
isSuite: isSuite
});
}; };
var maximumSpecCallbackDepth = 100; var maximumSpecCallbackDepth = 100;
var currentSpecCallbackDepth = 0; var currentSpecCallbackDepth = 0;
function encourageGarbageCollection(fn) { function encourageGarbageCollection(fn) {
currentSpecCallbackDepth++; currentSpecCallbackDepth++;
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) { if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
@@ -145,7 +154,6 @@
} else { } else {
fn(); fn();
} }
} }
}; };
@@ -162,7 +170,7 @@
/** /**
* @returns an object containing jasmine version build info, if set. * @returns an object containing jasmine version build info, if set.
*/ */
jasmine.Env.prototype.version = function () { jasmine.Env.prototype.version = function() {
if (this.jasmine.version_) { if (this.jasmine.version_) {
return this.jasmine.version_; return this.jasmine.version_;
} else { } else {
@@ -171,7 +179,7 @@
}; };
jasmine.Env.prototype.expect = function(actual) { jasmine.Env.prototype.expect = function(actual) {
return this.currentSpec.expect(actual); return this.currentSpec.expect(actual);
}; };
jasmine.Env.prototype.spyOn = function(obj, methodName) { jasmine.Env.prototype.spyOn = function(obj, methodName) {
@@ -227,14 +235,14 @@
/** /**
* @returns a sequential integer starting at 0 * @returns a sequential integer starting at 0
*/ */
jasmine.Env.prototype.nextSpecId = function () { jasmine.Env.prototype.nextSpecId = function() {
return this.nextSpecId_++; return this.nextSpecId_++;
}; };
/** /**
* @returns a sequential integer starting at 0 * @returns a sequential integer starting at 0
*/ */
jasmine.Env.prototype.nextSuiteId = function () { jasmine.Env.prototype.nextSuiteId = function() {
return this.nextSuiteId_++; return this.nextSuiteId_++;
}; };
@@ -265,7 +273,7 @@
var declarationError = null; var declarationError = null;
try { try {
specDefinitions.call(suite); specDefinitions.call(suite);
} catch(e) { } catch (e) {
declarationError = e; declarationError = e;
} }
@@ -288,7 +296,7 @@
} }
}; };
jasmine.Env.prototype.currentRunner = function () { jasmine.Env.prototype.currentRunner = function() {
return this.currentRunner_; return this.currentRunner_;
}; };

View File

@@ -1,27 +1,19 @@
/** jasmine.Suite = function(attrs) {
* Internal representation of a Jasmine suite. this.env = attrs.env;
* this.id = attrs.id;
* @constructor this.parentSuite = attrs.parentSuite;
* @param {jasmine.Env} env this.description = attrs.description;
* @param {String} description this.beforeFns = [];
* @param {Function} specDefinitions this.afterFns = [];
* @param {jasmine.Suite} parentSuite
*/ var queueFactory = attrs.queueFactory || function() {};
jasmine.Suite = function(env, description, specDefinitions, parentSuite, queueFactory, isSuite) { this.queue = queueFactory();
var self = this;
//TODO: remove once we unit test Suite this.isSuite = attrs.isSuite || function() {};
var queueFactory = queueFactory || function() {};
self.id = env.nextSuiteId ? env.nextSuiteId() : null; this.children_ = []; // TODO: used by current reporters; keep for now
self.description = description; this.suites_ = [];
self.queue = queueFactory(); this.specs_ = [];
self.parentSuite = parentSuite;
self.env = env;
self.isSuite = isSuite || function() {};
self.before_ = [];
self.after_ = [];
self.children_ = [];
self.suites_ = [];
self.specs_ = [];
}; };
jasmine.Suite.prototype.getFullName = function() { jasmine.Suite.prototype.getFullName = function() {
@@ -40,14 +32,12 @@ jasmine.Suite.prototype.finish = function(onComplete) {
} }
}; };
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { jasmine.Suite.prototype.beforeEach = function(fn) {
beforeEachFunction.typeName = 'beforeEach'; this.beforeFns.unshift(fn);
this.before_.unshift(beforeEachFunction);
}; };
jasmine.Suite.prototype.afterEach = function(afterEachFunction) { jasmine.Suite.prototype.afterEach = function(fn) {
afterEachFunction.typeName = 'afterEach'; this.afterFns.unshift(fn);
this.after_.unshift(afterEachFunction);
}; };
//TODO: interface should be addSpec or addSuite methods. //TODO: interface should be addSpec or addSuite methods.