I'm attempting to test a small node library with mocha:
var util = require('util'),
exec = require('child_process').exec;
var seleniumLocator = function(command) {
return function(callback) {
var pathToSeleniumServer = './'
, pathToMatch =/\/[\w\-\/]+\/selenium-server-standalone-\d+\.\d+\.\d+\.jar/m
, child;
child = exec(command, function(error, stdout, stderr) {
if (!error) {
pathToSeleniumServer = (stdout.match(pathToMatch) || [])[0];
callback(pathToSeleniumServer);
}
});
};
}
var homebrewLocator = seleniumLocator('brew info selenium-server-standalone');
module.exports.homebrewLocator = homebrewLocator;
when I run the code from command line the callback can be seen to work however my test in mocha fails to identify the callback was invoked.
var should = require('should')
, sinon = require('sinon')
, homebrewLocator = require('./../lib/locators/homebrew_locator').homebrewLocator;
describe('seleniumLocator', function() {
describe('when using Homebrew', function() {
it('should calls a callback with the location of selenium', function() {
var callback = sinon.spy();
homebrewLocator(callback);
callback.called.should.be.true;
});
});
});
Is there something about exec and scope I'm not getting?