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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
describe('Runner', function(){
var scenario, runner, log, Describe, It, $scenario, body;
function logger(text) {
return function(done){
log += text;
(done||noop)();
};
}
beforeEach(function(){
log = '';
scenario = {};
body = _jQuery('<div></div>');
runner = new angular.scenario.Runner(scenario, _jQuery);
Describe = scenario.describe;
BeforeEach = scenario.beforeEach;
AfterEach = scenario.afterEach;
It = scenario.it;
$scenario = scenario.$scenario;
});
describe('describe', function(){
it('should consume the describe functions', function(){
Describe('describe name', logger('body'));
expect(log).toEqual('body');
});
describe('it', function(){
it('should consume it', function(){
Describe('describe name', function(){
It('should text', logger('body'));
});
expect(log).toEqual('body');
var spec = $scenario.specs['describe name: it should text'];
expect(spec.steps).toEqual([]);
expect(spec.name).toEqual('describe name: it should text');
});
it('should complain on duplicate it', function() {
// WRITE ME!!!!
});
it('should create a failing step if there is a javascript error', function(){
var spec;
Describe('D1', function(){
It('I1', function(){
spec = $scenario.currentSpec;
throw {message: 'blah'};
});
});
var step = spec.steps[0];
expect(step.name).toEqual('blah');
try {
step.fn();
fail();
} catch (e) {
expect(e.message).toEqual('blah');
};
});
});
describe('beforeEach', function() {
it('should execute beforeEach before every it', function() {
Describe('describe name', function(){
BeforeEach(logger('before;'));
It('should text', logger('body;'));
It('should text2', logger('body2;'));
});
expect(log).toEqual('before;body;before;body2;');
});
});
describe('afterEach', function() {
it('should execute afterEach after every it', function() {
Describe('describe name', function(){
AfterEach(logger('after;'));
It('should text', logger('body;'));
It('should text2', logger('body2;'));
});
expect(log).toEqual('body;after;body2;after;');
});
it('should always execute afterEach after every it', function() {
Describe('describe name', function(){
AfterEach(logger('after;'));
It('should text', function() {
log = 'body;';
throw "MyError";
});
It('should text2', logger('body2;'));
});
expect(log).toEqual('body;after;body2;after;');
});
});
});
describe('steps building', function(){
it('should queue steps', function(){
function step(){};
Describe('name', function(){
It('should', function(){
$scenario.addStep('stepname', step);
});
});
expect($scenario.specs['name: it should'].steps).toEqual([{name:'stepname', fn:step}]);
});
});
describe('execution', function(){
it('should execute the queued steps', function(){
var next, firstThis, secondThis, doneThis, spec;
$scenario.specs['spec'] = {
steps: [
{name:'step1', fn: function(done) {
next = done;
log += 'first;';
firstThis = this;
}},
{name:'step2', fn:function(done){
next = done;
log += 'second;';
secondThis = this;
}}
]
};
spec = $scenario.execute('spec', function(done){
log += 'done;';
doneThis = this;
});
expect(log).toEqual('first;');
next();
expect(log).toEqual('first;second;');
next();
expect(log).toEqual('first;second;done;');
expect(spec).not.toEqual(window);
expect(spec).toEqual(firstThis);
expect(spec).toEqual(secondThis);
expect(spec).toEqual(doneThis);
expect(spec.result.failed).toEqual(false);
expect(spec.result.finished).toEqual(true);
expect(spec.result.error).toBeUndefined();
expect(spec.result.passed).toEqual(true);
});
it('should handle exceptions in a step', function(){
$scenario.specs['spec'] = {
steps: [
{name:'error', fn:function(done) {
throw "MyError";
}}
]
};
var spec = $scenario.execute('spec');
expect(spec.result.passed).toEqual(false);
expect(spec.result.failed).toEqual(true);
expect(spec.result.finished).toEqual(true);
expect(spec.result.error).toEqual("MyError");
});
});
describe('run', function(){
var next;
it('should execute all specs', function(){
Describe('d1', function(){
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
It('it2', function(){
$scenario.addStep('s2', logger('s2,'));
$scenario.addStep('s2.2', function(done){ next = done; });
});
});
Describe('d2', function(){
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
});
$scenario.run(body);
expect(log).toEqual('s1,s2,');
next();
expect(log).toEqual('s1,s2,s3,s4,');
});
});
});
|