[Finishes #52959947] Warn user about spy conflicts; Refactor spy tests to more reflect responsibilities and removed duplicate tests

This commit is contained in:
Colin O'Byrne and JR Boyens
2013-07-22 16:24:20 -07:00
parent 30aec66ce5
commit 9609aba25f
4 changed files with 109 additions and 205 deletions

View File

@@ -211,16 +211,16 @@ getJasmineRequireObj().Env = function(j$) {
this.spyOn = function(obj, methodName) {
if (j$.util.isUndefined(obj)) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
throw new Error("spyOn could not find an object to spy upon for " + methodName + "()");
}
if (j$.util.isUndefined(obj[methodName])) {
throw methodName + '() method does not exist';
throw new Error(methodName + '() method does not exist');
}
if (obj[methodName] && j$.isSpy(obj[methodName])) {
//TODO?: should this return the current spy? Downside: may cause user confusion about spy state
throw methodName + ' has already been spied upon';
throw new Error(methodName + ' has already been spied upon');
}
var spy = j$.createSpy(methodName, obj[methodName]);

View File

@@ -65,13 +65,17 @@ getJasmineRequireObj().base = function(j$) {
return spyStrategy.exec.apply(this, arguments);
};
spy.and = spyStrategy;
spy.calls = callTracker;
for (var prop in originalFn) {
if (prop === 'and' || prop === 'calls') {
throw new Error("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
}
for (prop in originalFn) {
spy[prop] = originalFn[prop];
}
spy.and = spyStrategy;
spy.calls = callTracker;
return spy;
};