Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Not storing the before, after, and it callback function in the DOM be…

…cause it has race conditions when loading the page.
  • Loading branch information...
commit fde9ab64ae3f70d5a108ed5efd6a15013fa41b6f 1 parent 85a8add
@btakita btakita authored
Showing with 37 additions and 13 deletions.
  1. +26 −5 lib/screw.behaviors.js
  2. +11 −8 lib/screw.builder.js
View
31 lib/screw.behaviors.js
@@ -36,7 +36,7 @@ $(Screw).bind('loaded', function() {
}
}
});
-
+
$('.it').fn({
parent: function() {
return $(this).parent('.its').parent('.describe');
@@ -46,7 +46,14 @@ $(Screw).bind('loaded', function() {
try {
$(this)
.fn('parent').fn('run_befores');
- $(this).data('screwunit.run')();
+
+ for(var i=0; i < Screw.its.length; i++) {
+ var args = Screw.its[i];
+ if(args[0] == this) {
+ args[1]();
+ break;
+ }
+ }
} finally {
$(this).fn('parent').fn('run_afters');
}
@@ -68,13 +75,27 @@ $(Screw).bind('loaded', function() {
+ ' > .its > .it:eq(' + $(this).parent('.its').children('.it').index(this) + ')';
}
});
-
+
$('.before').fn({
- run: function() { $(this).data('screwunit.run')() }
+ run: function() {
+ for(var i=0; i < Screw.befores.length; i++) {
+ var args = Screw.befores[i];
+ if(args[0] == this) {
+ return args[1]();
+ }
+ }
+ }
});
$('.after').fn({
- run: function() { $(this).data('screwunit.run')() }
+ run: function() {
+ for(var i=0; i < Screw.afters.length; i++) {
+ var args = Screw.afters[i];
+ if(args[0] == this) {
+ return args[1]();
+ }
+ }
+ }
});
$('.status').text('Running...');
View
19 lib/screw.builder.js
@@ -28,6 +28,9 @@ var Screw = {
},
root_element: null,
last_suite: null,
+ befores: [],
+ its: [],
+ afters: [],
Specifications: {
context: [],
describe: function(name, fn) {
@@ -42,7 +45,7 @@ var Screw = {
this.context.push(describe);
fn.call();
this.context.pop();
-
+
this.context[this.context.length-1]
.children('.describes')
.append(describe);
@@ -50,24 +53,24 @@ var Screw = {
it: function(name, fn) {
var it = $('<li class="it">');
$('<h2>').text(name).appendTo(it);
- it.data('screwunit.run', fn);
-
+ Screw.its.push([it[0], fn]);
+
this.context[this.context.length-1]
.children('.its')
.append(it);
},
before: function(fn) {
- var before = $('<li class="before">')
- .data('screwunit.run', fn);
+ var before = $('<li class="before">');
+ Screw.befores.push([before[0], fn]);
this.context[this.context.length-1]
.find('.befores')
.append(before);
},
after: function(fn) {
- var after = $('<li class="after">')
- .data('screwunit.run', fn);
+ var after = $('<li class="after">');
+ Screw.afters.push([after[0], fn])
this.context[this.context.length-1]
.find('.afters')
.append(after);
@@ -121,7 +124,7 @@ var Screw = {
if(actual.length == undefined) {
throw(actual.toString() + " does not respond to length");
}
- return actual.length == 0;
+ return actual.length == 0;
},
failure_message: function(expected, actual, not) {
return 'expected ' + $([actual]).print() + (not ? ' to not be empty' : ' to be empty');
Please sign in to comment.
Something went wrong with that request. Please try again.