Skip to content

Instantly share code, notes, and snippets.

@anatoliychakkaev
Created December 25, 2010 14:44
Show Gist options
  • Save anatoliychakkaev/754898 to your computer and use it in GitHub Desktop.
Save anatoliychakkaev/754898 to your computer and use it in GitHub Desktop.
nodeunit spec helper file
var group_name = false, EXT_EXP;
function it(should, test_case) {
check_external_exports();
if (group_name) {
EXT_EXP[group_name][should] = test_case;
} else {
EXT_EXP[should] = test_case;
}
}
global.it = it;
function context(name, tests) {
check_external_exports();
EXT_EXP[name] = {};
group_name = name;
tests({
before: function (f) {
it('setUp', f);
},
after: function (f) {
it('tearDown', f);
}
});
group_name = false;
}
global.context = context;
exports.init = function (external_exports) {
EXT_EXP = external_exports;
};
function check_external_exports() {
if (!EXT_EXP) throw new Error(
'Before run this, please ensure that ' +
'require("spec_helper").init(exports); called');
}
require('./spec_helper').init(exports);
it('should be done', function (test) {
test.done();
});
context('rain', function (each) {
each.before(prepare_rain);
each.after(dry_ground);
it('should falling down', function (test) {
test.done();
});
it('should make ground wet', function (test) {
test.done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment