Skip to content

Instantly share code, notes, and snippets.

@quirkey
Created March 24, 2009 01:47
Show Gist options
  • Select an option

  • Save quirkey/83884 to your computer and use it in GitHub Desktop.

Select an option

Save quirkey/83884 to your computer and use it in GitHub Desktop.
(function($) {
jqUnit.Spec = function(name) {
this.before = false;
this.after = false;
this.assigns = {};
jqUnit.module(name);
};
$.extend(jqUnit.Spec.prototype, {
// shortcut to append 'should' to tests
should: function(name, callback, nowait) {
var spec = this;
if (spec.before) spec.before.apply(spec.assigns);
jqUnit.test('should ' + name, function() { callback.apply(spec); }, nowait);
if (spec.after) this.after.apply(spec.assigns);
return spec;
},
a: function(key) {
if (typeof key == 'undefined') {
return this.assigns;
} else {
return this.assigns[key];
}
}
})
$.extend(jqUnit, {
// like rspec/bacon describe, sort of
describe: function() {
var args = [].splice.call(arguments, 0);
// configuration function
var config = (args[args.length - 1].constructor == Object) ? args.pop() : {};
var spec = new jqUnit.Spec(args.join(' '));
spec.before = config['before'];
spec.after = config['after'];
return spec;
},
// asserts that the method is defined (like respond_to?)
defined: function(object, method) {
return jqUnit.ok(typeof object[method] == 'function', method + 'is not defined on' + object);
},
// asserts that the object is of a certain type
isType: function(object, type) {
return jqUnit.ok(object.constructor === type, object.toString() + ' is not of type ' + type + ', is ' + object.constructor);
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment