Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/nkallen/screw-unit
Browse files Browse the repository at this point in the history
Conflicts:

	lib/screw.behaviors.js
	lib/screw.builder.js
	spec/screwunit_spec.html
  • Loading branch information
btakita committed May 5, 2008
2 parents bb5a373 + 5438b3a commit b208a0e
Show file tree
Hide file tree
Showing 12 changed files with 542 additions and 659 deletions.
2 changes: 2 additions & 0 deletions TODO
@@ -0,0 +1,2 @@
need a way to do global before and afters
need to investigate race condition with data store
8 changes: 4 additions & 4 deletions lib/jquery-1.2.3.js
Expand Up @@ -1857,7 +1857,7 @@ jQuery.event = {
var val;

// Handle the second event of a trigger and when
// an event is called after a page has unloaded
// an event is called after a page has unload
if ( typeof jQuery == "undefined" || jQuery.event.triggered )
return val;

Expand Down Expand Up @@ -2282,7 +2282,7 @@ jQuery.extend({
readyList: [],
// Handle when the DOM is ready
ready: function() {
// Make sure that the DOM is not already loaded
// Make sure that the DOM is not already load
if ( !jQuery.isReady ) {
// Remember that the DOM is ready
jQuery.isReady = true;
Expand Down Expand Up @@ -2347,7 +2347,7 @@ function bindReady(){
var numStyles;
(function(){
if (jQuery.isReady) return;
if ( document.readyState != "loaded" && document.readyState != "complete" ) {
if ( document.readyState != "load" && document.readyState != "complete" ) {
setTimeout( arguments.callee, 0 );
return;
}
Expand Down Expand Up @@ -2641,7 +2641,7 @@ jQuery.extend({
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function(){
if ( !done && (!this.readyState ||
this.readyState == "loaded" || this.readyState == "complete") ) {
this.readyState == "load" || this.readyState == "complete") ) {
done = true;
success();
complete();
Expand Down
15 changes: 12 additions & 3 deletions lib/jquery.print.js
@@ -1,13 +1,22 @@
(function($) {
$.fn.print = function() {
var obj = this.get();
$.print = function(obj) {
if (obj instanceof Function) {
return obj.toString().match(/^([^\{]*) {/)[1];
} else if(obj instanceof Array) {
return "[" + obj.toString() + "]";
var result = [];
for (var i = 0; i < obj.length; i++) {
result.push($.print(obj[i]));
}
return "[" + result.join(", ") + "]";
} else if(obj instanceof HTMLElement) {
return "<" + obj.tagName + " " + (obj.className != "" ? "class='" + obj.className + "'" : "") +
(obj.id != "" ? "id='" + obj.id + "'" : "") + ">";
} else if(obj instanceof Object) {
var result = [];
for (var k in obj) {
result.push(k + ": " + $.print(obj[k]))
}
return "{" + result.join(", ") + "}"
} else {
return obj.toString().replace(/\n\s*/g, "");
}
Expand Down
162 changes: 85 additions & 77 deletions lib/screw.behaviors.js
@@ -1,83 +1,91 @@
$(Screw).bind('loaded', function() {
$(Screw).trigger('before');
$('.status').fn({
display: function() {
$(this).text(
$('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)'
);
}
});
$(Screw).bind('after', function() {
$('.status').fn('display');
});

$('.describe').fn({
parent: function() {
return $(this).parent('.describes').parent('.describe');
},
run_befores: function() {
$(this).fn('parent').fn('run_befores');
$(this).children('.befores').find('.before').each(function() {
Screw.befores[this.id]();
});
},
run_afters: function() {
$(this).fn('parent').fn('run_afters');
$(this).children('.afters').find('.after').each(function() {
Screw.afters[this.id]();
});
},
enqueue: function() {
$(this).children('.its').children('.it').fn('enqueue');
$(this).children('.describes').children('.describe').fn('enqueue');
},
selector: function() {
var parent_selector = $(this).fn('parent').fn('selector');
if(parent_selector) {
return parent_selector + ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
} else {
return 'body > .describe';
(function($) {
$(Screw).bind('load', function() {
$('.status').fn({
display: function() {
$(this).text(
$('.passed').length + $('.failed').length + ' test(s), ' + $('.failed').length + ' failure(s)'
);
}
}
});
});

$('.it').fn({
parent: function() {
return $(this).parent('.its').parent('.describe');
},
run: function() {
try {
$('.describe').fn({
parent: function() {
return $(this).parent('.describes').parent('.describe');
},

run_befores: function() {
$(this).fn('parent').fn('run_befores');
$(this).children('.befores').children('.before').fn('run');
},

run_afters: function() {
$(this).fn('parent').fn('run_afters');
$(this).children('.afters').children('.after').fn('run');
},

enqueue: function() {
$(this).children('.its').children('.it').fn('enqueue');
$(this).children('.describes').children('.describe').fn('enqueue');
},

selector: function() {
return $(this).fn('parent').fn('selector')
+ ' > .describes > .describe:eq(' + $(this).parent('.describes').children('.describe').index(this) + ')';
}
});

$('body > .describe').fn({
selector: function() { return 'body > .describe' }
});

$('.it').fn({
parent: function() {
return $(this).parent('.its').parent('.describe');
},

run: function() {
try {
$(this)
.fn('parent').fn('run_befores');

Screw.its[this.id]();
} finally {
$(this).fn('parent').fn('run_afters');
try {
$(this).fn('parent').fn('run_befores');
$(this).data('screwunit.run')();
} finally {
$(this).fn('parent').fn('run_afters');
}
$(this).trigger('passed');
} catch(e) {
$(this).trigger('failed', [e]);
}
$(this).trigger('passed');
} catch(e) {
$(this).trigger('failed', [e]);
},

enqueue: function() {
var self = $(this).trigger('enqueued');
$(Screw)
.queue(function() {
self.fn('run');
setTimeout(function() { $(Screw).dequeue() }, 0);
});
},

selector: function() {
return $(this).fn('parent').fn('selector')
+ ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
}
},
enqueue: function() {
var self = $(this).trigger('enqueued');
$(Screw)
.queue(function() {
self.fn('run');
setTimeout(function() { $(Screw).dequeue() }, 0);
});
},
selector: function() {
return $(this).fn('parent').fn('selector')
+ ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
}
});
});

$('.before').fn({
run: function() { $(this).data('screwunit.run')() }
});

$('.after').fn({
run: function() { $(this).data('screwunit.run')() }
});

$('.status').text('Running...');
var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
$(to_run)
.focus()
.fn('enqueue');
$(Screw).queue(function() {$(Screw).trigger('after');});
});
$(Screw).trigger('before');
var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
$(to_run)
.focus()
.eq(0).trigger('scroll').end()
.fn('enqueue');
$(Screw).queue(function() { $(Screw).trigger('after') });
})
})(jQuery);

0 comments on commit b208a0e

Please sign in to comment.