pivotal/jasmine — Issue #173: Make adding new matchers easy
Author: alexeypetrushin
Created: 2012-01-07 17:40:21+00:00
State: open

Hello, right now the proposed way for adding new matchers is this:

``` JavaScript
beforeEach(function() {
this.addMatchers({
toBeLessThan: function(expected) {
return this.actual < expected;
}
});
});
```

It's not very convenient, because usually You define special matchers in a standalone helper file and reuse it among many spec files.

But right now it's not easy to define matchers without the `beforeEach` block, for example code below wouldn't work:

``` JavaScript
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
return this.actual < expected;
};
```

Now You has also to do some extra magic, like this:

``` JavaScript
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
return this.actual < expected;
};
jasmine.Matchers.prototype.toBeLessThan = jasmine.Matchers.matcherFn_('toBeLessThan', jasmine.Matchers.prototype.toBeLessThan);
```

So, maybe it's worth to somehow simplify this, add some helper method for example?, like `jasmine.Mathcers.addMatchers` that will do all this behind the scene?

Thanks.