Reorganizing spy matcher specs.

This commit is contained in:
Christian Williams 2009-11-13 12:30:22 -05:00
parent 752b91f118
commit b0326d3078
1 changed files with 81 additions and 82 deletions

View File

@ -471,7 +471,7 @@ describe("jasmine.Matchers", function() {
}); });
describe("spy matchers (wasCalled, wasNotCalled, wasCalledWith)", function() { describe("spy matchers È", function() {
var TestClass; var TestClass;
beforeEach(function() { beforeEach(function() {
TestClass = { TestClass = {
@ -481,30 +481,25 @@ describe("jasmine.Matchers", function() {
}; };
}); });
it("should throw an exception when wasCalled and wasNotCalled are invoked with the wrong number of arguments", function() { describe("wasCalled", function() {
it("should pass iff the spy was called", function() {
expect(match(TestClass.spyFunction).wasCalled()).toEqual(false);
TestClass.spyFunction();
expect(match(TestClass.spyFunction).wasCalled()).toEqual(true);
});
it("should throw an exception when invoked with any arguments", function() {
expect(function() { expect(function() {
match(TestClass.normalFunction).wasCalled("unwanted argument"); match(TestClass.normalFunction).wasCalled("unwanted argument");
}).toThrow('wasCalled does not take arguments, use wasCalledWith'); }).toThrow('wasCalled does not take arguments, use wasCalledWith');
expect(function() {
match(TestClass.normalFunction).wasNotCalled("unwanted argument");
}).toThrow('wasNotCalled does not take arguments');
}); });
describe('with non-spies', function() { it('should throw an exception when invoked on a non-spy', function () {
it('should always show an error', function () {
expect(function() { expect(function() {
match(TestClass.normalFunction).wasCalled(); match(TestClass.normalFunction).wasCalled();
}).toThrow('Expected a spy, but got Function.'); }).toThrow('Expected a spy, but got Function.');
expect(function() {
match(TestClass.normalFunction).wasNotCalled();
}).toThrow('Expected a spy, but got Function.');
expect(function() {
match(TestClass.normalFunction).wasCalledWith();
}).toThrow('Expected a spy, but got Function.');
expect(function() { expect(function() {
match(undefined).wasCalled(); match(undefined).wasCalled();
}).toThrow('Expected a spy, but got undefined.'); }).toThrow('Expected a spy, but got undefined.');
@ -515,17 +510,6 @@ describe("jasmine.Matchers", function() {
}); });
}); });
describe('with spies', function () {
describe("wasCalled", function() {
it("should pass iff the spy was called", function() {
expect(match(TestClass.spyFunction).wasCalled()).toEqual(false);
TestClass.spyFunction();
expect(match(TestClass.spyFunction).wasCalled()).toEqual(true);
});
});
describe("wasNotCalled", function() { describe("wasNotCalled", function() {
it("should pass iff the spy was not called", function() { it("should pass iff the spy was not called", function() {
expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true); expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true);
@ -534,6 +518,17 @@ describe("jasmine.Matchers", function() {
expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(false); expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(false);
}); });
it("should throw an exception when invoked with any arguments", function() {
expect(function() {
match(TestClass.normalFunction).wasNotCalled("unwanted argument");
}).toThrow('wasNotCalled does not take arguments');
});
it('should throw an exception when invoked on a non-spy', function () {
expect(function() {
match(TestClass.normalFunction).wasNotCalled();
}).toThrow('Expected a spy, but got Function.');
});
}); });
describe("wasCalledWith", function() { describe("wasCalledWith", function() {
@ -560,12 +555,14 @@ describe("jasmine.Matchers", function() {
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true); expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
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 () {
expect(function() {
match(TestClass.normalFunction).wasCalledWith();
}).toThrow('Expected a spy, but got Function.');
}); });
describe("wasCalledWith to build an ExpectationResult", function () { describe("to build an ExpectationResult", function () {
var TestClass;
beforeEach(function() { beforeEach(function() {
var currentSuite; var currentSuite;
var spec; var spec;
@ -592,3 +589,5 @@ describe("jasmine.Matchers", function() {
}); });
}); });
}); });
});
});