// Monkey-patch sinon.create to patch all created spyCall instances
// so that the top stack frame is a predictable string.
// Prevents every test from failing when the test suite is updated.
module.exports = function (sinon) {
    // Copied from test/monkeyPatchSinonStackFrames.js
    function patchCall(call) {
        var getStackFrames = call && call.getStackFrames;
        if (getStackFrames) {
            call.getStackFrames = function () {
                return ['at theFunction (theFileName:xx:yy)'];
            };
        }
        return call;
    }

    ['spy', 'stub'].forEach(function (name) {
        var orig = sinon[name];
        sinon[name] = function () {
            var result = orig.apply(this, arguments);
            var getCall = result.getCall;
            result.getCall = function () {
                return patchCall(getCall.apply(result, arguments));
            };
            var getCalls = result.getCalls;
            result.getCalls = function () {
                return getCalls.call(result).map(patchCall);
            };
            return result;
        };
        sinon[name].create = orig.create;
    });
};

@@ -229,58 +229,130 @@
     
-// Copied from test/monkeyPatchSinonStackFrames.js
+function isSpy(value) %7B%0A        return value && typeof value.id === 'string' &&%0A            /%5Espy#/.test(value.id);%0A    %7D%0A
 %0A   
@@ -639,80 +639,66 @@
     
-%5B'spy', 'stub'%5D.forEach(function (name) %7B%0A        var orig = sinon%5Bname%5D
+function patchSpy(spy) %7B%0A        var getCall = spy.getCall
 ;%0A  
@@ -704,26 +704,26 @@
        s
-inon%5Bname%5D
+py.getCall
  = funct
@@ -747,36 +747,42 @@
     
-var result = orig
+return patchCall(getCall
 .apply(
-this
+spy
 , ar
@@ -789,22 +789,30 @@
 guments)
+)
 ;%0A    
+    %7D;%0A
         
@@ -822,33 +822,31 @@
  getCall
+s
  = 
-result
+spy
 .getCall
 ;%0A      
@@ -829,32 +829,33 @@
 ls = spy.getCall
+s
 ;%0A            re
@@ -848,34 +848,27 @@
         
-    result
+spy
 .getCall
  = funct
@@ -851,32 +851,33 @@
      spy.getCall
+s
  = function () %7B
@@ -893,61 +893,47 @@
     
-    
 return 
-patchCall(getCall.apply(result, arguments)
+getCalls.call(spy).map(patchCall
 );%0A 
@@ -943,161 +943,251 @@
     
+%7D;%0A
     %7D
-;
+%0A%0A
 %0A    
-   
+%5B'spy', 'stub'%5D.forEach(function (name) %7B%0A
      
+   
 var 
-getCalls = result.getCalls;%0A            result.getCalls = function () %7B%0A                return getCalls.call(result).map(patchCall
+orig = sinon%5Bname%5D;%0A        sinon%5Bname%5D = function () %7B%0A            var result = orig.apply(this, arguments);%0A            if (isSpy(result)) %7B%0A                patchSpy(result
 );%0A 
@@ -1190,33 +1190,32 @@
 );%0A            %7D
-;
 %0A            ret

Test suite: Fix overeager monkey-patching of the sinon.stub return value that made sinon.createStubInstance() return an object with getCall and getCalls methods.