var Screw = (function($) { var screw = { Unit: function(fn) { var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]; var fn = new Function("matchers", "specifications", "with (specifications) { with (matchers) { " + contents + " } }" ); $(Screw).queue(function() { Screw.Specifications.context.push($('body > .describe')); fn.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') }); $(function() { $('
            ') .append('

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