Permalink
Browse files

Made the method signature expect(count, stubfn) work

  • Loading branch information...
1 parent 62b728d commit b86cf7a3c98c7d28255eb4bb38ed140d988a08c1 @jer jer committed with Nov 18, 2010
Showing with 15 additions and 3 deletions.
  1. +2 −2 lib/gently/gently.js
  2. +13 −1 test/simple/test-gently.js
View
4 lib/gently/gently.js
@@ -48,10 +48,10 @@ Gently.prototype.hijack = function(realRequire) {
};
Gently.prototype.expect = function(obj, method, count, stubFn) {
- if (typeof obj != 'function' && typeof obj != 'object') {
+ if (typeof obj != 'function' && typeof obj != 'object' && typeof obj != 'number') {
throw new Error
( 'Bad 1st argument for gently.expect(), '
- + 'object or function expected, got: '+(typeof obj)
+ + 'object, function, or number expected, got: '+(typeof obj)
);
} else if (typeof obj == 'function' && (typeof method != 'string')) {
// expect(stubFn) interface
View
14 test/simple/test-gently.js
@@ -20,7 +20,7 @@ test(function expectBadArgs() {
gently.expect(BAD_ARG);
assert.ok(false, 'throw needs to happen');
} catch (e) {
- assert.equal(e.message, 'Bad 1st argument for gently.expect(), object or function expected, got: '+(typeof BAD_ARG));
+ assert.equal(e.message, 'Bad 1st argument for gently.expect(), object, function, or number expected, got: '+(typeof BAD_ARG));
}
});
@@ -104,6 +104,18 @@ test(function expectClosure() {
assert.equal(stubFnCalled, 1);
});
+test(function expectClosureCount() {
+ var stubFnCalled = 0;
+ function closureFn() {stubFnCalled++};
+
+ var fn = gently.expect(2, closureFn);
+ assert.equal(gently.expectations.length, 2);
+ fn();
+ assert.equal(gently.expectations.length, 1);
+ fn();
+ assert.equal(stubFnCalled, 2);
+});
+
test(function restore() {
var OBJ = {}, NAME = '[my object].myFn()';
OBJ.foo = function(x) {

0 comments on commit b86cf7a

Please sign in to comment.