Add Utils to global.Cylon namespace, add bootstrap

This commit moves Utils to live in the global Cylon namespace, so they can be
accessed in test suites. This is necessary because Mocha, when setting up for
tests, will override our #after method, making TDR not work if any robots
contain a #after call in their work block.

To fix this, in test setup you can call global.Cylon.Utils.bootstrap();
which will re-setup our globals.
This commit is contained in:
Andrew Stewart 2014-04-01 12:31:13 -07:00
parent 2563e62de4
commit 1cffa6067e
1 changed files with 167 additions and 146 deletions

View File

@ -77,7 +77,10 @@ Number.prototype.toScale = function(start, end) {
}
};
var Utils = {
var namespace = require('node-namespace');
namespace('Cylon', function() {
this.Utils = {
// Public: Alias to setInterval, combined with Number monkeypatches below to
// create an artoo-like syntax.
//
@ -228,10 +231,28 @@ var Utils = {
// Returns a function wrapper
bind: function(fn, me) {
return function() { return fn.apply(me, arguments); };
},
// Public: Adds all methods from Cylon.Utils directly to the global
// namespace.
//
// Examples
//
// Cylon.Utils.bootstrap();
// (after === Cylon.Utils.After) // true
//
// Returns Cylon.Utils
bootstrap: function() {
for (util in this) {
// we're not going to attach the 'bootstrap' method
if (!(util === "bootstrap")) {
global[util] = this[util];
}
}
};
// Add all utility functions to global namespace
for (var util in Utils) { global[util] = Utils[util]; }
return this;
}
};
});
module.exports = Utils;
module.exports = Cylon.Utils.bootstrap();