Merge branch 'issue-931-respy' of https://github.com/guy-mograbi-at-gigaspaces/jasmine into guy-mograbi-at-gigaspaces-issue-931-respy
- Merges #953 - Fixes #931
This commit is contained in:
@@ -773,6 +773,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return runnableResources[currentRunnable().id].spies;
|
return runnableResources[currentRunnable().id].spies;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
this.allowRespy = function(allow){
|
||||||
|
spyRegistry.allowRespy(allow);
|
||||||
|
};
|
||||||
|
|
||||||
this.spyOn = function() {
|
this.spyOn = function() {
|
||||||
return spyRegistry.spyOn.apply(spyRegistry, arguments);
|
return spyRegistry.spyOn.apply(spyRegistry, arguments);
|
||||||
};
|
};
|
||||||
@@ -2006,6 +2010,10 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
|
this.allowRespy = function(allow){
|
||||||
|
this.respy = allow;
|
||||||
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
if (j$.util.isUndefined(obj)) {
|
if (j$.util.isUndefined(obj)) {
|
||||||
throw new Error('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 + '()');
|
||||||
@@ -2019,9 +2027,12 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
throw new Error(methodName + '() method does not exist');
|
throw new Error(methodName + '() method does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj[methodName] && j$.isSpy(obj[methodName])) {
|
if (obj[methodName] && j$.isSpy(obj[methodName]) ) {
|
||||||
//TODO?: should this return the current spy? Downside: may cause user confusion about spy state
|
if ( !!this.respy ){
|
||||||
throw new Error(methodName + ' has already been spied upon');
|
return obj[methodName];
|
||||||
|
}else {
|
||||||
|
throw new Error(methodName + ' has already been spied upon');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor;
|
var descriptor;
|
||||||
|
|||||||
@@ -677,6 +677,31 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be configured to allow respying on functions', function () {
|
||||||
|
var env = new jasmineUnderTest.Env(),
|
||||||
|
foo = {
|
||||||
|
bar: function () {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
env.allowRespy(true);
|
||||||
|
|
||||||
|
env.describe('test suite', function(){
|
||||||
|
env.it('spec 0', function(){
|
||||||
|
env.spyOn(foo,'bar');
|
||||||
|
|
||||||
|
var error = null;
|
||||||
|
|
||||||
|
expect(function() {
|
||||||
|
env.spyOn(foo, 'bar');
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
it('removes all spies added in a spec after the spec is complete', function(done) {
|
it('removes all spies added in a spec after the spec is complete', function(done) {
|
||||||
var env = new jasmineUnderTest.Env(),
|
var env = new jasmineUnderTest.Env(),
|
||||||
originalFoo = function() {},
|
originalFoo = function() {},
|
||||||
|
|||||||
@@ -269,6 +269,10 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
return runnableResources[currentRunnable().id].spies;
|
return runnableResources[currentRunnable().id].spies;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
this.allowRespy = function(allow){
|
||||||
|
spyRegistry.allowRespy(allow);
|
||||||
|
};
|
||||||
|
|
||||||
this.spyOn = function() {
|
this.spyOn = function() {
|
||||||
return spyRegistry.spyOn.apply(spyRegistry, arguments);
|
return spyRegistry.spyOn.apply(spyRegistry, arguments);
|
||||||
};
|
};
|
||||||
|
|||||||
+10
-3
@@ -4,6 +4,10 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var currentSpies = options.currentSpies || function() { return []; };
|
var currentSpies = options.currentSpies || function() { return []; };
|
||||||
|
|
||||||
|
this.allowRespy = function(allow){
|
||||||
|
this.respy = allow;
|
||||||
|
};
|
||||||
|
|
||||||
this.spyOn = function(obj, methodName) {
|
this.spyOn = function(obj, methodName) {
|
||||||
if (j$.util.isUndefined(obj)) {
|
if (j$.util.isUndefined(obj)) {
|
||||||
throw new Error('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 + '()');
|
||||||
@@ -17,9 +21,12 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
|
|||||||
throw new Error(methodName + '() method does not exist');
|
throw new Error(methodName + '() method does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj[methodName] && j$.isSpy(obj[methodName])) {
|
if (obj[methodName] && j$.isSpy(obj[methodName]) ) {
|
||||||
//TODO?: should this return the current spy? Downside: may cause user confusion about spy state
|
if ( !!this.respy ){
|
||||||
throw new Error(methodName + ' has already been spied upon');
|
return obj[methodName];
|
||||||
|
}else {
|
||||||
|
throw new Error(methodName + ' has already been spied upon');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var descriptor;
|
var descriptor;
|
||||||
|
|||||||
Reference in New Issue
Block a user