Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Made the method signature expect(count, stubfn) work

  • Loading branch information...
commit b86cf7a3c98c7d28255eb4bb38ed140d988a08c1 1 parent 62b728d
Jeremiah Wuenschel authored November 17, 2010 felixge committed November 20, 2010
4  lib/gently/gently.js
@@ -48,10 +48,10 @@ Gently.prototype.hijack = function(realRequire) {
48 48
 };
49 49
 
50 50
 Gently.prototype.expect = function(obj, method, count, stubFn) {
51  
-  if (typeof obj != 'function' && typeof obj != 'object') {
  51
+  if (typeof obj != 'function' && typeof obj != 'object' && typeof obj != 'number') {
52 52
     throw new Error
53 53
       ( 'Bad 1st argument for gently.expect(), '
54  
-      + 'object or function expected, got: '+(typeof obj)
  54
+      + 'object, function, or number expected, got: '+(typeof obj)
55 55
       );
56 56
   } else if (typeof obj == 'function' && (typeof method != 'string')) {
57 57
     // expect(stubFn) interface
14  test/simple/test-gently.js
@@ -20,7 +20,7 @@ test(function expectBadArgs() {
20 20
     gently.expect(BAD_ARG);
21 21
     assert.ok(false, 'throw needs to happen');
22 22
   } catch (e) {
23  
-    assert.equal(e.message, 'Bad 1st argument for gently.expect(), object or function expected, got: '+(typeof BAD_ARG));
  23
+    assert.equal(e.message, 'Bad 1st argument for gently.expect(), object, function, or number expected, got: '+(typeof BAD_ARG));
24 24
   }
25 25
 });
26 26
 
@@ -104,6 +104,18 @@ test(function expectClosure() {
104 104
   assert.equal(stubFnCalled, 1);
105 105
 });
106 106
 
  107
+test(function expectClosureCount() {
  108
+  var stubFnCalled = 0;
  109
+  function closureFn() {stubFnCalled++};
  110
+
  111
+  var fn = gently.expect(2, closureFn);
  112
+  assert.equal(gently.expectations.length, 2);
  113
+  fn();
  114
+  assert.equal(gently.expectations.length, 1);
  115
+  fn();
  116
+  assert.equal(stubFnCalled, 2);
  117
+});
  118
+
107 119
 test(function restore() {
108 120
   var OBJ = {}, NAME = '[my object].myFn()';
109 121
   OBJ.foo = function(x) {

0 notes on commit b86cf7a

Please sign in to comment.
Something went wrong with that request. Please try again.