Skip to content
Browse files

Fix and test case for verify with 0 expectations

  • Loading branch information...
1 parent ffba501 commit f1f6da86845983f7ec435b59b58a47269a9e9d47 Joshua Cohen committed Jun 3, 2011
Showing with 27 additions and 1 deletion.
  1. +15 −1 lib/gently/gently.js
  2. +12 −0 test/simple/test-gently.js
View
16 lib/gently/gently.js
@@ -106,7 +106,21 @@ Gently.prototype.verify = function(msg) {
return;
}
- var expectation = this.expectations[0];
+ var validExpectations = [];
+ for (var i = 0, l = this.expectations.length; i < l; i++) {
+ var expectation = this.expectations[i];
+
+ if (expectation.count > 0) {
+ validExpectations.push(expectation);
+ }
+ }
+
+ if (!validExpectations.length) {
+ return;
+ }
+
+ var expectation = validExpectations[0];
+
throw new Error
( 'Expected call to '+expectation.name+' did not happen'
+ ( (msg)
View
12 test/simple/test-gently.js
@@ -334,3 +334,15 @@ test(function _name() {
assert.equal(gently._name(null, null, myClosure), '>> '+myClosure.toString()+' <<');
})();
});
+
+test(function verifyExpectNone() {
+ var OBJ = {toString: function() {return '[OBJ]'}};
+ gently.verify();
+
+ gently.expect(OBJ, 'foo', 0);
+ try {
+ gently.verify();
+ } catch (e) {
+ assert.fail('Exception should not have been thrown');
+ }
+});

0 comments on commit f1f6da8

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