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() {
var env;
//describe('Suite', function() {
// 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() {
env = new jasmine.Env();
env.updateInterval = 0;
});
describe("Suite (unit tests)", function() {
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);
});
});
it("keeps its id", function() {
var env = new jasmine.Env(),
suite = new jasmine.Suite({
env: env,
id: 456,
description: "I am a suite"
});
expect(suite.specs().length).toEqual(3);
});
expect(suite.id).toEqual(456);
});
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);
});
});
it("returns its full name", function() {
var env = new jasmine.Env(),
suite = new jasmine.Suite({
env: env,
description: "I am a suite"
});
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;
@@ -89,11 +89,11 @@
this.catchExceptions = function(value) {
return catchExceptions = !!value;
}
};
this.catchingExceptions = function(value) {
return catchExceptions;
}
};
this.specFactory = function(description, fn, suite) {
var spec = new specConstructor({
@@ -103,7 +103,9 @@
expectationFactory: expectationFactory,
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,
getSpecName: function(spec) { return getSpecName(spec, suite) },
getSpecName: function(spec) {
return getSpecName(spec, suite)
},
startCallback: startCallback,
description: description,
catchingExceptions: this.catchingExceptions,
@@ -131,12 +133,19 @@
var queueFactory = function() {
return new queueConstructor(self);
};
this.suiteFactory = function(description, specDefinitions) {
return new suiteConstructor(self, description, specDefinitions, self.currentSuite, queueFactory, isSuite);
this.suiteFactory = function(description) {
return new suiteConstructor({
env: self,
description: description,
currentSuite: self.currentSuite,
queueFactory: queueFactory,
isSuite: isSuite
});
};
var maximumSpecCallbackDepth = 100;
var currentSpecCallbackDepth = 0;
function encourageGarbageCollection(fn) {
currentSpecCallbackDepth++;
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
@@ -145,7 +154,6 @@
} else {
fn();
}
}
};
@@ -162,7 +170,7 @@
/**
* @returns an object containing jasmine version build info, if set.
*/
jasmine.Env.prototype.version = function () {
jasmine.Env.prototype.version = function() {
if (this.jasmine.version_) {
return this.jasmine.version_;
} else {
@@ -171,7 +179,7 @@
};
jasmine.Env.prototype.expect = function(actual) {
return this.currentSpec.expect(actual);
return this.currentSpec.expect(actual);
};
jasmine.Env.prototype.spyOn = function(obj, methodName) {
@@ -227,14 +235,14 @@
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSpecId = function () {
jasmine.Env.prototype.nextSpecId = function() {
return this.nextSpecId_++;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSuiteId = function () {
jasmine.Env.prototype.nextSuiteId = function() {
return this.nextSuiteId_++;
};
@@ -265,7 +273,7 @@
var declarationError = null;
try {
specDefinitions.call(suite);
} catch(e) {
} catch (e) {
declarationError = e;
}
@@ -288,7 +296,7 @@
}
};
jasmine.Env.prototype.currentRunner = function () {
jasmine.Env.prototype.currentRunner = function() {
return this.currentRunner_;
};

View File

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