Reuse an 'it' block.

This commit is contained in:
Christian Williams 2009-11-13 12:40:04 -05:00
parent b0326d3078
commit 60ea562560

View File

@ -471,7 +471,7 @@ describe("jasmine.Matchers", function() {
}); });
describe("spy matchers È", function() { describe("spy matchers >>", function() {
var TestClass; var TestClass;
beforeEach(function() { beforeEach(function() {
TestClass = { TestClass = {
@ -481,6 +481,22 @@ describe("jasmine.Matchers", function() {
}; };
}); });
function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
return function() {
expect(function() {
match(TestClass.normalFunction)[methodName]();
}).toThrow('Expected a spy, but got Function.');
expect(function() {
match(undefined)[methodName]();
}).toThrow('Expected a spy, but got undefined.');
expect(function() {
match({some:'object'})[methodName]();
}).toThrow('Expected a spy, but got { some : \'object\' }.');
};
}
describe("wasCalled", function() { describe("wasCalled", function() {
it("should pass iff the spy was called", function() { it("should pass iff the spy was called", function() {
expect(match(TestClass.spyFunction).wasCalled()).toEqual(false); expect(match(TestClass.spyFunction).wasCalled()).toEqual(false);
@ -495,19 +511,7 @@ describe("jasmine.Matchers", function() {
}).toThrow('wasCalled does not take arguments, use wasCalledWith'); }).toThrow('wasCalled does not take arguments, use wasCalledWith');
}); });
it('should throw an exception when invoked on a non-spy', function () { it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalled'));
expect(function() {
match(TestClass.normalFunction).wasCalled();
}).toThrow('Expected a spy, but got Function.');
expect(function() {
match(undefined).wasCalled();
}).toThrow('Expected a spy, but got undefined.');
expect(function() {
match({some:'object'}).wasCalled();
}).toThrow('Expected a spy, but got { some : \'object\' }.');
});
}); });
describe("wasNotCalled", function() { describe("wasNotCalled", function() {
@ -524,11 +528,7 @@ describe("jasmine.Matchers", function() {
}).toThrow('wasNotCalled does not take arguments'); }).toThrow('wasNotCalled does not take arguments');
}); });
it('should throw an exception when invoked on a non-spy', function () { it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
expect(function() {
match(TestClass.normalFunction).wasNotCalled();
}).toThrow('Expected a spy, but got Function.');
});
}); });
describe("wasCalledWith", function() { describe("wasCalledWith", function() {
@ -556,11 +556,7 @@ describe("jasmine.Matchers", function() {
expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false); expect(expected.wasCalledWith('x', 'y', 'z')).toEqual(false);
}); });
it('should throw an exception when invoked on a non-spy', function () { it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasCalledWith'));
expect(function() {
match(TestClass.normalFunction).wasCalledWith();
}).toThrow('Expected a spy, but got Function.');
});
describe("to build an ExpectationResult", function () { describe("to build an ExpectationResult", function () {
beforeEach(function() { beforeEach(function() {