forked from nkallen/screw-unit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
screw.behaviors.js
92 lines (79 loc) · 2.92 KB
/
screw.behaviors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
(function($) {
$(Screw).bind('loaded', function() {
$('body > div.screw_unit_content .status').fn({
display: function() {
$(this).html(
$('.screw_unit_content .passed').length + $('.screw_unit_content .failed').length + ' test(s), ' + $('.screw_unit_content .failed').length + ' failure(s)<br />' +
((new Date() - Screw.suite_start_time)/1000.0).toString() + " seconds elapsed"
);
}
});
$('body > div.screw_unit_content .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 > div.screw_unit_content > .describe').fn({
selector: function() { return 'body > div.screw_unit_content > .describe' }
});
$('body > div.screw_unit_content .it').fn({
parent: function() {
return $(this).parent('.its').parent('.describe');
},
run: function() {
try {
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]);
}
},
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) + ')';
}
});
$('body > div.screw_unit_content .before').fn({
run: function() { $(this).data('screwunit.run')() }
});
$('body > div.screw_unit_content .after').fn({
run: function() { $(this).data('screwunit.run')() }
});
$(Screw).trigger('before');
var to_run = unescape(location.search.slice(1)) || 'body > div.screw_unit_content > .describe > .describes > .describe';
$(to_run)
.focus()
.eq(0).trigger('scroll').end()
.fn('enqueue');
$(Screw).queue(function() { $(Screw).trigger('after') });
})
})(jQuery);