Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Commit

Permalink
force undefined contexts passed to test be false rather than throwing…
Browse files Browse the repository at this point in the history
… errors. Fixes #4
  • Loading branch information
Garrett Johnson committed Feb 25, 2013
1 parent 772e047 commit ec5a24c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function Rule(path, ruler){
*/

Rule.prototype.test = function(obj){
if ('undefined' == typeof obj) return false;
var actual = this.path(obj);
return this.stack.every(function(fn){
return fn(actual);
Expand Down
8 changes: 8 additions & 0 deletions test/rule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,12 @@ describe('Rule', function(){
});
});

describe('undefined contexts', function(){
it('should not throw an exception', function(){
var rule = new Rule('name');
rule.eq('hai');
rule.test().should.equal(false);
});
});

});

0 comments on commit ec5a24c

Please sign in to comment.