var Screw = (function($) { var screw = { Unit: function(fn) { 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')); wrappedFn.call(this, Screw.Matchers, Screw.Specifications); Screw.Specifications.context.pop(); $(this).dequeue(); }); }, Specifications: { context: [], describe: function(name, fn) { var describe = $('
  • ') .append($('

    ').text(name)) .append('
      ') .append('
        ') .append('
          ') .append('
            '); this.context.push(describe); fn.call(); this.context.pop(); this.context[this.context.length-1] .children('.describes') .append(describe); }, it: function(name, fn) { var it = $('
          1. ') .append($('

            ').text(name)) .data('screwunit.run', fn); this.context[this.context.length-1] .children('.its') .append(it); }, before: function(fn) { var before = $('
          2. ') .data('screwunit.run', fn); this.context[this.context.length-1] .children('.befores') .append(before); }, after: function(fn) { var after = $('
          3. ') .data('screwunit.run', fn); this.context[this.context.length-1] .children('.afters') .append(after); } } }; $(screw).queue(function() { $(screw).trigger('loading') }); $(window).load(function(){ $('
            ') .append('

            ') .append('
              ') .append('
                ') .append('
                  ') .appendTo('body'); $(screw).dequeue(); $(screw).trigger('loaded'); }); return screw; })(jQuery);