Created
October 4, 2012 03:42
-
-
Save codeimpossible/3831347 to your computer and use it in GitHub Desktop.
BDD style unit tests for node-worker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Worker', function(){ | |
var helpers = require('./test_helpers'); | |
var loadModule = require('./module-loader').loadModule; | |
var mocks = require('mocks'); | |
var assert = require("assert"); | |
var module, fsMock, mockRequest, mockResponse, Worker; | |
Function.prototype.after = function(ms) { | |
var current = this; | |
var args = arguments; | |
function delay(){ | |
var arr = []; | |
current.apply(this, arr.slice.call(args, 1)); | |
} | |
this.after_timeout = setTimeout(delay, ms); | |
return this.after_timeout; | |
}; | |
Function.prototype.prevent = function() { | |
clearTimeout(this.after_timeout); | |
} | |
beforeEach(function() { | |
fsMock = mocks.fs.create(); | |
Worker = require('../src/worker'); | |
}); | |
describe('#job', function() { | |
it('should exist', function(){ | |
var worker = Worker.create(); | |
assert.ok( worker.hasOwnProperty('job') ); | |
}) | |
}) | |
describe('#init()', function(){ | |
it('should exist', function(){ | |
var worker = Worker.create(); | |
assert.ok( worker.hasOwnProperty('init') ); | |
}) | |
it('should emit no_config event if worker.yml does not exist', function( done ){ | |
var worker = Worker.create({ fs: { exists: function(file, ev) { ev(false); } } }); | |
done.after(1000, "no_config event did not get called when the config was missing!"); | |
worker.on('no_config', function(){ | |
done.prevent(); | |
done(); | |
} ); | |
worker.init(); | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment