-
Notifications
You must be signed in to change notification settings - Fork 7
/
FrameworkAssertionEngineTest.cfc
368 lines (307 loc) · 16.8 KB
/
FrameworkAssertionEngineTest.cfc
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/**
* @doc_abstract true
*/
component extends="testbox.system.BaseSpec" {
function getCUT() {
throw('Method is abstract and must be implemented in a concrete test component. Return the component from this method.');
}
function setUpEvent() {
throw('Method is abstract and must be implemented in a concrete test component. Return the event object from this method.');
}
function beforeAll() {
if (isAbstractSpec()) {
return;
}
this.CUT = getCUT();
getMockBox().prepareMock( this.CUT );
}
function isAbstractSpec() {
var md = getMetadata(this);
return structKeyExists( md, 'doc_abstract' ) && md.doc_abstract == true;
}
function run() {
if (isAbstractSpec()) {
debug( "This spec is not run directly. To run these tests, extend this class from a concrete component." );
return;
}
describe( "Framework Assertion Engine Tests — #getMetadata(this).fullname#", function() {
it( "adheres to the FrameworkAssertionEngine interface", function() {
expect( this.CUT ).toBeInstanceOf( "Integrated.Engines.Assertion.Contracts.FrameworkAssertionEngine" );
} );
beforeEach(function() {
// Set the default request method to 'visit'
this.CUT.$property(propertyName = 'requestMethod', mock = 'visit');
// Add a mock request context
variables.mockEvent = setUpEvent();
this.CUT.$property( propertyName = 'event', mock = mockEvent );
});
feature('seePageIs', function() {
it('verifies the url of the page', function() {
mockEvent.$('getCurrentRoutedUrl').$results('/login-page.html');
expect(function() {
this.CUT.seePageIs('/login-page.html');
}).notToThrow();
expect(function() {
this.CUT.seePageIs('/random-page.html');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the url \[\/login-page\.html\] \(actual\) equalled \[\/random\-page\.html\] \(expected\)\.'
);
});
it('throws an exception if trying to verify the url of a page visited by `visitEvent`', function() {
mockEvent.$('getCurrentRoutedUrl').$results('');
this.CUT.$property(propertyName = 'requestMethod', mock = 'visitEvent');
expect(function() {
this.CUT.seePageIs('/sample-page.html');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'You cannot assert the page when you visited using the visitEvent\(\) method\. Please use visit\(\) instead\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seePageIs('/sample-page.html');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('seeViewIs', function() {
it('verifies the currently routed framework view', function() {
mockEvent.$('getCurrentView').$results('main.index');
expect(function() {
this.CUT.seeViewIs('main.index'); }
).notToThrow();
expect(function() {
this.CUT.seeViewIs('main.doesntExist');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that view \[main\.index\] \(actual\) equalled \[main\.doesntExist\] \(expected\)\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seeViewIs('main.index');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('seeHandlerIs', function() {
it('verifies the currently routed framework handler', function() {
mockEvent.$('getCurrentHandler').$results('Main');
expect(function() {
this.CUT.seeHandlerIs('Main'); }
).notToThrow();
expect(function() {
this.CUT.seeHandlerIs('DoesntExist');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that handler \[Main\] \(actual\) equalled \[DoesntExist\] \(expected\)\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seeHandlerIs('Main');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('seeActionIs', function() {
it('verifies the currently routed framework action', function() {
mockEvent.$('getCurrentAction').$results('index');
expect(function() {
this.CUT.seeActionIs('index'); }
).notToThrow();
expect(function() {
this.CUT.seeActionIs('doesntExist');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that action \[index\] \(actual\) equalled \[doesntExist\] \(expected\)\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seeActionIs('index');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('seeEventIs', function() {
it('verifies the currently routed framework event', function() {
mockEvent.$('getCurrentEvent').$results('Main.index');
expect(function() {
this.CUT.seeEventIs('Main.index'); }
).notToThrow();
expect(function() {
this.CUT.seeEventIs('Main.doesntExist');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that event \[Main\.index\] \(actual\) equalled \[Main\.doesntExist\] \(expected\)\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seeEventIs('Main.index');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('seeInCollection', function() {
it('verifies that a key exists in the request collection', function() {
expect(function() {
this.CUT.seeInCollection('email');
}).notToThrow();
expect(function() {
this.CUT.seeInCollection('username');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[username\] exists in the request collection\.'
);
});
it('verifies that a key exists in the private request collection', function() {
expect(function() {
this.CUT.seeInCollection(key = 'birthday', private = true);
}).notToThrow();
expect(function() {
this.CUT.seeInCollection(key = 'username', private = true);
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[username\] exists in the private request collection\.'
);
});
it('verifies that a key with a given value exists in the request collection', function() {
expect(function() {
this.CUT.seeInCollection('email', '[email protected]');
}).notToThrow();
expect(function() {
this.CUT.seeInCollection('username', 'johnny_boy');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[username\] with the value \[johnny\_boy\] exists in the request collection\.'
);
});
it('verifies that a key with a given value exists in the private request collection', function() {
expect(function() {
this.CUT.seeInCollection(key = 'birthday', value = '01/01/1980', private = true);
}).notToThrow();
expect(function() {
this.CUT.seeInCollection(key = 'username', value = 'johnny_boy', private = true);
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[username\] with the value \[johnny_boy\] exists in the private request collection\.'
);
});
it('fails if the key does exist but not with the given value in the request collection', function() {
expect(function() {
this.CUT.seeInCollection('email', '[email protected]');
}).notToThrow();
expect(function() {
this.CUT.seeInCollection('email', '[email protected]');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[email\] with the value \[johnny\_boy\@example\.com\] exists in the request collection\.'
);
});
it('fails if the key does exist but not with the given value in the private request collection', function() {
expect(function() {
this.CUT.seeInCollection(key = 'birthday', value = '01/01/1980', private = true);
}).notToThrow();
expect(function() {
this.CUT.seeInCollection(key = 'birthday', value = '02/29/2016', private = true);
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[birthday\] with the value \[02\/29\/2016\] exists in the private request collection\.'
);
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.seeInCollection('email');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
feature('dontSeeInCollection', function() {
it('verifies that a key does not exist in the request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection('username');
}).notToThrow();
expect(function() {
this.CUT.dontSeeInCollection('email');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[email\] does not exist in the request collection\.'
);
});
it('verifies that a key does not exist in the private request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection(key = 'username', private = true);
}).notToThrow();
expect(function() {
this.CUT.dontSeeInCollection(key = 'birthday', private = true);
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[birthday\] does not exist in the private request collection\.'
);
});
it('verifies that a key with a given value does not exist in the request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection('username', 'johnny_boy');
}).notToThrow();
expect(function() {
this.CUT.dontSeeInCollection('email', '[email protected]');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[email\] with the value \[john\@example\.com\] does not exist in the request collection\.'
);
});
it('verifies that a key with a given value does not exist in the private request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection(key = 'username', value = 'johnny_boy', private = true);
}).notToThrow();
expect(function() {
this.CUT.dontSeeInCollection(key = 'birthday', value = '01/01/1980', private = true);
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Failed asserting that the key \[birthday\] with the value \[01\/01\/1980\] does not exist in the private request collection\.'
);
});
it('does not fail if the key does exist but not with the given value in the request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection('email', '[email protected]');
}).notToThrow();
});
it('does not fail if the key does exist but not with the given value in the private request collection', function() {
expect(function() {
this.CUT.dontSeeInCollection(key = 'birthday', value = '02/29/2016', private = true);
}).notToThrow();
});
it('throws an exception if there is no parsed document', function() {
this.CUT.$property(propertyName = 'event', mock = '');
expect(function() {
this.CUT.dontSeeInCollection('email');
}).toThrow(
type = 'TestBox.AssertionFailed',
regex = 'Cannot make assertions until you visit a page\. Make sure to run visit\(\) or visitEvent\(\) first\.'
);
});
});
} );
}
}