Permalink
Browse files

Return original function in expect()

  • Loading branch information...
1 parent 53d86aa commit a1186b5fe860c3676dc048de839f978fdd1aac82 @felixge committed May 23, 2010
Showing with 5 additions and 2 deletions.
  1. +2 −0 Readme.md
  2. +1 −1 lib/gently/gently.js
  3. +2 −1 test/simple/test-gently.js
View
@@ -69,6 +69,8 @@ Creates a new gently instance. It listens to the process `'exit'` event to make
Creates an expectation for an objects method to be called. You can optionally specify the call `count` you are expecting, as well as `mock` function that will run instead of the original function.
+Returns a reference to the function that is getting overwritten.
+
#### gently.expect([count], mock)
Returns a function that is supposed to be executed `count` times, delegating any calls to the provided `mock` function. Naming your mock closure will help to properly diagnose errors that are being thrown:
View
@@ -55,7 +55,7 @@ Gently.prototype.expect = function(obj, method, count, mock) {
var original = obj[method];
obj[method] = delegate;
- obj[method]._original = original;
+ return obj[method]._original = original;
};
Gently.prototype.restore = function(obj, method) {
@@ -26,7 +26,8 @@ test(function expectObjMethod() {
, mock = function() {};
(function testAddOne() {
- gently.expect(OBJ, 'foo', mock);
+ var original = OBJ.foo;
+ assert.strictEqual(gently.expect(OBJ, 'foo', mock), original);
assert.equal(gently.expectations.length, 1);
var expectation = gently.expectations[0];

0 comments on commit a1186b5

Please sign in to comment.