shuriken 0.1.2.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +28 -0
  3. data/coffeescripts/shuriken/test/assertions.coffee +111 -0
  4. data/coffeescripts/shuriken/test/reporters.coffee +61 -0
  5. data/coffeescripts/shuriken/test.coffee +117 -0
  6. data/coffeescripts/shuriken.coffee +2 -2
  7. data/javascripts/shuriken/mixins/callbacks.js +45 -0
  8. data/javascripts/shuriken/mixins.js +58 -0
  9. data/javascripts/shuriken/test/assertions.js +117 -0
  10. data/javascripts/shuriken/test/reporters.js +84 -0
  11. data/javascripts/shuriken/test.js +165 -0
  12. data/javascripts/shuriken.js +195 -0
  13. data/lib/shuriken.rb +1 -1
  14. data/shuriken.gemspec +84 -4
  15. data/tests/basic_namespace_tests.coffee +114 -0
  16. data/tests/template.erb +26 -0
  17. data/tests.watchr +6 -0
  18. data/vendor/jasmine-0.10.0/MIT.LICENSE +20 -0
  19. data/vendor/jasmine-0.10.0/README.markdown +437 -0
  20. data/vendor/jasmine-0.10.0/doc/files.html +460 -0
  21. data/vendor/jasmine-0.10.0/doc/index.html +322 -0
  22. data/vendor/jasmine-0.10.0/doc/symbols/_global_.html +918 -0
  23. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Block.html +417 -0
  24. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Clock.html +678 -0
  25. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Env.html +1169 -0
  26. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.JsApiReporter.html +822 -0
  27. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Matchers.html +1461 -0
  28. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.MultiReporter.html +394 -0
  29. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.NestedResults.html +710 -0
  30. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Reporter.html +574 -0
  31. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Runner.html +710 -0
  32. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spec.html +1259 -0
  33. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spy.html +855 -0
  34. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Suite.html +705 -0
  35. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.html +1345 -0
  36. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.util.html +535 -0
  37. data/vendor/jasmine-0.10.0/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
  38. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Block.js.html +29 -0
  39. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Env.js.html +240 -0
  40. data/vendor/jasmine-0.10.0/doc/symbols/src/src_JsApiReporter.js.html +111 -0
  41. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Matchers.js.html +328 -0
  42. data/vendor/jasmine-0.10.0/doc/symbols/src/src_MultiReporter.js.html +36 -0
  43. data/vendor/jasmine-0.10.0/doc/symbols/src/src_NestedResults.js.html +88 -0
  44. data/vendor/jasmine-0.10.0/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
  45. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Queue.js.html +102 -0
  46. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporter.js.html +35 -0
  47. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporters.js.html +51 -0
  48. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Runner.js.html +75 -0
  49. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Spec.js.html +211 -0
  50. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Suite.js.html +77 -0
  51. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  52. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  53. data/vendor/jasmine-0.10.0/doc/symbols/src/src_base.js.html +555 -0
  54. data/vendor/jasmine-0.10.0/doc/symbols/src/src_mock-timeout.js.html +185 -0
  55. data/vendor/jasmine-0.10.0/doc/symbols/src/src_util.js.html +75 -0
  56. data/vendor/jasmine-0.10.0/example/example_runner.html +25 -0
  57. data/vendor/jasmine-0.10.0/example/spec/example_suite.js +11 -0
  58. data/vendor/jasmine-0.10.0/lib/TrivialReporter.js +117 -0
  59. data/vendor/jasmine-0.10.0/lib/consolex.js +28 -0
  60. data/vendor/jasmine-0.10.0/lib/jasmine-0.10.0.js +2261 -0
  61. data/vendor/jasmine-0.10.0/lib/jasmine.css +86 -0
  62. data/vendor/jasmine-0.10.0/spec/runner.html +63 -0
  63. data/vendor/jasmine-0.10.0/spec/suites/CustomMatchersSpec.js +112 -0
  64. data/vendor/jasmine-0.10.0/spec/suites/EnvSpec.js +71 -0
  65. data/vendor/jasmine-0.10.0/spec/suites/ExceptionsSpec.js +107 -0
  66. data/vendor/jasmine-0.10.0/spec/suites/JsApiReporterSpec.js +82 -0
  67. data/vendor/jasmine-0.10.0/spec/suites/MatchersSpec.js +589 -0
  68. data/vendor/jasmine-0.10.0/spec/suites/MockClockSpec.js +34 -0
  69. data/vendor/jasmine-0.10.0/spec/suites/MultiReporterSpec.js +30 -0
  70. data/vendor/jasmine-0.10.0/spec/suites/NestedResultsSpec.js +54 -0
  71. data/vendor/jasmine-0.10.0/spec/suites/PrettyPrintSpec.js +93 -0
  72. data/vendor/jasmine-0.10.0/spec/suites/QueueSpec.js +23 -0
  73. data/vendor/jasmine-0.10.0/spec/suites/ReporterSpec.js +60 -0
  74. data/vendor/jasmine-0.10.0/spec/suites/RunnerSpec.js +258 -0
  75. data/vendor/jasmine-0.10.0/spec/suites/SpecRunningSpec.js +1086 -0
  76. data/vendor/jasmine-0.10.0/spec/suites/SpecSpec.js +110 -0
  77. data/vendor/jasmine-0.10.0/spec/suites/SpySpec.js +187 -0
  78. data/vendor/jasmine-0.10.0/spec/suites/SuiteSpec.js +101 -0
  79. data/vendor/jasmine-0.10.0/spec/suites/TrivialReporterSpec.js +140 -0
  80. data/vendor/jasmine-0.10.0/spec/suites/UtilSpec.js +23 -0
  81. data/vendor/jquery.js +154 -0
  82. data/wip-coffeescripts/example_test.coffee +0 -0
  83. data/wip-coffeescripts/test/assertions.coffee +111 -0
  84. data/wip-coffeescripts/test/reporters.coffee +61 -0
  85. data/wip-coffeescripts/test.coffee +96 -15
  86. metadata +83 -4
@@ -0,0 +1,1086 @@
1
+ describe("jasmine spec running", function () {
2
+ var env;
3
+ var fakeTimer;
4
+
5
+ beforeEach(function() {
6
+ env = new jasmine.Env();
7
+ env.updateInterval = 0;
8
+
9
+ fakeTimer = new jasmine.FakeTimer();
10
+ env.setTimeout = fakeTimer.setTimeout;
11
+ env.clearTimeout = fakeTimer.clearTimeout;
12
+ env.setInterval = fakeTimer.setInterval;
13
+ env.clearInterval = fakeTimer.clearInterval;
14
+ });
15
+
16
+ it('should assign spec ids sequentially', function() {
17
+ var it0, it1, it2, it3, it4;
18
+ env.describe('test suite', function() {
19
+ it0 = env.it('spec 0', function() {
20
+ });
21
+ it1 = env.it('spec 1', function() {
22
+ });
23
+ it2 = env.xit('spec 2', function() {
24
+ });
25
+ it3 = env.it('spec 3', function() {
26
+ });
27
+ });
28
+ env.describe('test suite 2', function() {
29
+ it4 = env.it('spec 4', function() {
30
+ });
31
+ });
32
+
33
+ expect(it0.id).toEqual(0);
34
+ expect(it1.id).toEqual(1);
35
+ expect(it2.id).toEqual(2);
36
+ expect(it3.id).toEqual(3);
37
+ expect(it4.id).toEqual(4);
38
+ });
39
+
40
+ it("should build up some objects with results we can inspect", function() {
41
+
42
+ var specWithNoBody, specWithExpectation, specWithFailingExpectations, specWithMultipleExpectations;
43
+
44
+ var suite = env.describe('default current suite', function() {
45
+ specWithNoBody = env.it('new spec');
46
+
47
+ specWithExpectation = env.it('spec with an expectation').runs(function () {
48
+ var foo = 'bar';
49
+ this.expect(foo).toEqual('bar');
50
+ });
51
+
52
+ specWithFailingExpectations = env.it('spec with failing expectation').runs(function () {
53
+ var foo = 'bar';
54
+ this.expect(foo).toEqual('baz');
55
+ });
56
+
57
+ specWithMultipleExpectations = env.it('spec with multiple assertions').runs(function () {
58
+ var foo = 'bar';
59
+ var baz = 'quux';
60
+
61
+ this.expect(foo).toEqual('bar');
62
+ this.expect(baz).toEqual('quux');
63
+ });
64
+ });
65
+
66
+ suite.execute();
67
+
68
+ expect(specWithNoBody.description).toEqual('new spec');
69
+
70
+ expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed"
71
+ expect(specWithExpectation.results().getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true"
72
+ expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description"
73
+
74
+ expect(specWithFailingExpectations.results().getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed"
75
+
76
+ expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations"
77
+ });
78
+
79
+ it("should work without a runs block", function() {
80
+ var another_spec;
81
+ env.describe('default current suite', function() {
82
+ another_spec = env.it('spec with an expectation', function () {
83
+ var foo = 'bar';
84
+ this.expect(foo).toEqual('bar');
85
+ this.expect(foo).toEqual('baz');
86
+ });
87
+ });
88
+
89
+ another_spec.execute();
90
+ another_spec.done = true;
91
+
92
+ expect(another_spec.results().getItems().length).toEqual(2);
93
+ expect(another_spec.results().getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false"
94
+ expect(another_spec.results().getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true";
95
+ expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description";
96
+ });
97
+
98
+ it('should queue waits and runs that it encounters while executing specs', function() {
99
+ var specWithRunsAndWaits;
100
+ var foo = 0;
101
+ env.describe('test async spec', function() {
102
+ specWithRunsAndWaits = env.it('spec w/ queued statments', function () {
103
+ this.runs(function () {
104
+ foo++;
105
+ });
106
+ this.waits(500);
107
+ this.runs(function () {
108
+ foo++;
109
+ });
110
+ this.waits(500);
111
+ this.runs(function () {
112
+ foo++;
113
+ });
114
+ });
115
+ });
116
+
117
+ expect(foo).toEqual(0);
118
+ specWithRunsAndWaits.execute();
119
+
120
+ expect(foo).toEqual(1);
121
+ fakeTimer.tick(500);
122
+ expect(foo).toEqual(2);
123
+ fakeTimer.tick(500);
124
+ expect(foo).toEqual(3);
125
+ });
126
+
127
+ it("should run asynchronous tests", function () {
128
+ var foo = 0;
129
+
130
+ var a_spec;
131
+ env.describe('test async spec', function() {
132
+ a_spec = env.it('spec w/ queued statments', function () {
133
+ this.runs(function () {
134
+ foo++;
135
+ });
136
+ this.runs(function () {
137
+ this.expect(foo).toEqual(1);
138
+ });
139
+ });
140
+ });
141
+
142
+ a_spec.execute();
143
+
144
+ expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions';
145
+ expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed';
146
+
147
+ foo = 0;
148
+ env.describe('test async spec', function() {
149
+ a_spec = env.it('spec w/ queued statments', function () {
150
+ this.runs(function () {
151
+ fakeTimer.setTimeout(function() {
152
+ foo++;
153
+ }, 500);
154
+ });
155
+ this.waits(1000);
156
+ this.runs(function() {
157
+ this.expect(foo).toEqual(1);
158
+ });
159
+ });
160
+ });
161
+
162
+ a_spec.execute();
163
+
164
+ expect(a_spec.results().getItems().length).toEqual(0);
165
+
166
+ fakeTimer.tick(500);
167
+ expect(a_spec.results().getItems().length).toEqual(0);
168
+
169
+ fakeTimer.tick(500);
170
+ expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions';
171
+
172
+ expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed';
173
+
174
+ var bar = 0;
175
+ var another_spec;
176
+ env.describe('test async spec', function() {
177
+ another_spec = env.it('spec w/ queued statments', function () {
178
+ this.runs(function () {
179
+ fakeTimer.setTimeout(function() {
180
+ bar++;
181
+ }, 250);
182
+
183
+ });
184
+ this.waits(500);
185
+ this.runs(function () {
186
+ fakeTimer.setTimeout(function() {
187
+ bar++;
188
+ }, 250);
189
+ });
190
+ this.waits(500);
191
+ this.runs(function () {
192
+ this.expect(bar).toEqual(2);
193
+ });
194
+ });
195
+ });
196
+
197
+
198
+ another_spec.execute();
199
+
200
+ fakeTimer.tick(1000);
201
+
202
+ expect(another_spec.results().getItems().length).toEqual(1);
203
+ expect(another_spec.results().getItems()[0].passed()).toEqual(true);
204
+
205
+ var baz = 0;
206
+ var yet_another_spec;
207
+ env.describe('test async spec', function() {
208
+ yet_another_spec = env.it('spec w/ async fail', function () {
209
+ this.runs(function () {
210
+ fakeTimer.setTimeout(function() {
211
+ baz++;
212
+ }, 250);
213
+ });
214
+ this.waits(100);
215
+ this.runs(function() {
216
+ this.expect(baz).toEqual(1);
217
+ });
218
+ });
219
+ });
220
+
221
+
222
+ yet_another_spec.execute();
223
+ //tick twice so that second runs gets eval'd first: mockClock bug?
224
+ fakeTimer.tick(100);
225
+ fakeTimer.tick(150);
226
+
227
+
228
+ expect(yet_another_spec.results().getItems().length).toEqual(1);
229
+ expect(yet_another_spec.results().getItems()[0].passed()).toEqual(false);
230
+ });
231
+
232
+ it("testAsyncSpecsWithMockSuite", function () {
233
+ var bar = 0;
234
+ var another_spec;
235
+ env.describe('test async spec', function() {
236
+ another_spec = env.it('spec w/ queued statments', function () {
237
+ this.runs(function () {
238
+ fakeTimer.setTimeout(function() {
239
+ bar++;
240
+ }, 250);
241
+ });
242
+ this.waits(500);
243
+ this.runs(function () {
244
+ fakeTimer.setTimeout(function() {
245
+ bar++;
246
+ }, 250);
247
+ });
248
+ this.waits(1500);
249
+ this.runs(function() {
250
+ this.expect(bar).toEqual(2);
251
+ });
252
+ });
253
+ });
254
+
255
+ another_spec.execute();
256
+ fakeTimer.tick(2000);
257
+ expect(another_spec.results().getItems().length).toEqual(1);
258
+ expect(another_spec.results().getItems()[0].passed()).toEqual(true);
259
+ });
260
+
261
+ it("testWaitsFor", function() {
262
+ var doneWaiting = false;
263
+ var runsBlockExecuted = false;
264
+
265
+ var spec;
266
+ env.describe('foo', function() {
267
+ spec = env.it('has a waits for', function() {
268
+ this.runs(function() {
269
+ });
270
+
271
+ this.waitsFor(500, function() {
272
+ return doneWaiting;
273
+ });
274
+
275
+ this.runs(function() {
276
+ runsBlockExecuted = true;
277
+ });
278
+ });
279
+ });
280
+
281
+ spec.execute();
282
+ expect(runsBlockExecuted).toEqual(false); //, 'should not have executed runs block yet');
283
+ fakeTimer.tick(100);
284
+ doneWaiting = true;
285
+ fakeTimer.tick(100);
286
+ expect(runsBlockExecuted).toEqual(true); //, 'should have executed runs block');
287
+ });
288
+
289
+ it("testWaitsForFailsWithMessage", function() {
290
+ var spec;
291
+ env.describe('foo', function() {
292
+ spec = env.it('has a waits for', function() {
293
+ this.runs(function() {
294
+ });
295
+
296
+ this.waitsFor(500, function() {
297
+ return false; // force a timeout
298
+ }, 'my awesome condition');
299
+
300
+ this.runs(function() {
301
+ });
302
+ });
303
+ });
304
+
305
+ spec.execute();
306
+ fakeTimer.tick(1000);
307
+ var actual = spec.results().getItems()[0].message;
308
+ var expected = 'timeout: timed out after 500 msec waiting for my awesome condition';
309
+ expect(actual).toEqual(expected);
310
+ });
311
+
312
+ it("waitsFor fails and skips the rest of the spec if timeout is reached and the latch function is still false", function() {
313
+ var runsBlockExecuted = false;
314
+
315
+ var spec;
316
+ env.describe('foo', function() {
317
+ spec = env.it('has a waits for', function() {
318
+ this.runs(function() {
319
+ });
320
+
321
+ this.waitsFor(500, function() {
322
+ return false;
323
+ });
324
+
325
+ this.runs(function() {
326
+ runsBlockExecuted = true;
327
+ });
328
+ });
329
+ });
330
+
331
+ spec.execute();
332
+ expect(runsBlockExecuted).toEqual(false);
333
+ fakeTimer.tick(100);
334
+ expect(runsBlockExecuted).toEqual(false);
335
+ fakeTimer.tick(400);
336
+ expect(runsBlockExecuted).toEqual(false);
337
+ var actual = spec.results().getItems()[0].message;
338
+ var expected = 'timeout: timed out after 500 msec waiting for something to happen';
339
+ expect(actual).toEqual(expected,
340
+ 'expected "' + expected + '" but found "' + actual + '"');
341
+ });
342
+
343
+ it("testSpecAfter", function() {
344
+ var log = "";
345
+ var spec;
346
+ var suite = env.describe("has after", function() {
347
+ spec = env.it('spec with after', function() {
348
+ this.runs(function() {
349
+ log += "spec";
350
+ });
351
+ });
352
+ });
353
+ spec.after(function() {
354
+ log += "after1";
355
+ });
356
+ spec.after(function() {
357
+ log += "after2";
358
+ });
359
+
360
+ suite.execute();
361
+
362
+ expect(log).toEqual("specafter2after1");
363
+ });
364
+
365
+ describe('test suite declaration', function() {
366
+ var suite;
367
+ var dummyFunction = function() {
368
+ };
369
+
370
+ it('should give the suite a description', function() {
371
+ suite = env.describe('one suite description', dummyFunction);
372
+ expect(suite.description).toEqual('one suite description');
373
+ });
374
+
375
+ it('should enqueue functions for multipart tests and support waits, and run any ready runs() blocks', function() {
376
+ var foo = 0;
377
+ var bar = 0;
378
+
379
+ suite = env.describe('one suite description', function () {
380
+ env.it('should be a test with queuedFunctions', function() {
381
+ this.runs(function() {
382
+ foo++;
383
+ });
384
+ this.waits(100);
385
+ this.runs(function() {
386
+ bar++;
387
+ });
388
+ });
389
+ });
390
+
391
+ suite.execute();
392
+
393
+ expect(foo).toEqual(1);
394
+ expect(bar).toEqual(0);
395
+
396
+ fakeTimer.tick(100);
397
+ expect(bar).toEqual(1);
398
+ });
399
+
400
+ });
401
+
402
+ it("testBeforeAndAfterCallbacks", function () {
403
+ var suiteWithBefore = env.describe('one suite with a before', function () {
404
+
405
+ this.beforeEach(function () {
406
+ this.foo = 1;
407
+ });
408
+
409
+ env.it('should be a spec', function () {
410
+ this.runs(function() {
411
+ this.foo++;
412
+ this.expect(this.foo).toEqual(2);
413
+ });
414
+ });
415
+
416
+ env.it('should be another spec', function () {
417
+ this.runs(function() {
418
+ this.foo++;
419
+ this.expect(this.foo).toEqual(2);
420
+ });
421
+ });
422
+ });
423
+
424
+ suiteWithBefore.execute();
425
+
426
+ var suite = suiteWithBefore;
427
+
428
+ expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
429
+ expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
430
+
431
+
432
+ var foo = 1;
433
+ var suiteWithAfter = env.describe('one suite with an after_each', function () {
434
+
435
+ env.it('should be a spec with an after_each', function () {
436
+ this.expect(foo).toEqual(1);
437
+ foo++;
438
+ this.expect(foo).toEqual(2);
439
+ });
440
+
441
+ env.it('should be another spec with an after_each', function () {
442
+ this.expect(foo).toEqual(0);
443
+ foo++;
444
+ this.expect(foo).toEqual(1);
445
+ });
446
+
447
+ this.afterEach(function () {
448
+ foo = 0;
449
+ });
450
+ });
451
+
452
+ suiteWithAfter.execute();
453
+
454
+ suite = suiteWithAfter;
455
+ expect(suite.afterEach.length).toEqual(1);
456
+ expect(suite.results().getItems()[0].passed()).toEqual(true);
457
+ expect(suite.results().getItems()[1].passed()).toEqual(true);
458
+ expect(foo).toEqual(0);
459
+
460
+ });
461
+
462
+ it('#waits should allow consecutive waits calls', function () {
463
+ var foo = 0;
464
+ var waitsSuite = env.describe('suite that waits', function () {
465
+ env.it('should wait', function() {
466
+ this.waits(500);
467
+ this.waits(500);
468
+ this.runs(function () {
469
+ foo++;
470
+ });
471
+ });
472
+ });
473
+
474
+ waitsSuite.execute();
475
+ expect(foo).toEqual(0);
476
+ fakeTimer.tick(500);
477
+ expect(foo).toEqual(0);
478
+ fakeTimer.tick(500);
479
+
480
+ expect(foo).toEqual(1);
481
+ });
482
+
483
+ it('nested suites', function () {
484
+
485
+ var foo = 0;
486
+ var bar = 0;
487
+ var baz = 0;
488
+ var quux = 0;
489
+ var nested = env.describe('suite', function () {
490
+ env.describe('nested', function () {
491
+ env.it('should run nested suites', function () {
492
+ foo++;
493
+ });
494
+ env.it('should run nested suites', function () {
495
+ bar++;
496
+ });
497
+ });
498
+
499
+ env.describe('nested 2', function () {
500
+ env.it('should run suites following nested suites', function () {
501
+ baz++;
502
+ });
503
+ });
504
+
505
+ env.it('should run tests following nested suites', function () {
506
+ quux++;
507
+ });
508
+ });
509
+
510
+ expect(foo).toEqual(0);
511
+ expect(bar).toEqual(0);
512
+ expect(baz).toEqual(0);
513
+ expect(quux).toEqual(0);
514
+ nested.execute();
515
+
516
+ expect(foo).toEqual(1);
517
+ expect(bar).toEqual(1);
518
+ expect(baz).toEqual(1);
519
+ expect(quux).toEqual(1);
520
+ });
521
+
522
+ describe('#waitsFor should allow consecutive calls', function () {
523
+
524
+ var foo;
525
+ beforeEach(function () {
526
+
527
+ foo = 0;
528
+ });
529
+
530
+ it('exits immediately (does not stack) if the latchFunction times out', function () {
531
+ var reachedFirstWaitsFor = false;
532
+ var reachedSecondWaitsFor = false;
533
+ var waitsSuite = env.describe('suite that waits', function () {
534
+ env.it('should stack timeouts', function() {
535
+ this.waitsFor(500, function () {
536
+ reachedFirstWaitsFor = true;
537
+ return false;
538
+ });
539
+ this.waitsFor(500, function () {
540
+ reachedSecondWaitsFor = true;
541
+ });
542
+ this.runs(function () {
543
+ foo++;
544
+ });
545
+ });
546
+ });
547
+
548
+ expect(reachedFirstWaitsFor).toEqual(false);
549
+ waitsSuite.execute();
550
+
551
+ expect(reachedFirstWaitsFor).toEqual(true);
552
+ expect(foo).toEqual(0);
553
+ expect(reachedSecondWaitsFor).toEqual(false);
554
+ fakeTimer.tick(500);
555
+ expect(reachedSecondWaitsFor).toEqual(false);
556
+ expect(foo).toEqual(0);
557
+ fakeTimer.tick(500);
558
+ expect(reachedSecondWaitsFor).toEqual(false);
559
+ expect(foo).toEqual(0);
560
+ });
561
+
562
+ it('stacks latchFunctions', function () {
563
+ var firstWaitsResult = false;
564
+ var secondWaitsResult = false;
565
+ var waitsSuite = env.describe('suite that waits', function () {
566
+ env.it('spec with waitsFors', function() {
567
+ this.waitsFor(600, function () {
568
+ fakeTimer.setTimeout(function () {
569
+ firstWaitsResult = true;
570
+ }, 300);
571
+ return firstWaitsResult;
572
+ });
573
+ this.waitsFor(600, function () {
574
+ fakeTimer.setTimeout(function () {
575
+ secondWaitsResult = true;
576
+ }, 300);
577
+ return secondWaitsResult;
578
+ });
579
+ this.runs(function () {
580
+ foo++;
581
+ });
582
+ });
583
+ });
584
+
585
+ expect(firstWaitsResult).toEqual(false);
586
+ expect(secondWaitsResult).toEqual(false);
587
+ waitsSuite.execute();
588
+
589
+ expect(firstWaitsResult).toEqual(false);
590
+ expect(secondWaitsResult).toEqual(false);
591
+ expect(foo).toEqual(0);
592
+
593
+ fakeTimer.tick(300);
594
+
595
+ expect(firstWaitsResult).toEqual(true);
596
+ expect(secondWaitsResult).toEqual(false);
597
+ expect(foo).toEqual(0);
598
+
599
+ fakeTimer.tick(300);
600
+
601
+ expect(firstWaitsResult).toEqual(true);
602
+ expect(secondWaitsResult).toEqual(true);
603
+ expect(foo).toEqual(1);
604
+
605
+ });
606
+ });
607
+
608
+ it("#beforeEach should be able to eval runs and waits blocks", function () {
609
+ var foo = 0;
610
+ var bar = 0;
611
+ var suiteWithBefore = env.describe('one suite with a before', function () {
612
+ this.beforeEach(function () {
613
+ this.runs(function () {
614
+ foo++;
615
+ });
616
+ this.waits(500);
617
+ this.runs(function () {
618
+ foo++;
619
+ });
620
+ this.waits(500);
621
+ });
622
+
623
+ env.it('should be a spec', function () {
624
+ bar = 1;
625
+ foo++;
626
+ });
627
+
628
+ });
629
+
630
+ expect(foo).toEqual(0);
631
+ expect(bar).toEqual(0);
632
+ suiteWithBefore.execute();
633
+
634
+ expect(bar).toEqual(0);
635
+ expect(foo).toEqual(1);
636
+ fakeTimer.tick(500);
637
+
638
+ expect(bar).toEqual(0);
639
+ expect(foo).toEqual(2);
640
+ fakeTimer.tick(500);
641
+ expect(bar).toEqual(1);
642
+ expect(foo).toEqual(3);
643
+ });
644
+
645
+ it("#afterEach should be able to eval runs and waits blocks", function () {
646
+ var foo = 0;
647
+ var firstSpecHasRun = false;
648
+ var secondSpecHasRun = false;
649
+ var suiteWithAfter = env.describe('one suite with a before', function () {
650
+ this.afterEach(function () {
651
+ this.waits(500);
652
+ this.runs(function () {
653
+ foo++;
654
+ });
655
+ this.waits(500);
656
+ });
657
+
658
+ env.it('should be the first spec', function () {
659
+ firstSpecHasRun = true;
660
+ });
661
+
662
+ env.it('should be a spec', function () {
663
+ secondSpecHasRun = true;
664
+ foo++;
665
+ });
666
+
667
+ });
668
+
669
+ expect(firstSpecHasRun).toEqual(false);
670
+ expect(secondSpecHasRun).toEqual(false);
671
+ expect(foo).toEqual(0);
672
+
673
+ suiteWithAfter.execute();
674
+
675
+
676
+ expect(firstSpecHasRun).toEqual(true);
677
+ expect(secondSpecHasRun).toEqual(false);
678
+ expect(foo).toEqual(0);
679
+
680
+ fakeTimer.tick(500);
681
+
682
+ expect(foo).toEqual(1);
683
+ expect(secondSpecHasRun).toEqual(false);
684
+ fakeTimer.tick(500);
685
+
686
+ expect(foo).toEqual(2);
687
+ expect(secondSpecHasRun).toEqual(true);
688
+
689
+ });
690
+
691
+ it("Spec#after should be able to eval runs and waits blocks", function () {
692
+ var runsBeforeAfter = false;
693
+ var firstSpecHasRun = false;
694
+ var secondSpecHasRun = false;
695
+ var afterHasRun = false;
696
+ var suiteWithAfter = env.describe('one suite with a before', function () {
697
+
698
+ env.it('should be the first spec', function () {
699
+ firstSpecHasRun = true;
700
+ this.after(function () {
701
+ this.waits(500);
702
+ this.runs(function () {
703
+ afterHasRun = true;
704
+ });
705
+ this.waits(500);
706
+ }, true);
707
+ this.waits(500);
708
+ this.runs(function () {
709
+ runsBeforeAfter = true;
710
+ });
711
+ });
712
+
713
+ env.it('should be a spec', function () {
714
+ secondSpecHasRun = true;
715
+ });
716
+
717
+ });
718
+
719
+ expect(firstSpecHasRun).toEqual(false);
720
+ expect(runsBeforeAfter).toEqual(false);
721
+ expect(afterHasRun).toEqual(false);
722
+ expect(secondSpecHasRun).toEqual(false);
723
+
724
+ suiteWithAfter.execute();
725
+
726
+ expect(firstSpecHasRun).toEqual(true);
727
+ expect(runsBeforeAfter).toEqual(false);
728
+ expect(afterHasRun).toEqual(false);
729
+ expect(secondSpecHasRun).toEqual(false);
730
+
731
+ fakeTimer.tick(500);
732
+
733
+ expect(firstSpecHasRun).toEqual(true);
734
+ expect(runsBeforeAfter).toEqual(true);
735
+ expect(afterHasRun).toEqual(false);
736
+ expect(secondSpecHasRun).toEqual(false);
737
+
738
+ fakeTimer.tick(500);
739
+
740
+ expect(firstSpecHasRun).toEqual(true);
741
+ expect(runsBeforeAfter).toEqual(true);
742
+ expect(afterHasRun).toEqual(true);
743
+ expect(secondSpecHasRun).toEqual(false);
744
+
745
+ fakeTimer.tick(500);
746
+
747
+ expect(firstSpecHasRun).toEqual(true);
748
+ expect(runsBeforeAfter).toEqual(true);
749
+ expect(afterHasRun).toEqual(true);
750
+ expect(secondSpecHasRun).toEqual(true);
751
+ });
752
+
753
+ it("handles waits", function () {
754
+ var firstSpecHasRun = false;
755
+ var secondSpecHasRun = false;
756
+ var suiteWithAfter = env.describe('one suite with a before', function () {
757
+
758
+ env.it('should be the first spec', function () {
759
+ this.waits(500);
760
+ this.runs(function () {
761
+ firstSpecHasRun = true;
762
+ });
763
+ });
764
+
765
+ env.it('should be a spec', function () {
766
+ secondSpecHasRun = true;
767
+ });
768
+
769
+ });
770
+
771
+ expect(firstSpecHasRun).toEqual(false);
772
+ expect(secondSpecHasRun).toEqual(false);
773
+
774
+ suiteWithAfter.execute();
775
+
776
+ expect(firstSpecHasRun).toEqual(false);
777
+ expect(secondSpecHasRun).toEqual(false);
778
+
779
+ fakeTimer.tick(500);
780
+
781
+ expect(firstSpecHasRun).toEqual(true);
782
+ expect(secondSpecHasRun).toEqual(true);
783
+ });
784
+
785
+ it("testBeforeExecutesSafely", function() {
786
+ var report = "";
787
+ var suite = env.describe('before fails on first test, passes on second', function() {
788
+ var counter = 0;
789
+ this.beforeEach(function() {
790
+ counter++;
791
+ if (counter == 1) {
792
+ throw "before failure";
793
+ }
794
+ });
795
+ env.it("first should not run because before fails", function() {
796
+ this.runs(function() {
797
+ report += "first";
798
+ this.expect(true).toEqual(true);
799
+ });
800
+ });
801
+ env.it("second should run and pass because before passes", function() {
802
+ this.runs(function() {
803
+ report += "second";
804
+ this.expect(true).toEqual(true);
805
+ });
806
+ });
807
+ });
808
+
809
+ suite.execute();
810
+
811
+ expect(report).toEqual("firstsecond");
812
+ var suiteResults = suite.results();
813
+ expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
814
+ expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true);
815
+ });
816
+
817
+ it("testAfterExecutesSafely", function() {
818
+ var report = "";
819
+ var suite = env.describe('after fails on first test, then passes', function() {
820
+ var counter = 0;
821
+ this.afterEach(function() {
822
+ counter++;
823
+ if (counter == 1) {
824
+ throw "after failure";
825
+ }
826
+ });
827
+ env.it("first should run, expectation passes, but spec fails because after fails", function() {
828
+ this.runs(function() {
829
+ report += "first";
830
+ this.expect(true).toEqual(true);
831
+ });
832
+ });
833
+ env.it("second should run and pass because after passes", function() {
834
+ this.runs(function() {
835
+ report += "second";
836
+ this.expect(true).toEqual(true);
837
+ });
838
+ });
839
+ env.it("third should run and pass because after passes", function() {
840
+ this.runs(function() {
841
+ report += "third";
842
+ this.expect(true).toEqual(true);
843
+ });
844
+ });
845
+ });
846
+
847
+ suite.execute();
848
+
849
+ expect(report).toEqual("firstsecondthird"); // "all tests should run");
850
+ //After each errors should not go in spec results because it confuses the count.
851
+ var suiteResults = suite.results();
852
+ expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
853
+
854
+ expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
855
+ expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
856
+ expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
857
+
858
+ expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
859
+ expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
860
+ expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
861
+ expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
862
+ });
863
+
864
+ it("testNestedDescribes", function() {
865
+ var actions = [];
866
+
867
+ env.beforeEach(function () {
868
+ actions.push('runner beforeEach');
869
+ });
870
+
871
+ env.afterEach(function () {
872
+ actions.push('runner afterEach');
873
+ });
874
+
875
+ env.describe('Something', function() {
876
+ env.beforeEach(function() {
877
+ actions.push('outer beforeEach');
878
+ });
879
+
880
+ env.afterEach(function() {
881
+ actions.push('outer afterEach');
882
+ });
883
+
884
+ env.it('does it 1', function() {
885
+ actions.push('outer it 1');
886
+ });
887
+
888
+ env.describe('Inner 1', function() {
889
+ env.beforeEach(function() {
890
+ actions.push('inner 1 beforeEach');
891
+ });
892
+
893
+ env.afterEach(function() {
894
+ actions.push('inner 1 afterEach');
895
+ });
896
+
897
+ env.it('does it 2', function() {
898
+ actions.push('inner 1 it');
899
+ });
900
+ });
901
+
902
+ env.it('does it 3', function() {
903
+ actions.push('outer it 2');
904
+ });
905
+
906
+ env.describe('Inner 2', function() {
907
+ env.beforeEach(function() {
908
+ actions.push('inner 2 beforeEach');
909
+ });
910
+
911
+ env.afterEach(function() {
912
+ actions.push('inner 2 afterEach');
913
+ });
914
+
915
+ env.it('does it 2', function() {
916
+ actions.push('inner 2 it');
917
+ });
918
+ });
919
+ });
920
+
921
+ env.execute();
922
+
923
+
924
+ var expected = [
925
+ "runner beforeEach",
926
+ "outer beforeEach",
927
+ "outer it 1",
928
+ "outer afterEach",
929
+ "runner afterEach",
930
+
931
+ "runner beforeEach",
932
+ "outer beforeEach",
933
+ "inner 1 beforeEach",
934
+ "inner 1 it",
935
+ "inner 1 afterEach",
936
+ "outer afterEach",
937
+ "runner afterEach",
938
+
939
+ "runner beforeEach",
940
+ "outer beforeEach",
941
+ "outer it 2",
942
+ "outer afterEach",
943
+ "runner afterEach",
944
+
945
+ "runner beforeEach",
946
+ "outer beforeEach",
947
+ "inner 2 beforeEach",
948
+ "inner 2 it",
949
+ "inner 2 afterEach",
950
+ "outer afterEach",
951
+ "runner afterEach"
952
+ ];
953
+ expect(actions).toEqual(expected);
954
+ });
955
+
956
+ it("builds up nested names", function() {
957
+ var nestedSpec;
958
+ env.describe('Test Subject', function() {
959
+ env.describe('when under circumstance A', function() {
960
+ env.describe('and circumstance B', function() {
961
+ nestedSpec = env.it('behaves thusly', function() {
962
+ });
963
+ });
964
+ });
965
+ });
966
+
967
+ expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
968
+ });
969
+
970
+ it("should skip empty suites", function () {
971
+ env.describe('NonEmptySuite1', function() {
972
+ env.it('should pass', function() {
973
+ this.expect(true).toEqual(true);
974
+ });
975
+ env.describe('NestedEmptySuite', function() {
976
+ });
977
+ env.it('should pass', function() {
978
+ this.expect(true).toEqual(true);
979
+ });
980
+ });
981
+
982
+ env.describe('EmptySuite', function() {
983
+ });
984
+
985
+ env.describe('NonEmptySuite2', function() {
986
+ env.it('should pass', function() {
987
+ this.expect(true).toEqual(true);
988
+ });
989
+ });
990
+
991
+ env.execute();
992
+
993
+ var runnerResults = env.currentRunner_.results();
994
+ expect(runnerResults.totalCount).toEqual(3);
995
+ expect(runnerResults.passedCount).toEqual(3);
996
+ expect(runnerResults.failedCount).toEqual(0);
997
+ });
998
+
999
+ it("should bind 'this' to the running spec within the spec body", function() {
1000
+ var spec;
1001
+ var suite = env.describe('one suite description', function () {
1002
+ env.it('should be a test with queuedFunctions', function() {
1003
+ spec = this.runs(function() {
1004
+ this.foo = 0;
1005
+ this.foo++;
1006
+ });
1007
+
1008
+ this.runs(function() {
1009
+ var that = this;
1010
+ fakeTimer.setTimeout(function() {
1011
+ that.foo++;
1012
+ }, 250);
1013
+ });
1014
+
1015
+ this.runs(function() {
1016
+ this.expect(this.foo).toEqual(2);
1017
+ });
1018
+
1019
+ this.waits(300);
1020
+
1021
+ this.runs(function() {
1022
+ this.expect(this.foo).toEqual(2);
1023
+ });
1024
+ });
1025
+
1026
+ });
1027
+
1028
+ suite.execute();
1029
+ fakeTimer.tick(600);
1030
+ expect(spec.foo).toEqual(2);
1031
+ var suiteResults = suite.results();
1032
+ expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
1033
+ expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
1034
+ expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true);
1035
+ });
1036
+
1037
+ it("shouldn't run disabled tests", function() {
1038
+ var xitSpecWasRun = false;
1039
+ var suite = env.describe('default current suite', function() {
1040
+ env.xit('disabled spec').runs(function () {
1041
+ xitSpecWasRun = true;
1042
+ });
1043
+
1044
+ env.it('enabled spec').runs(function () {
1045
+ var foo = 'bar';
1046
+ expect(foo).toEqual('bar');
1047
+ });
1048
+ });
1049
+
1050
+ suite.execute();
1051
+ expect(xitSpecWasRun).toEqual(false);
1052
+ });
1053
+
1054
+ it('shouldn\'t execute specs in disabled suites', function() {
1055
+ var spy = jasmine.createSpy();
1056
+ var disabledSuite = env.xdescribe('a disabled suite', function() {
1057
+ env.it('enabled spec, but should not be run', function() {
1058
+ spy();
1059
+ });
1060
+ });
1061
+
1062
+ disabledSuite.execute();
1063
+
1064
+ expect(spy).wasNotCalled();
1065
+ });
1066
+
1067
+ it('#explodes should throw an exception when it is called inside a spec', function() {
1068
+ var exceptionMessage = false;
1069
+ var anotherSuite = env.describe('Spec', function () {
1070
+ env.it('plodes', function() {
1071
+ try {
1072
+ this.explodes();
1073
+ }
1074
+ catch (e) {
1075
+ exceptionMessage = e;
1076
+ }
1077
+ expect(exceptionMessage).toNotEqual(false);
1078
+ });
1079
+ });
1080
+
1081
+ anotherSuite.execute();
1082
+
1083
+ expect(exceptionMessage).toEqual('explodes function should not have been called');
1084
+ });
1085
+
1086
+ });