Reorganizing spy matcher specs.

This commit is contained in:
Christian Williams 2009-11-13 12:30:22 -05:00
parent 752b91f118
commit b0326d3078

View File

@ -471,7 +471,7 @@ describe("jasmine.Matchers", function() {
});
describe("spy matchers (wasCalled, wasNotCalled, wasCalledWith)", function() {
describe("spy matchers È", function() {
var TestClass;
beforeEach(function() {
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() {
match(TestClass.normalFunction).wasCalled("unwanted argument");
}).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 always show an error', function () {
it('should throw an exception when invoked on a non-spy', function () {
expect(function() {
match(TestClass.normalFunction).wasCalled();
}).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() {
match(undefined).wasCalled();
}).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() {
it("should pass iff the spy was not called", function() {
expect(match(TestClass.spyFunction).wasNotCalled()).toEqual(true);
@ -534,6 +518,17 @@ describe("jasmine.Matchers", function() {
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() {
@ -560,12 +555,14 @@ describe("jasmine.Matchers", function() {
expect(expected.wasCalledWith('d', 'e', 'f')).toEqual(true);
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 () {
var TestClass;
describe("to build an ExpectationResult", function () {
beforeEach(function() {
var currentSuite;
var spec;
@ -592,3 +589,5 @@ describe("jasmine.Matchers", function() {
});
});
});
});
});