Skip to content

Commit

Permalink
Use deprecation helper and remove all references to 'reset'
Browse files Browse the repository at this point in the history
  • Loading branch information
GCHQDeveloper500 committed Dec 11, 2017
1 parent 8cd3bf4 commit e870a64
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
7 changes: 4 additions & 3 deletions lib/sinon/spy.js
Expand Up @@ -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");
Expand Down Expand Up @@ -32,7 +33,7 @@ function spy(object, property, types) {
return spy.create(function () { });
}

if (!types) {
if (!types) {
return wrapMethod(object, property, spy.create(object[property]));
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -413,7 +414,7 @@ function delegateToCalls(method, matchAny, actual, notCalled) {
};
}

spyApi.reset = spyApi.resetHistory;
spyApi.reset = deprecated.wrap(spyApi.resetHistory, deprecated.defaultMsg('reset'));

delegateToCalls("calledOn", true);
delegateToCalls("alwaysCalledOn", false, "calledOn");
Expand Down
2 changes: 1 addition & 1 deletion lib/sinon/stub.js
Expand Up @@ -132,7 +132,7 @@ var proto = {
});
},

resetHistory: spy.reset,
resetHistory: spy.resetHistory,

reset: function () {
this.resetHistory();
Expand Down
10 changes: 5 additions & 5 deletions test/call-test.js
Expand Up @@ -971,7 +971,7 @@ describe("sinonSpy.call", function () {
var spy = sinonSpy();
spy();

spy.reset();
spy.resetHistory();

assertReset(spy);
});
Expand All @@ -981,7 +981,7 @@ describe("sinonSpy.call", function () {
spies[0]();
spies[1]();

spies[0].reset();
spies[0].resetHistory();

assert(!spies[0].calledBefore(spies[1]));
});
Expand All @@ -995,7 +995,7 @@ describe("sinonSpy.call", function () {
spy("c");
var fakeC = spy.withArgs("c");

spy.reset();
spy.resetHistory();

assertReset(fakeA);
assertReset(fakeB);
Expand Down Expand Up @@ -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");
Expand All @@ -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");
});
Expand Down
8 changes: 0 additions & 8 deletions test/spy-test.js
Expand Up @@ -2538,14 +2538,6 @@ describe("spy", function () {
});
});

describe(".reset", function () {
it("is alias for resetHistory", function () {
var spy = createSpy();

assert.same(spy.reset, spy.resetHistory);
});
});

describe(".resetHistory", function () {
it("return same object", function () {
var spy = createSpy();
Expand Down
2 changes: 1 addition & 1 deletion test/stub-test.js
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion test/util/core/every-test.js
Expand Up @@ -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);
Expand Down

0 comments on commit e870a64

Please sign in to comment.