diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 5b5bb84ba..45c43d30f 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -386,7 +386,7 @@ var spyApi = { } }; -function delegateToCalls(method, matchAny, actual, notCalled) { +function delegateToCalls(method, matchAny, actual, notCalled, totalCallCount) { spyApi[method] = function () { if (!this.called) { if (notCalled) { @@ -395,6 +395,12 @@ function delegateToCalls(method, matchAny, actual, notCalled) { return false; } + if (totalCallCount !== undefined) { + if (this.callCount !== totalCallCount) { + return false; + } + } + var currentCall; var matches = 0; @@ -423,6 +429,7 @@ delegateToCalls("calledWithMatch", true); delegateToCalls("alwaysCalledWith", false, "calledWith"); delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); delegateToCalls("calledWithExactly", true); +delegateToCalls("calledOnceWithExactly", true, "calledWithExactly", undefined, 1); delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); delegateToCalls("neverCalledWith", false, "notCalledWith", function () { return true; diff --git a/test/spy-test.js b/test/spy-test.js index 132032483..059400364 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -1181,6 +1181,38 @@ describe("spy", function () { }); }); + describe(".calledOnceWithExactly", function () { + beforeEach(function () { + this.spy = createSpy.create(); + }); + + it("returns true for exact match", function () { + this.spy(1, 2, 3); + + assert.isTrue(this.spy.calledOnceWithExactly(1, 2, 3)); + }); + + it("returns false for exact parameters but called more then once", function () { + this.spy(1, 2, 3); + this.spy(1, 2, 3); + + assert.isFalse(this.spy.calledOnceWithExactly(1, 2, 3)); + }); + + it("return false for one mismatched call", function () { + this.spy(1, 2); + + assert.isFalse(this.spy.calledOnceWithExactly(1, 2, 3)); + }); + + it("return false for one mismatched call with some other ", function () { + this.spy(1, 2, 3); + this.spy(1, 2); + + assert.isFalse(this.spy.calledOnceWithExactly(1, 2, 3)); + }); + }); + describe(".alwaysCalledWithExactly", function () { beforeEach(function () { this.spy = createSpy.create();