core/lib/screw.builder.js in btakita-screw-unit-server-0.3.0 vs core/lib/screw.builder.js in btakita-screw-unit-server-0.6.0
- old
+ new
@@ -1,27 +1,41 @@
var Screw = (function($) {
var screw = {
Unit: function(fn) {
- var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
- var fn = new Function("matchers", "specifications",
+ var wrappedFn;
+ if(fn.length == 0) {
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
+ wrappedFn = new Function("matchers", "specifications",
"with (specifications) { with (matchers) { " + contents + " } }"
- );
+ );
+ } else {
+ wrappedFn = function(matchers, specifications) {
+ var screwContext = {};
+ for(var method in matchers) {
+ screwContext[method] = matchers[method];
+ }
+ for(var method in specifications) {
+ screwContext[method] = specifications[method];
+ }
+ fn(screwContext);
+ }
+ }
$(Screw).queue(function() {
Screw.Specifications.context.push($('body > .describe'));
- fn.call(this, Screw.Matchers, Screw.Specifications);
+ wrappedFn.call(this, Screw.Matchers, Screw.Specifications);
Screw.Specifications.context.pop();
$(this).dequeue();
});
},
Specifications: {
context: [],
describe: function(name, fn) {
var describe = $('<li class="describe">')
- .append($('<h1>').text(name))
+ .append($('<h1 />').text(name))
.append('<ol class="befores">')
.append('<ul class="its">')
.append('<ul class="describes">')
.append('<ol class="afters">');
@@ -34,47 +48,48 @@
.append(describe);
},
it: function(name, fn) {
var it = $('<li class="it">')
- .append($('<h2>').text(name))
+ .append($('<h2 />').text(name))
.data('screwunit.run', fn);
this.context[this.context.length-1]
.children('.its')
.append(it);
},
before: function(fn) {
- var before = $('<li class="before">')
+ var before = $('<li class="before"></li>')
.data('screwunit.run', fn);
this.context[this.context.length-1]
.children('.befores')
.append(before);
},
after: function(fn) {
- var after = $('<li class="after">')
+ var after = $('<li class="after"></li>')
.data('screwunit.run', fn);
this.context[this.context.length-1]
.children('.afters')
.append(after);
}
}
};
$(screw).queue(function() { $(screw).trigger('loading') });
- $(function() {
+ $(window).load(function(){
$('<div class="describe">')
- .append('<h3 class="status">')
+ .append('<h3 class="status" />')
.append('<ol class="befores">')
.append('<ul class="describes">')
.append('<ol class="afters">')
.appendTo('body');
-
+
$(screw).dequeue();
$(screw).trigger('loaded');
});
+
return screw;
})(jQuery);
\ No newline at end of file