Merge branch 'beforeAll' into master

Conflicts:
	lib/jasmine-core/boot.js
	lib/jasmine-core/boot/boot.js
	lib/jasmine-core/jasmine.css
	lib/jasmine-core/jasmine.js
	spec/core/SpecSpec.js
	spec/core/SuiteSpec.js
	spec/core/integration/EnvSpec.js
	spec/node_suite.js
	src/core/Env.js
	src/core/requireCore.js
	src/core/util.js
This commit is contained in:
slackersoft
2014-09-24 20:19:47 -07:00
29 changed files with 2512 additions and 655 deletions
-63
View File
@@ -5,68 +5,6 @@ describe("Env", function() {
env = new j$.Env();
});
it('removes all spies when env is executed', function(done) {
var originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
var assertions = function() {
expect(firstSpec).toHaveBeenCalled();
expect(secondSpec).toHaveBeenCalled();
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
describe("#spyOn", function() {
it("checks for the existence of the object", function() {
expect(function() {
env.spyOn(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks for the existence of the method", function() {
var subject = {};
expect(function() {
env.spyOn(subject, 'pants');
}).toThrowError(/method does not exist/);
});
it("checks if it has already been spied upon", function() {
var subject = { spiedFunc: function() {} };
env.spyOn(subject, 'spiedFunc');
expect(function() {
env.spyOn(subject, 'spiedFunc');
}).toThrowError(/has already been spied upon/);
});
it("overrides the method on the object and returns the spy", function() {
var originalFunctionWasCalled = false;
var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var spy = env.spyOn(subject, 'spiedFunc');
expect(subject.spiedFunc).toEqual(spy);
});
});
describe("#pending", function() {
it("throws the Pending Spec exception", function() {
expect(function() {
@@ -82,4 +20,3 @@ describe("Env", function() {
});
});
});
+15 -53
View File
@@ -1,14 +1,14 @@
describe("Expectation", function() {
it(".addMatchers makes matchers available to any expectation", function() {
it("makes custom matchers available to this expectation", function() {
var matchers = {
toFoo: function() {},
toBar: function() {}
},
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({});
expectation = new j$.Expectation({
customMatchers: matchers
});
expect(expectation.toFoo).toBeDefined();
expect(expectation.toBar).toBeDefined();
@@ -27,25 +27,6 @@ describe("Expectation", function() {
expect(expectation.toQuux).toBeDefined();
});
it(".resetMatchers should keep only core matchers", function() {
var matchers = {
toFoo: function() {}
},
coreMatchers = {
toQuux: function() {}
},
expectation;
j$.Expectation.addCoreMatchers(coreMatchers);
j$.Expectation.addMatchers(matchers);
j$.Expectation.resetMatchers();
expectation = new j$.Expectation({});
expect(expectation.toQuux).toBeDefined();
expect(expectation.toFoo).toBeUndefined();
});
it("Factory builds an expectation/negative expectation", function() {
var builtExpectation = j$.Expectation.Factory();
@@ -65,10 +46,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
util: util,
customMatchers: matchers,
customEqualityTesters: customEqualityTesters,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -94,10 +74,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
util: util,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
});
@@ -121,10 +100,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
util: util,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -155,10 +132,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
util: util,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -191,10 +166,9 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
});
@@ -225,10 +199,8 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
});
@@ -259,10 +231,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -294,10 +264,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
util: util,
addExpectationResult: addExpectationResult,
@@ -332,10 +300,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -365,10 +331,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
@@ -403,10 +367,8 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
j$.Expectation.addMatchers(matchers);
expectation = new j$.Expectation({
matchers: matchers,
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
isNot: true
+3 -2
View File
@@ -135,7 +135,9 @@ describe("j$.pp", function () {
},
env = new j$.Env();
env.spyOn(TestObject, 'someFunction');
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {return [];}});
spyRegistry.spyOn(TestObject, 'someFunction');
expect(j$.pp(TestObject.someFunction)).toEqual("spy on someFunction");
expect(j$.pp(j$.createSpy("something"))).toEqual("spy on something");
@@ -158,4 +160,3 @@ describe("j$.pp", function () {
expect(j$.pp(obj)).toEqual("{ foo: 'bar' }");
});
});
+69 -66
View File
@@ -2,15 +2,15 @@ describe("QueueRunner", function() {
it("runs all the functions it's passed", function() {
var calls = [],
fn1 = jasmine.createSpy('fn1'),
fn2 = jasmine.createSpy('fn2'),
queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2]
queueableFns: [queueableFn1, queueableFn2]
});
fn1.and.callFake(function() {
queueableFn1.fn.and.callFake(function() {
calls.push('fn1');
});
fn2.and.callFake(function() {
queueableFn2.fn.and.callFake(function() {
calls.push('fn2');
});
@@ -20,19 +20,19 @@ describe("QueueRunner", function() {
});
it("calls each function with a consistent 'this'-- an empty object", function() {
var fn1 = jasmine.createSpy('fn1'),
fn2 = jasmine.createSpy('fn2'),
fn3 = function(done) { asyncContext = this; done(); },
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueableFn3 = { fn: function(done) { asyncContext = this; done(); } },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3]
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
}),
asyncContext;
queueRunner.execute();
var context = fn1.calls.first().object;
var context = queueableFn1.fn.calls.first().object;
expect(context).toEqual({});
expect(fn2.calls.first().object).toBe(context);
expect(queueableFn2.fn.calls.first().object).toBe(context);
expect(asyncContext).toBe(context);
});
@@ -53,20 +53,20 @@ describe("QueueRunner", function() {
beforeCallback = jasmine.createSpy('beforeCallback'),
fnCallback = jasmine.createSpy('fnCallback'),
afterCallback = jasmine.createSpy('afterCallback'),
fn1 = function(done) {
queueableFn1 = { fn: function(done) {
beforeCallback();
setTimeout(done, 100);
},
fn2 = function(done) {
} },
queueableFn2 = { fn: function(done) {
fnCallback();
setTimeout(done, 100);
},
fn3 = function(done) {
} },
queueableFn3 = { fn: function(done) {
afterCallback();
setTimeout(done, 100);
},
} },
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3],
queueableFns: [queueableFn1, queueableFn2, queueableFn3],
onComplete: onComplete
});
@@ -94,54 +94,54 @@ describe("QueueRunner", function() {
});
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var beforeFn = function(done) { },
fn = jasmine.createSpy('fn'),
var timeout = 3,
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [beforeFn, fn],
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException,
enforceTimeout: function() { return true; }
onException: onException
});
queueRunner.execute();
expect(fn).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
jasmine.clock().tick(timeout);
expect(onException).toHaveBeenCalledWith(jasmine.any(Error));
expect(fn).toHaveBeenCalled();
expect(queueableFn.fn).toHaveBeenCalled();
expect(onComplete).toHaveBeenCalled();
});
it("by default does not set a timeout for asynchronous functions", function() {
var beforeFn = function(done) { },
fn = jasmine.createSpy('fn'),
var beforeFn = { fn: function(done) { } },
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [beforeFn, fn],
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException,
});
queueRunner.execute();
expect(fn).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(onException).not.toHaveBeenCalled();
expect(fn).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled();
});
it("clears the timeout when an async function throws an exception, to prevent additional onException calls", function() {
var fn = function(done) { throw new Error("error!"); },
it("clears the timeout when an async function throws an exception, to prevent additional exception reporting", function() {
var queueableFn = { fn: function(done) { throw new Error("error!"); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
});
@@ -156,11 +156,11 @@ describe("QueueRunner", function() {
});
it("clears the timeout when the done callback is called", function() {
var fn = function(done) { done(); },
var queueableFn = { fn: function(done) { done(); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
});
@@ -174,75 +174,78 @@ describe("QueueRunner", function() {
});
it("only moves to the next spec the first time you call done", function() {
var fn = function(done) {done(); done();},
nextFn = jasmine.createSpy('nextFn');
var queueableFn = { fn: function(done) {done(); done();} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
expect(nextFn.calls.count()).toEqual(1);
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
});
it("does not move to the next spec if done is called after an exception has ended the spec", function() {
var fn = function(done) {
var queueableFn = { fn: function(done) {
setTimeout(done, 1);
throw new Error('error!');
},
nextFn = jasmine.createSpy('nextFn');
} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
jasmine.clock().tick(1);
expect(nextFn.calls.count()).toEqual(1);
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
});
});
it("calls an exception handler when an exception is thrown in a fn", function() {
var fn = function() {
it("calls exception handlers when an exception is thrown in a fn", function() {
var queueableFn = { type: 'queueable',
fn: function() {
throw new Error('fake error');
},
exceptionCallback = jasmine.createSpy('exception callback'),
} },
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new j$.QueueRunner({
fns: [fn],
onException: exceptionCallback
queueableFns: [queueableFn],
onException: onExceptionCallback
});
queueRunner.execute();
expect(exceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
expect(onExceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
});
it("rethrows an exception if told to", function() {
var fn = function() {
var queueableFn = { fn: function() {
throw new Error('fake error');
},
} },
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
catchException: function(e) { return false; }
});
expect(queueRunner.execute).toThrow();
expect(function() {
queueRunner.execute();
}).toThrowError('fake error');
});
it("continues running the functions even after an exception is thrown in an async spec", function() {
var fn = function(done) { throw new Error("error"); },
nextFn = jasmine.createSpy("nextFunction"),
var queueableFn = { fn: function(done) { throw new Error("error"); } },
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
queueableFns: [queueableFn, nextQueueableFn]
});
queueRunner.execute();
expect(nextFn).toHaveBeenCalled();
expect(nextQueueableFn.fn).toHaveBeenCalled();
});
it("calls a provided complete callback when done", function() {
var fn = jasmine.createSpy('fn'),
var queueableFn = { fn: jasmine.createSpy('fn') },
completeCallback = jasmine.createSpy('completeCallback'),
queueRunner = new j$.QueueRunner({
fns: [fn],
queueableFns: [queueableFn],
onComplete: completeCallback
});
@@ -252,12 +255,12 @@ describe("QueueRunner", function() {
});
it("calls a provided stack clearing function when done", function() {
var asyncFn = function(done) { done() },
afterFn = jasmine.createSpy('afterFn'),
var asyncFn = { fn: function(done) { done() } },
afterFn = { fn: jasmine.createSpy('afterFn') },
completeCallback = jasmine.createSpy('completeCallback'),
clearStack = jasmine.createSpy('clearStack'),
queueRunner = new j$.QueueRunner({
fns: [asyncFn, afterFn],
queueableFns: [asyncFn, afterFn],
clearStack: clearStack,
onComplete: completeCallback
});
@@ -265,7 +268,7 @@ describe("QueueRunner", function() {
clearStack.and.callFake(function(fn) { fn(); });
queueRunner.execute();
expect(afterFn).toHaveBeenCalled();
expect(afterFn.fn).toHaveBeenCalled();
expect(clearStack).toHaveBeenCalledWith(completeCallback);
});
});
+24 -25
View File
@@ -29,7 +29,7 @@ describe("Spec", function() {
spec = new j$.Spec({
description: 'my test',
id: 'some-id',
fn: function() {},
queueableFn: { fn: function() {} },
queueRunnerFactory: fakeQueueRunner
});
@@ -44,7 +44,7 @@ describe("Spec", function() {
spec = new j$.Spec({
id: 123,
description: 'foo bar',
fn: function() {},
queueableFn: { fn: function() {} },
onStart: startCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -66,7 +66,7 @@ describe("Spec", function() {
expect(beforesWereCalled).toBe(false);
}),
spec = new j$.Spec({
fn: function() {},
queueableFn: { fn: function() {} },
beforeFns: function() {
return [function() {
beforesWereCalled = true
@@ -85,25 +85,22 @@ describe("Spec", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
before = jasmine.createSpy('before'),
after = jasmine.createSpy('after'),
fn = jasmine.createSpy('test body').and.callFake(function() {
queueableFn = { fn: jasmine.createSpy('test body').and.callFake(function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
}),
}) },
spec = new j$.Spec({
fn: fn,
beforeFns: function() {
return [before]
},
afterFns: function() {
return [after]
queueableFn: queueableFn,
beforeAndAfterFns: function() {
return {befores: [before], afters: [after]}
},
queueRunnerFactory: fakeQueueRunner
});
spec.execute();
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].fns;
expect(allSpecFns).toEqual([before, fn, after]);
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
expect(allSpecFns).toEqual([before, queueableFn, after]);
});
it("is marked pending if created without a function body", function() {
@@ -113,7 +110,7 @@ describe("Spec", function() {
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
onStart: startCallback,
fn: null,
queueableFn: { fn: null },
resultCallback: resultCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -129,7 +126,7 @@ describe("Spec", function() {
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
onStart:startCallback,
fn: specBody,
queueableFn: { fn: specBody },
resultCallback: resultCallback,
queueRunnerFactory: fakeQueueRunner
});
@@ -158,7 +155,8 @@ describe("Spec", function() {
getSpecName: function() {
return "a suite with a spec"
},
queueRunnerFactory: fakeQueueRunner
queueRunnerFactory: fakeQueueRunner,
queueableFn: { fn: null }
});
spec.pend();
@@ -183,7 +181,7 @@ describe("Spec", function() {
it("should call the done callback on execution complete", function() {
var done = jasmine.createSpy('done callback'),
spec = new j$.Spec({
fn: function() {},
queueableFn: { fn: function() {} },
catchExceptions: function() { return false; },
resultCallback: function() {},
queueRunnerFactory: function(attrs) { attrs.onComplete(); }
@@ -194,19 +192,19 @@ describe("Spec", function() {
expect(done).toHaveBeenCalled();
});
it("#status returns passing by default", function(){
var spec = new j$.Spec({ fn: function () {} });
expect(spec.status()).toBe("passed");
it("#status returns passing by default", function() {
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
expect(spec.status()).toBe('passed');
});
it("#status returns passed if all expectations in the spec have passed", function() {
var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
spec.addExpectationResult(true);
expect(spec.status()).toBe('passed');
});
it("#status returns failed if any expectations in the spec have failed", function() {
var spec = new j$.Spec({ fn: jasmine.createSpy("spec body") });
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body") } });
spec.addExpectationResult(true);
spec.addExpectationResult(false);
expect(spec.status()).toBe('failed');
@@ -215,7 +213,7 @@ describe("Spec", function() {
it("keeps track of passed and failed expectations", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
fn: jasmine.createSpy("spec body"),
queueableFn: { fn: jasmine.createSpy("spec body") },
expectationResultFactory: function (data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
resultCallback: resultCallback
@@ -233,7 +231,8 @@ describe("Spec", function() {
var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
var spec = new j$.Spec({
getSpecName: specNameSpy
getSpecName: specNameSpy,
queueableFn: { fn: null }
});
expect(spec.getFullName()).toBe('expected val');
@@ -248,7 +247,7 @@ describe("Spec", function() {
spec = new j$.Spec({
description: 'my test',
id: 'some-id',
fn: function() { },
queueableFn: { fn: function() { } },
queueRunnerFactory: fakeQueueRunner
});
+55
View File
@@ -0,0 +1,55 @@
describe("SpyRegistry", function() {
describe("#spyOn", function() {
it("checks for the existence of the object", function() {
var spyRegistry = new j$.SpyRegistry();
expect(function() {
spyRegistry.spyOn(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks for the existence of the method", function() {
var spyRegistry = new j$.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOn(subject, 'pants');
}).toThrowError(/method does not exist/);
});
it("checks if it has already been spied upon", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
subject = { spiedFunc: function() {} };
spyRegistry.spyOn(subject, 'spiedFunc');
expect(function() {
spyRegistry.spyOn(subject, 'spiedFunc');
}).toThrowError(/has already been spied upon/);
});
it("overrides the method on the object and returns the spy", function() {
var originalFunctionWasCalled = false,
spyRegistry = new j$.SpyRegistry(),
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
expect(subject.spiedFunc).toEqual(spy);
});
});
describe("#clearSpies", function() {
it("restores the original functions on the spied-upon objects", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subject = { spiedFunc: originalFunction };
spyRegistry.spyOn(subject, 'spiedFunc');
spyRegistry.clearSpies();
expect(subject.spiedFunc).toBe(originalFunction);
});
});
});
+98 -10
View File
@@ -52,6 +52,31 @@ describe("Suite", function() {
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
});
it("runs beforeAll functions in order of needed execution", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
suite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunner
}),
firstBefore = jasmine.createSpy('outerBeforeAll'),
lastBefore = jasmine.createSpy('insideBeforeAll'),
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
suite.beforeAll(firstBefore);
suite.beforeAll(lastBefore);
suite.addChild(fakeIt);
suite.execute();
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
suiteFns[0]();
expect(firstBefore).toHaveBeenCalled();
suiteFns[1]();
expect(lastBefore).toHaveBeenCalled();
});
it("adds after functions in order of needed execution", function() {
var env = new j$.Env(),
suite = new j$.Suite({
@@ -67,6 +92,31 @@ describe("Suite", function() {
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
});
it("runs afterAll functions in order of needed execution", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
suite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunner
}),
firstAfter = jasmine.createSpy('outerAfterAll'),
lastAfter = jasmine.createSpy('insideAfterAll'),
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
suite.afterAll(firstAfter);
suite.afterAll(lastAfter);
suite.addChild(fakeIt);
suite.execute();
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
suiteFns[1]();
expect(firstAfter).toHaveBeenCalled();
suiteFns[2]();
expect(lastAfter).toHaveBeenCalled();
});
it("can be disabled, but still calls callbacks", function() {
var env = new j$.Env(),
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
@@ -93,7 +143,7 @@ describe("Suite", function() {
expect(onComplete).toHaveBeenCalled();
});
it("delegates execution of its specs and suites", function() {
it("delegates execution of its specs, suites, beforeAlls, and afterAlls", function() {
var env = new j$.Env(),
parentSuiteDone = jasmine.createSpy('parent suite done'),
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
@@ -109,22 +159,57 @@ describe("Suite", function() {
queueRunner: fakeQueueRunner
}),
fakeSpec1 = {
execute: jasmine.createSpy('fakeSpec1')
};
execute: jasmine.createSpy('fakeSpec1'),
isExecutable: function() { return true; }
},
beforeAllFn = { fn: jasmine.createSpy('beforeAll') },
afterAllFn = { fn: jasmine.createSpy('afterAll') };
spyOn(suite, "execute");
parentSuite.addChild(fakeSpec1);
parentSuite.addChild(suite);
parentSuite.beforeAll(beforeAllFn);
parentSuite.afterAll(afterAllFn);
parentSuite.execute(parentSuiteDone);
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].fns;
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].queueableFns;
parentSuiteFns[0]();
parentSuiteFns[0].fn();
expect(beforeAllFn.fn).toHaveBeenCalled();
parentSuiteFns[1].fn();
expect(fakeSpec1.execute).toHaveBeenCalled();
parentSuiteFns[1]();
parentSuiteFns[2].fn();
expect(suite.execute).toHaveBeenCalled();
parentSuiteFns[3].fn();
expect(afterAllFn.fn).toHaveBeenCalled();
});
it("does not run beforeAll or afterAll if there are no child specs to run", function() {
var env = new j$.Env(),
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
fakeQueueRunnerForChild = jasmine.createSpy('fake child queue runner'),
parentSuite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunnerForParent
}),
childSuite = new j$.Suite({
env: env,
description: "I am a suite",
queueRunner: fakeQueueRunnerForChild,
parentSuite: parentSuite
}),
beforeAllFn = jasmine.createSpy('beforeAll'),
afterAllFn = jasmine.createSpy('afterAll');
parentSuite.addChild(childSuite);
parentSuite.beforeAll(beforeAllFn);
parentSuite.afterAll(afterAllFn);
parentSuite.execute();
expect(fakeQueueRunnerForParent).toHaveBeenCalledWith(jasmine.objectContaining({queueableFns: []}));
});
it("calls a provided onStart callback when starting", function() {
@@ -138,7 +223,8 @@ describe("Suite", function() {
queueRunner: fakeQueueRunner
}),
fakeSpec1 = {
execute: jasmine.createSpy('fakeSpec1')
execute: jasmine.createSpy('fakeSpec1'),
isExecutable: function() { return true; }
};
suite.execute();
@@ -182,9 +268,10 @@ describe("Suite", function() {
expect(suiteResultsCallback).toHaveBeenCalledWith({
id: suite.id,
status: '',
status: 'finished',
description: "with a child suite",
fullName: "with a child suite"
fullName: "with a child suite",
failedExpectations: []
});
});
@@ -210,7 +297,8 @@ describe("Suite", function() {
id: suite.id,
status: 'disabled',
description: "with a child suite",
fullName: "with a child suite"
fullName: "with a child suite",
failedExpectations: []
});
});
});
+34 -32
View File
@@ -38,13 +38,13 @@ describe("Custom Matchers (Integration)", function() {
});
it("passes the spec if the custom matcher passes", function(done) {
env.addMatchers({
toBeReal: function() {
return { compare: function() { return { pass: true }; } };
}
});
env.it("spec using custom matcher", function() {
env.addMatchers({
toBeReal: function() {
return { compare: function() { return { pass: true }; } };
}
});
env.expect(true).toBeReal();
});
@@ -57,16 +57,16 @@ describe("Custom Matchers (Integration)", function() {
});
it("uses the negative compare function for a negative comparison, if provided", function(done) {
env.addMatchers({
toBeReal: function() {
return {
compare: function() { return { pass: true }; },
negativeCompare: function() { return { pass: true }; }
};
}
});
env.it("spec with custom negative comparison matcher", function() {
env.addMatchers({
toBeReal: function() {
return {
compare: function() { return { pass: true }; },
negativeCompare: function() { return { pass: true }; }
};
}
});
env.expect(true).not.toBeReal();
});
@@ -79,17 +79,17 @@ describe("Custom Matchers (Integration)", function() {
});
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
env.addMatchers({
toBeReal: function() {
return {
compare: function() {
return { pass: false };
env.it('spec with an expectation', function() {
env.addMatchers({
toBeReal: function() {
return {
compare: function() {
return { pass: false };
}
}
}
}
});
});
env.it('spec with an expectation', function() {
env.expect("a").toBeReal();
});
@@ -103,13 +103,14 @@ describe("Custom Matchers (Integration)", function() {
it("passes the expected and actual arguments to the comparison function", function(done) {
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
env.addMatchers({
toBeReal: function() {
return { compare: argumentSpy };
}
});
env.it('spec with an expectation', function () {
env.addMatchers({
toBeReal: function() {
return { compare: argumentSpy };
}
});
env.expect(true).toBeReal();
env.expect(true).toBeReal("arg");
env.expect(true).toBeReal("arg1", "arg2");
@@ -130,12 +131,13 @@ describe("Custom Matchers (Integration)", function() {
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
customEqualityFn = function() { return true; };
env.addCustomEqualityTester(customEqualityFn);
env.addMatchers({
toBeReal: argumentSpy
});
env.it("spec with expectation", function() {
env.addCustomEqualityTester(customEqualityFn);
env.addMatchers({
toBeReal: argumentSpy
});
env.expect(true).toBeReal();
});
+751 -39
View File
@@ -1,4 +1,44 @@
describe("Env integration", function() {
beforeEach(function() {
jasmine.addMatchers({
toHaveFailedExpecationsForSuite: function(util, customeEqualityTesters) {
return {
compare: function(actual, suiteName, expectedFailures) {
var foundSuite = false, expectations = true, foundFailures = [];
for (var i = 0; i < actual.calls.count(); i++) {
var args = actual.calls.argsFor(i)[0];
if (args.description === suiteName) {
foundSuite = true;
for (var j = 0; j < args.failedExpectations.length; j++) {
foundFailures.push(args.failedExpectations[j].message);
}
for (var j = 0; j < expectedFailures.length; j++) {
var failure = foundFailures[j];
var expectedFailure = expectedFailures[j];
if (Object.prototype.toString.call(expectedFailure) === '[object RegExp]') {
expectations = expectations && expectedFailure.test(failure);
} else {
expectations = expectations && failure === expectedFailure;
}
}
break;
}
}
return {
pass: foundSuite && expectations,
message: !foundSuite ? 'The suite "' + suiteName + '" never finished' :
'Expected suite "' + suiteName + '" to have failures ' + jasmine.pp(expectedFailures) + ' but it had ' + jasmine.pp(foundFailures)
};
}
};
}
});
});
it("Suites execute as expected (no nesting)", function(done) {
var env = new j$.Env(),
@@ -80,7 +120,7 @@ describe("Env integration", function() {
env.describe("Outer suite", function() {
env.it("an outer spec", function() {
calls.push('an outer spec')
calls.push('an outer spec');
});
env.describe("Inner suite", function() {
env.it("an inner spec", function() {
@@ -212,6 +252,305 @@ describe("Env integration", function() {
env.execute();
});
it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
var env = new j$.Env(),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll');
env.addReporter({
jasmineDone: function() {
expect(after).toHaveBeenCalled();
expect(after.calls.count()).toBe(1);
expect(before.calls.count()).toBe(1);
done();
}
});
env.describe("with beforeAll and afterAll", function() {
env.it("spec", function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
});
env.it("another spec", function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
});
env.beforeAll(before);
env.afterAll(after);
});
env.execute();
});
it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
var env = new j$.Env(),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll');
env.addReporter({
jasmineDone: function() {
expect(after).toHaveBeenCalled();
expect(after.calls.count()).toBe(1);
expect(before.calls.count()).toBe(1);
done();
}
});
env.describe("with beforeAll and afterAll", function() {
env.it("spec", function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
});
env.it("another spec", function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
});
env.beforeAll(function(beforeCallbackUnderTest) {
before();
beforeCallbackUnderTest();
});
env.afterAll(function(afterCallbackUnderTest) {
after();
afterCallbackUnderTest();
});
});
env.execute();
});
it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
var env = new j$.Env();
env.addReporter({jasmineDone: done});
env.describe("with beforeAll and afterAll", function() {
env.beforeAll(function() {
this.x = 1;
});
env.it("has an x at the root", function() {
expect(this.x).toBe(1);
});
env.describe("child that deletes", function() {
env.beforeAll(function() {
expect(this.x).toBe(1);
delete this.x;
});
env.it("has no x", function() {
expect(this.x).not.toBeDefined();
});
});
env.describe("child should still have x", function() {
env.beforeAll(function(innerDone) {
expect(this.x).toBe(1);
innerDone();
});
env.it("has an x", function() {
expect(this.x).toBe(1);
delete this.x;
});
env.it("still has an x", function() {
expect(this.x).toBe(1);
});
env.it("adds a y", function() {
this.y = 2;
expect(this.y).toBe(2);
});
env.it("doesn't have y that was added in sibling", function() {
expect(this.y).not.toBeDefined();
});
});
});
env.execute();
});
it("fails all underlying specs when the beforeAll fails", function (done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone.calls.count()).toEqual(2);
expect(reporter.specDone.calls.argsFor(0)[0])
.toEqual(jasmine.objectContaining({status: 'failed'}));
expect(reporter.specDone.calls.argsFor(0)[0].failedExpectations[0].message)
.toEqual("Expected 1 to be 2.");
expect(reporter.specDone.calls.argsFor(1)[0])
.toEqual(jasmine.objectContaining({status: 'failed'}));
expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
.toEqual("Expected 1 to be 2.");
done();
});
env.addReporter(reporter);
env.describe('A suite', function(){
env.beforeAll(function() {
env.expect(1).toBe(2);
});
env.it("spec that will be failed", function() {
});
env.describe("nesting", function() {
env.it("another spec to fail", function() {
});
});
});
env.execute();
});
describe('suiteDone reporting', function(){
it("reports when an afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
});
it("if there are no specs, it still reports correctly", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
});
it("reports when afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function() {
throw error;
});
});
env.execute();
});
it("reports when an async afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
'Expected 1 to equal 2.'
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function(afterAllDone) {
env.expect(1).toEqual(2);
afterAllDone();
});
});
env.execute();
});
it("reports when an async afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: After All Exception/)
]);
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function(afterAllDone) {
throw error;
});
});
env.execute();
});
});
it("Allows specifying which specs and suites to run", function(done) {
var env = new j$.Env(),
calls = [],
@@ -248,21 +587,61 @@ describe("Env integration", function() {
env.execute([secondSuite.id, firstSpec.id]);
});
it("Functions can be spied on and have their calls tracked", function () {
var env = new j$.Env();
it('runs before and after all functions for runnables provided to .execute()', function(done) {
var env = new j$.Env(),
calls = [],
first_spec,
second_spec;
var originalFunctionWasCalled = false;
var subject = {
spiedFunc: function() {
originalFunctionWasCalled = true;
return "original result";
}
};
var assertions = function() {
expect(calls).toEqual([
"before",
"first spec",
"after",
"before",
"second spec",
"after"
]);
done();
};
env.addReporter({jasmineDone: assertions});
env.describe("first suite", function() {
env.beforeAll(function() {
calls.push("before");
});
env.afterAll(function() {
calls.push("after")
});
first_spec = env.it("spec", function() {
calls.push('first spec');
});
second_spec = env.it("spec 2", function() {
calls.push("second spec");
});
});
env.execute([first_spec.id, second_spec.id]);
});
it("Functions can be spied on and have their calls tracked", function (done) {
var env = new j$.Env();
var originalFunctionWasCalled = false;
var subject = {
spiedFunc: function() {
originalFunctionWasCalled = true;
return "original result";
}
};
env.addReporter({jasmineDone: done});
env.it("works with spies", function() {
var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
expect(subject.spiedFunc).toEqual(spy);
expect(subject.spiedFunc.calls.any()).toEqual(false);
expect(subject.spiedFunc.calls.count()).toEqual(0);
@@ -281,6 +660,67 @@ describe("Env integration", function() {
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
expect(originalFunctionWasCalled).toEqual(true);
});
env.execute();
});
it('removes all spies added in a spec after the spec is complete', function(done) {
var env = new j$.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
var assertions = function() {
expect(firstSpec).toHaveBeenCalled();
expect(secondSpec).toHaveBeenCalled();
done();
};
env.addReporter({ jasmineDone: assertions });
env.execute();
});
it('removes all spies added in a suite after the suite is complete', function(done) {
var env = new j$.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
};
env.describe('test suite', function() {
env.beforeAll(function() { env.spyOn(testObj, 'foo');})
env.it('spec 0', function() {
expect(j$.isSpy(testObj.foo)).toBe(true);
});
env.it('spec 1', function() {
expect(j$.isSpy(testObj.foo)).toBe(true);
});
});
env.describe('another suite', function() {
env.it('spec 2', function() {
expect(j$.isSpy(testObj.foo)).toBe(false);
});
});
env.addReporter({ jasmineDone: done });
env.execute();
});
it("Mock clock can be installed and used in tests", function(done) {
@@ -345,11 +785,11 @@ describe("Env integration", function() {
beforeEach(function() {
originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
jasmine.getEnv().clock.install();
jasmine.clock().install();
});
afterEach(function() {
jasmine.getEnv().clock.uninstall();
jasmine.clock().uninstall();
j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
@@ -371,7 +811,63 @@ describe("Env integration", function() {
env.it("async spec that doesn't call done", function(underTestCallback) {
env.expect(true).toBeTruthy();
jasmine.getEnv().clock.tick(8416);
jasmine.clock().tick(8416);
});
env.execute();
});
it("should wait a specified interval before failing beforeAll's and their associated specs that haven't called done", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone.calls.count()).toEqual(2);
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
done();
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 1290;
env.beforeAll(function(done) {
jasmine.clock().tick(1290);
});
env.it("spec that will be failed", function() {
});
env.describe("nesting", function() {
env.it("another spec to fail", function() {
});
});
env.execute();
});
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
]);
done();
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 3000;
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.afterAll(function(innerDone) {
jasmine.clock().tick(3001);
innerDone();
});
});
env.execute();
@@ -436,7 +932,58 @@ describe("Env integration", function() {
});
});
// TODO: something is wrong with this spec
describe('focused tests', function() {
it('should only run the focused tests', function(done) {
var env = new j$.Env(),
calls = [];
var assertions = function() {
expect(calls).toEqual(['focused']);
done();
};
env.addReporter({jasmineDone: assertions});
env.describe('a suite', function() {
env.fit('is focused', function() {
calls.push('focused');
});
env.it('is not focused', function() {
calls.push('freakout');
})
});
env.execute();
});
it('should only run focused suites', function(){
var env = new j$.Env(),
calls = [];
var assertions = function() {
expect(calls).toEqual(['focused']);
done();
};
env.addReporter({jasmineDone: assertions});
env.fdescribe('a focused suite', function() {
env.it('is focused', function() {
calls.push('focused');
});
});
env.describe('a regular suite', function() {
env.it('is not focused', function() {
calls.push('freakout');
})
});
env.execute();
});
});
it("should report as expected", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
@@ -502,11 +1049,7 @@ describe("Env integration", function() {
it("Custom equality testers should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);
@@ -536,30 +1079,42 @@ describe("Env integration", function() {
env.execute();
});
it("Custom matchers should be per spec", function() {
it("Custom equality testers should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
matchers = {
toFoo: function() {}
},
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);
reporter.jasmineDone.and.callFake(function() {
var firstSpecResult = reporter.specDone.calls.first().args[0],
secondSpecResult = reporter.specDone.calls.argsFor(0)[0],
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
expect(firstSpecResult.status).toEqual("passed");
expect(secondSpecResult.status).toEqual("passed");
expect(thirdSpecResult.status).toEqual("failed");
done();
});
env.addReporter(reporter);
env.describe("testing custom matchers", function() {
env.it("with a custom matcher", function() {
env.addMatchers(matchers);
expect(env.expect().toFoo).toBeDefined();
env.describe("testing custom equality testers", function() {
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; }); });
env.it("with a custom tester", function() {
env.expect("a").toEqual("b");
});
env.it("without a custom matcher", function() {
expect(env.expect().toFoo).toBeUndefined();
env.it("with the same custom tester", function() {
env.expect("a").toEqual("b");
});
});
env.describe("another suite", function() {
env.it("without the custom tester", function(){
env.expect("a").toEqual("b");
});
});
@@ -569,11 +1124,7 @@ describe("Env integration", function() {
it("Custom equality testers for toContain should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
"suiteStarted",
"suiteDone",
"specStarted",
"specDone"
]);
@@ -596,7 +1147,7 @@ describe("Env integration", function() {
});
env.it("without a custom tester", function() {
env.expect("a").toContain("b");
env.expect(["a"]).toContain("b");
});
});
@@ -616,5 +1167,166 @@ describe("Env integration", function() {
env.execute();
});
});
it("Custom equality testers for toContain should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone",
"specDone"
]);
reporter.jasmineDone.and.callFake(function() {
var firstSpecResult = reporter.specDone.calls.first().args[0],
secondSpecResult = reporter.specDone.calls.argsFor(1)[0],
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
expect(firstSpecResult.status).toEqual("passed");
expect(secondSpecResult.status).toEqual("passed");
expect(thirdSpecResult.status).toEqual("failed");
done();
});
env.addReporter(reporter);
env.describe("testing custom equality testers", function() {
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; })});
env.it("with a custom tester", function() {
env.expect(["a"]).toContain("b");
});
env.it("also with the custom tester", function() {
env.expect(["a"]).toContain("b");
});
});
env.describe("another suite", function() {
env.it("without the custom tester", function() {
env.expect(["a"]).toContain("b");
});
});
env.execute();
});
it("Custom matchers should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
matchers = {
toFoo: function() {}
};
env.describe("testing custom matchers", function() {
env.it("with a custom matcher", function() {
env.addMatchers(matchers);
expect(env.expect().toFoo).toBeDefined();
});
env.it("without a custom matcher", function() {
expect(env.expect().toFoo).toBeUndefined();
});
});
env.addReporter({jasmineDone: done});
env.execute();
});
it("Custom matchers should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
matchers = {
toFoo: function() {}
};
env.describe("testing custom matchers", function() {
env.beforeAll(function() { env.addMatchers(matchers); });
env.it("with a custom matcher", function() {
expect(env.expect().toFoo).toBeDefined();
});
env.it("with the same custom matcher", function() {
expect(env.expect().toFoo).toBeDefined();
});
});
env.describe("another suite", function() {
env.it("no longer has the custom matcher", function() {
expect(env.expect().toFoo).not.toBeDefined();
});
});
env.addReporter({jasmineDone: done});
env.execute();
});
it('throws an exception if you try to create a spy outside of a runnable', function (done) {
var env = new j$.Env(),
obj = {fn: function () {}},
exception;
env.describe("a suite", function () {
try {
env.spyOn(obj, 'fn');
} catch(e) {
exception = e;
}
});
var assertions = function() {
expect(exception.message).toBe('Spies must be created in a before function or a spec');
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
var env = new j$.Env(),
obj = {fn: function () {}},
exception;
env.describe("a suite", function () {
try {
env.addMatchers({myMatcher: function(actual,expected){return false;}});
} catch(e) {
exception = e;
}
});
var assertions = function() {
expect(exception.message).toBe('Matchers must be added in a before function or a spec');
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
var env = new j$.Env(),
obj = {fn: function () {}},
exception;
env.describe("a suite", function () {
try {
env.addCustomEqualityTester(function(first, second) {return true;});
} catch(e) {
exception = e;
}
});
var assertions = function() {
expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
+279 -3
View File
@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
];
expect(actions).toEqual(expected);
done();
}
};
env.addReporter({jasmineDone: assertions});
@@ -228,6 +228,257 @@ describe("jasmine spec running", function () {
env.execute();
});
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function() {
var actions = [];
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
env.it('does something or other', function() {
actions.push('it');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function() {
var actions = [],
spec,
spec2;
env.beforeAll(function() {
actions.push('runner beforeAll');
});
env.afterAll(function() {
actions.push('runner afterAll');
});
env.beforeEach(function () {
actions.push('runner beforeEach');
});
env.afterEach(function () {
actions.push('runner afterEach');
});
env.describe('Something', function() {
env.beforeEach(function() {
actions.push('inner beforeEach');
});
env.afterEach(function() {
actions.push('inner afterEach');
});
env.beforeAll(function() {
actions.push('inner beforeAll');
});
env.afterAll(function() {
actions.push('inner afterAll');
});
spec = env.it('does something', function() {
actions.push('it');
});
spec2 = env.it('does something or other', function() {
actions.push('it2');
});
});
var assertions = function() {
var expected = [
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll",
"runner beforeAll",
"inner beforeAll",
"runner beforeEach",
"inner beforeEach",
"it2",
"inner afterEach",
"runner afterEach",
"inner afterAll",
"runner afterAll"
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute([spec.id, spec2.id]);
});
describe('focused runnables', function() {
it('runs the relevant alls and eachs for each runnable', function(done) {
var actions = [];
env.beforeAll(function() {actions.push('beforeAll')});
env.afterAll(function() {actions.push('afterAll')});
env.beforeEach(function() {actions.push('beforeEach')});
env.afterEach(function() {actions.push('afterEach')});
env.fdescribe('a focused suite', function() {
env.it('is run', function() {
actions.push('spec in fdescribe')
});
});
env.describe('an unfocused suite', function() {
env.fit('has a focused spec', function() {
actions.push('focused spec')
});
});
var assertions = function() {
var expected = [
'beforeAll',
'beforeEach',
'spec in fdescribe',
'afterEach',
'afterAll',
'beforeAll',
'beforeEach',
'focused spec',
'afterEach',
'afterAll'
];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused specs in focused suites cause non-focused siblings to not run', function(done){
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.fit('focused spec', function() {
actions.push('focused spec')
});
});
var assertions = function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused suites in focused suites cause non-focused siblings to not run', function(done){
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.fdescribe('inner focused suite', function() {
env.it('inner spec', function() {
actions.push('inner spec');
});
});
});
var assertions = function() {
var expected = ['inner spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it('focused runnables unfocus ancestor focused suites', function() {
var actions = [];
env.fdescribe('focused suite', function() {
env.it('unfocused spec', function() {
actions.push('unfocused spec')
});
env.describe('inner focused suite', function() {
env.fit('focused spec', function() {
actions.push('focused spec');
});
});
});
var assertions = function() {
var expected = ['focused spec'];
expect(actions).toEqual(expected);
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
});
it("shouldn't run disabled suites", function(done) {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
suite = env.describe('A Suite', function() {
@@ -236,10 +487,36 @@ describe("jasmine spec running", function () {
});
});
suite.execute(function() {
var assertions = function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it("should allow top level suites to be disabled", function() {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
otherSpec = jasmine.createSpy("otherSpec");
env.xdescribe('A disabled suite', function() {
env.it('spec inside a disabled suite', specInADisabledSuite);
});
env.describe('Another suite', function() {
env.it('another spec', otherSpec);
});
var assertions = function() {
expect(specInADisabledSuite).not.toHaveBeenCalled();
expect(otherSpec).toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it("should set all pending specs to pending when a suite is run", function(done) {
@@ -254,7 +531,6 @@ describe("jasmine spec running", function () {
});
});
// TODO: is this useful? It doesn't catch syntax errors
xit("should recover gracefully when there are errors in describe functions", function() {
var specs = [];