Skip to content

Commit

Permalink
fix Mocha#grep(), escape regexp strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Aug 28, 2012
1 parent b5d7daf commit b00b6f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/_mocha
Expand Up @@ -218,7 +218,7 @@ mocha.suite.bail(program.bail);

// --grep

if (program.grep) mocha.grep(new RegExp(utils.escapeRegexp(program.grep)));
if (program.grep) mocha.grep(new RegExp(program.grep));

// --invert

Expand Down
11 changes: 6 additions & 5 deletions lib/mocha.js
Expand Up @@ -8,7 +8,8 @@
* Module dependencies.
*/

var path = require('path');
var path = require('path')
, utils = require('./utils');

/**
* Expose `Mocha`.
Expand All @@ -20,7 +21,7 @@ exports = module.exports = Mocha;
* Expose internals.
*/

exports.utils = require('./utils');
exports.utils = utils;
exports.interfaces = require('./interfaces');
exports.reporters = require('./reporters');
exports.Runnable = require('./runnable');
Expand Down Expand Up @@ -154,16 +155,16 @@ Mocha.prototype._growl = function(runner, reporter) {
};

/**
* Add regexp to grep for to the options object
* Add regexp to grep, if `re` is a string it is escaped.
*
* @param {RegExp} or {String} re
* @param {RegExp|String} re
* @return {Mocha}
* @api public
*/

Mocha.prototype.grep = function(re){
this.options.grep = 'string' == typeof re
? new RegExp(re)
? new RegExp(utils.escapeRegexp(re))
: re;
return this;
};
Expand Down

0 comments on commit b00b6f5

Please sign in to comment.