diff --git a/docs/release-source/release/spies.md b/docs/release-source/release/spies.md index 49a41d978..62e985d87 100644 --- a/docs/release-source/release/spies.md +++ b/docs/release-source/release/spies.md @@ -390,7 +390,7 @@ Array of return values, `spy.returnValues[0]` is the return value of the first c If the call did not explicitly return a value, the value at the call's location in `.returnValues` will be `undefined`. -#### `spy.reset()` +#### `spy.resetHistory()` Resets the state of a spy. diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index f2105c0cd..89281afa6 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -2,6 +2,7 @@ var createBehavior = require("./behavior").create; var extend = require("./util/core/extend"); +var deprecated = require("./util/core/deprecated"); var functionName = require("./util/core/function-name"); var functionToString = require("./util/core/function-to-string"); var getPropertyDescriptor = require("./util/core/get-property-descriptor"); @@ -100,7 +101,7 @@ var uuid = 0; var spyApi = { formatters: require("./spy-formatters"), - reset: function () { + resetHistory: function () { if (this.invoking) { var err = new Error("Cannot reset Sinon function while invoking it. " + "Move the call to .reset outside of the callback."); @@ -156,7 +157,7 @@ var spyApi = { delete proxy.create; extend(proxy, func); - proxy.reset(); + proxy.resetHistory(); proxy.prototype = func.prototype; proxy.displayName = name || "spy"; proxy.toString = functionToString; @@ -413,6 +414,8 @@ function delegateToCalls(method, matchAny, actual, notCalled) { }; } +spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg("reset")); + delegateToCalls("calledOn", true); delegateToCalls("alwaysCalledOn", false, "calledOn"); delegateToCalls("calledWith", true); diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index a21544d83..c7c5e2614 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -132,7 +132,7 @@ var proto = { }); }, - resetHistory: spy.reset, + resetHistory: spy.resetHistory, reset: function () { this.resetHistory(); diff --git a/test/call-test.js b/test/call-test.js index d2462db41..f720de7bd 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -971,7 +971,7 @@ describe("sinonSpy.call", function () { var spy = sinonSpy(); spy(); - spy.reset(); + spy.resetHistory(); assertReset(spy); }); @@ -981,7 +981,7 @@ describe("sinonSpy.call", function () { spies[0](); spies[1](); - spies[0].reset(); + spies[0].resetHistory(); assert(!spies[0].calledBefore(spies[1])); }); @@ -995,7 +995,7 @@ describe("sinonSpy.call", function () { spy("c"); var fakeC = spy.withArgs("c"); - spy.reset(); + spy.resetHistory(); assertReset(fakeA); assertReset(fakeB); @@ -1288,7 +1288,7 @@ describe("sinonSpy.call", function () { "\n\n spy(" + str + ")" + "\n\n spy(" + str + ")"); - spy.reset(); + spy.resetHistory(); spy("test"); spy("spy\ntest"); @@ -1306,7 +1306,7 @@ describe("sinonSpy.call", function () { spy(); assert.equals(spy.printf("%t"), "undefined"); - spy.reset(); + spy.resetHistory(); spy.call(true); assert.equals(spy.printf("%t"), "true"); }); diff --git a/test/spy-test.js b/test/spy-test.js index dc68d6d7f..132032483 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -2538,17 +2538,17 @@ describe("spy", function () { }); }); - describe(".reset", function () { + describe(".resetHistory", function () { it("return same object", function () { var spy = createSpy(); - var reset = spy.reset(); + var reset = spy.resetHistory(); assert(reset === spy); }); it("throws if called during spy invocation", function () { var spy = createSpy(function () { - spy.reset(); + spy.resetHistory(); }); assert.exception(spy, "InvalidResetException"); diff --git a/test/stub-test.js b/test/stub-test.js index 5b225e9ee..c8962a2fe 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -607,7 +607,7 @@ describe("stub", function () { this.originalError = global.Error; errorSpy = createSpy(global, "Error"); // errorSpy starts with a call already made, not sure why - errorSpy.reset(); + errorSpy.resetHistory(); }); afterEach(function () { diff --git a/test/util/core/every-test.js b/test/util/core/every-test.js index 0a084a054..549ef64f8 100644 --- a/test/util/core/every-test.js +++ b/test/util/core/every-test.js @@ -34,7 +34,7 @@ describe("util/core/every", function () { every(iterableOne, callback); assert.equals(callback.callCount, 4); - callback.reset(); + callback.resetHistory(); every(iterableTwo, callback); assert.equals(callback.callCount, 3);