Permalink
Browse files

Fix: _original method did not get preserved

When more than one expect() call was made to a method, the original method was
overwritten by the previous stub function.
  • Loading branch information...
1 parent 9033c14 commit 24f18ec9073dda911f2a3f8388586da6fcf8dffd @felixge committed Aug 22, 2010
Showing with 7 additions and 4 deletions.
  1. +5 −2 lib/gently/gently.js
  2. +2 −2 test/simple/test-gently.js
@@ -88,7 +88,10 @@ Gently.prototype.expect = function(obj, method, count, stubFn) {
return delegate;
}
- var original = obj[method];
+ var original = (obj[method])
+ ? obj[method]._original || obj[method]
+ : undefined;
+
obj[method] = delegate;
return obj[method]._original = original;
};
@@ -145,4 +148,4 @@ Gently.prototype._name = function(obj, method, stubFn) {
}
return '>> '+stubFn.toString()+' <<';
-};
+};
@@ -38,7 +38,6 @@ test(function expectObjMethod() {
, stubFn = function() {};
(function testAddOne() {
- var original = OBJ.foo;
assert.strictEqual(gently.expect(OBJ, 'foo', stubFn), original);
assert.equal(gently.expectations.length, 1);
@@ -53,6 +52,7 @@ test(function expectObjMethod() {
(function testAddTwo() {
gently.expect(OBJ, 'foo', 2, stubFn);
assert.equal(gently.expectations.length, 3);
+ assert.strictEqual(OBJ.foo._original, original);
})();
(function testAddOneWithoutMock() {
@@ -292,4 +292,4 @@ test(function _name() {
var myClosure = function() {2+2 == 5};
assert.equal(gently._name(null, null, myClosure), '>> '+myClosure.toString()+' <<');
})();
-});
+});

0 comments on commit 24f18ec

Please sign in to comment.