Permalink
Browse files

Raise bad argument exception in gently.expect()

Too often I found myself typing this:

gently.expect('method', fn);

Which so far got silently ignored. This patch makes this mistake more
obvious.
  • Loading branch information...
1 parent 7ca157e commit da84ab04aaf96164a6cabc97c5e81d4015ce1204 @felixge committed May 28, 2010
Showing with 16 additions and 1 deletion.
  1. +6 −1 lib/gently/gently.js
  2. +10 −0 test/simple/test-gently.js
View
@@ -9,7 +9,12 @@ function Gently() {
exports.Gently = Gently;
Gently.prototype.expect = function(obj, method, count, mock) {
- if (typeof obj == 'function') {
+ if (typeof obj != 'function' && typeof obj != 'object') {
+ throw new Error
+ ( 'Bad 1st argument for gently.expect(), '
+ + 'object or function expected, got: '+(typeof obj)
+ );
+ } else if (typeof obj == 'function') {
// expect(mock) interface
mock = obj;
obj = null;
View
@@ -13,6 +13,16 @@ test(function constructor() {
assert.equal(gently.constructor.name, 'Gently');
});
+test(function expectBadArgs() {
+ var BAD_ARG = 'oh no';
+ try {
+ 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));
+ }
+});
+
test(function expectObjMethod() {
var OBJ = {}, NAME = 'foobar';
OBJ.foo = function(x) {

0 comments on commit da84ab0

Please sign in to comment.