Skip to content
Browse files

Fixed overeagar including of before and after callbacks in nested des…

…cribes. Adding incrementing ids to describe, before, it, and after elements.
  • Loading branch information...
1 parent fde9ab6 commit a5a8cf242539d9f501c0620c3d8f31144ce1be01 @btakita btakita committed
Showing with 26 additions and 43 deletions.
  1. +7 −31 lib/screw.behaviors.js
  2. +19 −12 lib/screw.builder.js
View
38 lib/screw.behaviors.js
@@ -17,11 +17,15 @@ $(Screw).bind('loaded', function() {
},
run_befores: function() {
$(this).fn('parent').fn('run_befores');
- $(this).children('.befores').find('.before').fn('run');
+ $(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').fn('run');
+ $(this).children('.afters').find('.after').each(function() {
+ Screw.afters[this.id]();
+ });
},
enqueue: function() {
$(this).children('.its').children('.it').fn('enqueue');
@@ -47,13 +51,7 @@ $(Screw).bind('loaded', function() {
$(this)
.fn('parent').fn('run_befores');
- for(var i=0; i < Screw.its.length; i++) {
- var args = Screw.its[i];
- if(args[0] == this) {
- args[1]();
- break;
- }
- }
+ Screw.its[this.id]();
} finally {
$(this).fn('parent').fn('run_afters');
}
@@ -76,28 +74,6 @@ $(Screw).bind('loaded', function() {
}
});
- $('.before').fn({
- 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() {
- for(var i=0; i < Screw.afters.length; i++) {
- var args = Screw.afters[i];
- if(args[0] == this) {
- return args[1]();
- }
- }
- }
- });
-
$('.status').text('Running...');
var to_run = unescape(location.search.slice(1)) || 'body > .describe > .describes > .describe';
$(to_run)
View
31 lib/screw.builder.js
@@ -5,7 +5,7 @@ var Screw = {
if(!Screw.root_element) {
Screw.root_element = $('<div class="describe">');
Screw.root_element
- .append($('<h3 class="status">'))
+ .append('<h3 class="status">')
.append('<ol class="befores">')
.append('<ul class="its">')
.append('<ul class="describes">')
@@ -28,13 +28,22 @@ var Screw = {
},
root_element: null,
last_suite: null,
- befores: [],
- its: [],
- afters: [],
+ describes: {},
+ befores: {},
+ its: {},
+ afters: {},
+ assign_next_id: function(element) {
+ Screw.current_id++;
+ var id = "Screw_" + Screw.current_id;
+ element.attr('id', id);
+ return id
+ },
+ current_id: 0,
Specifications: {
context: [],
describe: function(name, fn) {
var describe = $('<li class="describe">');
+ Screw.describes[Screw.assign_next_id(describe)] = fn;
$('<h1>').text(name).appendTo(describe);
describe
.append('<ol class="befores">')
@@ -52,8 +61,8 @@ var Screw = {
},
it: function(name, fn) {
var it = $('<li class="it">');
+ Screw.its[Screw.assign_next_id(it)] = fn;
$('<h2>').text(name).appendTo(it);
- Screw.its.push([it[0], fn]);
this.context[this.context.length-1]
.children('.its')
@@ -61,18 +70,16 @@ var Screw = {
},
before: function(fn) {
var before = $('<li class="before">');
-
- Screw.befores.push([before[0], fn]);
+ Screw.befores[Screw.assign_next_id(before)] = fn;
this.context[this.context.length-1]
- .find('.befores')
+ .children('.befores')
.append(before);
},
after: function(fn) {
var after = $('<li class="after">');
-
- Screw.afters.push([after[0], fn])
+ Screw.afters[Screw.assign_next_id(after)] = fn;
this.context[this.context.length-1]
- .find('.afters')
+ .children('.afters')
.append(after);
}
},
@@ -131,4 +138,4 @@ var Screw = {
}
}
}
-};
+};

0 comments on commit a5a8cf2

Please sign in to comment.
Something went wrong with that request. Please try again.