jasmine-core 1.3.1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/jasmine-core.rb +14 -1
  2. data/lib/jasmine-core/boot.js +131 -0
  3. data/lib/jasmine-core/boot/boot.js +109 -0
  4. data/lib/jasmine-core/example/spec/PlayerSpec.js +2 -2
  5. data/lib/jasmine-core/example/spec/SpecHelper.js +14 -8
  6. data/lib/jasmine-core/jasmine-html.js +289 -616
  7. data/lib/jasmine-core/jasmine.css +52 -80
  8. data/lib/jasmine-core/jasmine.js +1972 -2211
  9. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +161 -386
  10. data/lib/jasmine-core/spec/core/AnySpec.js +45 -0
  11. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +105 -0
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +314 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +96 -97
  14. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +179 -0
  15. data/lib/jasmine-core/spec/core/EnvSpec.js +454 -102
  16. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +56 -0
  17. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +15 -126
  18. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  19. data/lib/jasmine-core/spec/core/ExpectationSpec.js +320 -0
  20. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +150 -38
  21. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +64 -0
  22. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +43 -42
  23. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +147 -0
  24. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +40 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +92 -1075
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +215 -95
  27. data/lib/jasmine-core/spec/core/SpySpec.js +28 -196
  28. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +101 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +216 -106
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +13 -0
  31. data/lib/jasmine-core/spec/core/UtilSpec.js +19 -30
  32. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +219 -0
  33. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +51 -0
  34. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  35. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  36. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +19 -0
  37. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  38. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +36 -0
  39. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  40. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  41. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  42. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +17 -0
  43. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +24 -0
  44. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +28 -0
  45. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +46 -0
  46. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +57 -0
  47. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +34 -0
  48. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +280 -0
  49. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +98 -0
  50. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +19 -0
  51. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +494 -0
  52. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  53. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +8 -8
  54. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +3 -3
  55. data/lib/jasmine-core/spec/html/QueryStringSpec.js +43 -0
  56. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  57. data/lib/jasmine-core/spec/node_suite.js +137 -79
  58. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  59. data/lib/jasmine-core/spec/support/dev_boot.js +118 -0
  60. data/lib/jasmine-core/version.rb +5 -2
  61. metadata +47 -103
  62. data/lib/jasmine-core/example/SpecRunner.html +0 -54
  63. data/lib/jasmine-core/spec/core/BaseSpec.js +0 -27
  64. data/lib/jasmine-core/spec/core/MatchersSpec.js +0 -1157
  65. data/lib/jasmine-core/spec/core/MockClockSpec.js +0 -38
  66. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +0 -45
  67. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +0 -54
  68. data/lib/jasmine-core/spec/core/QueueSpec.js +0 -23
  69. data/lib/jasmine-core/spec/core/ReporterSpec.js +0 -56
  70. data/lib/jasmine-core/spec/core/RunnerSpec.js +0 -280
  71. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +0 -118
  72. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +0 -209
  73. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +0 -239
@@ -0,0 +1,147 @@
1
+ describe("QueueRunner", function() {
2
+
3
+ it("runs all the functions it's passed", function() {
4
+ var calls = [],
5
+ fn1 = jasmine.createSpy('fn1'),
6
+ fn2 = jasmine.createSpy('fn2'),
7
+ queueRunner = new j$.QueueRunner({
8
+ fns: [fn1, fn2]
9
+ });
10
+ fn1.and.callFake(function() {
11
+ calls.push('fn1');
12
+ });
13
+ fn2.and.callFake(function() {
14
+ calls.push('fn2');
15
+ });
16
+
17
+ queueRunner.execute();
18
+
19
+ expect(calls).toEqual(['fn1', 'fn2']);
20
+ });
21
+
22
+ it("supports asynchronous functions, only advancing to next function after a done() callback", function() {
23
+ //TODO: it would be nice if spy arity could match the fake, so we could do something like:
24
+ //createSpy('asyncfn').and.callFake(function(done) {});
25
+
26
+ var onComplete = jasmine.createSpy('onComplete'),
27
+ beforeCallback = jasmine.createSpy('beforeCallback'),
28
+ fnCallback = jasmine.createSpy('fnCallback'),
29
+ afterCallback = jasmine.createSpy('afterCallback'),
30
+ fn1 = function(done) {
31
+ beforeCallback();
32
+ setTimeout(function() {
33
+ done()
34
+ }, 100);
35
+ },
36
+ fn2 = function(done) {
37
+ fnCallback();
38
+ setTimeout(function() {
39
+ done()
40
+ }, 100);
41
+ },
42
+ fn3 = function(done) {
43
+ afterCallback();
44
+ setTimeout(function() {
45
+ done()
46
+ }, 100);
47
+ },
48
+ queueRunner = new j$.QueueRunner({
49
+ fns: [fn1, fn2, fn3],
50
+ onComplete: onComplete
51
+ });
52
+
53
+ clock.install();
54
+
55
+ queueRunner.execute();
56
+
57
+ expect(beforeCallback).toHaveBeenCalled();
58
+ expect(fnCallback).not.toHaveBeenCalled();
59
+ expect(afterCallback).not.toHaveBeenCalled();
60
+ expect(onComplete).not.toHaveBeenCalled();
61
+
62
+ clock.tick(100);
63
+
64
+ expect(fnCallback).toHaveBeenCalled();
65
+ expect(afterCallback).not.toHaveBeenCalled();
66
+ expect(onComplete).not.toHaveBeenCalled();
67
+
68
+ clock.tick(100);
69
+
70
+ expect(afterCallback).toHaveBeenCalled();
71
+ expect(onComplete).not.toHaveBeenCalled();
72
+
73
+ clock.tick(100);
74
+
75
+ expect(onComplete).toHaveBeenCalled();
76
+ });
77
+
78
+ it("calls an exception handler when an exception is thrown in a fn", function() {
79
+ var fn = function() {
80
+ throw new Error('fake error');
81
+ },
82
+ exceptionCallback = jasmine.createSpy('exception callback'),
83
+ queueRunner = new j$.QueueRunner({
84
+ fns: [fn],
85
+ onException: exceptionCallback
86
+ });
87
+
88
+ queueRunner.execute();
89
+
90
+ expect(exceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
91
+ });
92
+
93
+ it("rethrows an exception if told to", function() {
94
+ var fn = function() {
95
+ throw new Error('fake error');
96
+ },
97
+ queueRunner = new j$.QueueRunner({
98
+ fns: [fn],
99
+ catchException: function(e) { return false; }
100
+ });
101
+
102
+ expect(function() { queueRunner.execute(); }).toThrow();
103
+ });
104
+
105
+ it("continues running the functions even after an exception is thrown in an async spec", function() {
106
+ var fn = function(done) { throw new Error("error"); },
107
+ nextFn = jasmine.createSpy("nextFunction");
108
+
109
+ queueRunner = new j$.QueueRunner({
110
+ fns: [fn, nextFn]
111
+ });
112
+
113
+ queueRunner.execute();
114
+ expect(nextFn).toHaveBeenCalled();
115
+ });
116
+
117
+ it("calls a provided complete callback when done", function() {
118
+ var fn = jasmine.createSpy('fn'),
119
+ completeCallback = jasmine.createSpy('completeCallback'),
120
+ queueRunner = new j$.QueueRunner({
121
+ fns: [fn],
122
+ onComplete: completeCallback
123
+ });
124
+
125
+ queueRunner.execute();
126
+
127
+ expect(completeCallback).toHaveBeenCalled();
128
+ });
129
+
130
+ it("calls a provided stack clearing function when done", function() {
131
+ var asyncFn = function(done) { done() },
132
+ afterFn = jasmine.createSpy('afterFn'),
133
+ completeCallback = jasmine.createSpy('completeCallback'),
134
+ clearStack = jasmine.createSpy('clearStack'),
135
+ queueRunner = new j$.QueueRunner({
136
+ fns: [asyncFn, afterFn],
137
+ clearStack: clearStack,
138
+ onComplete: completeCallback
139
+ });
140
+
141
+ clearStack.and.callFake(function(fn) { fn(); });
142
+
143
+ queueRunner.execute();
144
+ expect(afterFn).toHaveBeenCalled();
145
+ expect(clearStack).toHaveBeenCalledWith(completeCallback);
146
+ });
147
+ });
@@ -0,0 +1,40 @@
1
+ describe("ReportDispatcher", function() {
2
+
3
+ it("builds an interface of requested methods", function() {
4
+ var dispatcher = new j$.ReportDispatcher(['foo', 'bar', 'baz']);
5
+
6
+ expect(dispatcher.foo).toBeDefined();
7
+ expect(dispatcher.bar).toBeDefined();
8
+ expect(dispatcher.baz).toBeDefined();
9
+ });
10
+
11
+ it("dispatches requested methods to added reporters", function() {
12
+ var dispatcher = new j$.ReportDispatcher(['foo', 'bar']),
13
+ reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
14
+ anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
15
+
16
+ dispatcher.addReporter(reporter);
17
+ dispatcher.addReporter(anotherReporter);
18
+
19
+ dispatcher.foo(123, 456);
20
+
21
+ expect(reporter.foo).toHaveBeenCalledWith(123, 456);
22
+ expect(anotherReporter.foo).toHaveBeenCalledWith(123, 456);
23
+
24
+ dispatcher.bar('a', 'b');
25
+
26
+ expect(reporter.bar).toHaveBeenCalledWith('a', 'b');
27
+ expect(anotherReporter.bar).toHaveBeenCalledWith('a', 'b');
28
+ });
29
+
30
+ it("does not dispatch to a reporter if the reporter doesn't accept the method", function() {
31
+ var dispatcher = new j$.ReportDispatcher(['foo']),
32
+ reporter = jasmine.createSpyObj('reporter', ['baz']);
33
+
34
+ dispatcher.addReporter(reporter);
35
+
36
+ expect(function() {
37
+ dispatcher.foo(123, 456);
38
+ }).not.toThrow();
39
+ });
40
+ });
@@ -1,16 +1,11 @@
1
+ // TODO: This should really be part of the Env Integration Spec
1
2
  describe("jasmine spec running", function () {
2
3
  var env;
3
4
  var fakeTimer;
4
5
 
5
6
  beforeEach(function() {
6
- env = new jasmine.Env();
7
+ env = new j$.Env();
7
8
  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
9
  });
15
10
 
16
11
  it('should assign spec ids sequentially', function() {
@@ -37,627 +32,7 @@ describe("jasmine spec running", function () {
37
32
  expect(it4.id).toEqual(4);
38
33
  });
39
34
 
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 expectations').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
- describe("waitsFor", function() {
262
- var latchFunction = function() {
263
- return true;
264
- };
265
- var spec;
266
-
267
- function makeWaitsForSpec() {
268
- var args = jasmine.util.argsToArray(arguments);
269
- env.describe('suite', function() {
270
- spec = env.it('spec', function() {
271
- this.waitsFor.apply(this, args);
272
- });
273
- });
274
- env.execute();
275
- }
276
-
277
- it("should accept args (latchFunction, timeoutMessage, timeout)", function() {
278
- makeWaitsForSpec(latchFunction, "message", 123);
279
- var block = spec.queue.blocks[1];
280
- expect(block.latchFunction).toBe(latchFunction);
281
- expect(block.timeout).toEqual(123);
282
- expect(block.message).toEqual('message');
283
- });
284
-
285
- it("should accept args (latchFunction, timeout)", function() {
286
- makeWaitsForSpec(latchFunction, 123);
287
- var block = spec.queue.blocks[1];
288
- expect(block.latchFunction).toBe(latchFunction);
289
- expect(block.timeout).toEqual(123);
290
- expect(block.message).toEqual(null);
291
- });
292
-
293
- it("should accept args (latchFunction, timeoutMessage)", function() {
294
- env.defaultTimeoutInterval = 4321;
295
- makeWaitsForSpec(latchFunction, "message");
296
- var block = spec.queue.blocks[1];
297
- expect(block.latchFunction).toBe(latchFunction);
298
- expect(block.timeout).toEqual(4321);
299
- expect(block.message).toEqual('message');
300
- });
301
-
302
- it("should accept args (latchFunction)", function() {
303
- env.defaultTimeoutInterval = 4321;
304
- makeWaitsForSpec(latchFunction);
305
- var block = spec.queue.blocks[1];
306
- expect(block.latchFunction).toBe(latchFunction);
307
- expect(block.timeout).toEqual(4321);
308
- expect(block.message).toEqual(null);
309
- });
310
-
311
- it("should accept deprecated args order (timeout, latchFunction, timeoutMessage)", function() {
312
- makeWaitsForSpec(123, latchFunction, "message");
313
- var block = spec.queue.blocks[1];
314
- expect(block.latchFunction).toBe(latchFunction);
315
- expect(block.timeout).toEqual(123);
316
- expect(block.message).toEqual('message');
317
- });
318
-
319
- it("testWaitsFor", function() {
320
- var doneWaiting = false;
321
- var runsBlockExecuted = false;
322
-
323
- var spec;
324
- env.describe('foo', function() {
325
- spec = env.it('has a waits for', function() {
326
- this.runs(function() {
327
- });
328
-
329
- this.waitsFor(500, function() {
330
- return doneWaiting;
331
- });
332
-
333
- this.runs(function() {
334
- runsBlockExecuted = true;
335
- });
336
- });
337
- });
338
-
339
- spec.execute();
340
- expect(runsBlockExecuted).toEqual(false); //, 'should not have executed runs block yet');
341
- fakeTimer.tick(100);
342
- doneWaiting = true;
343
- fakeTimer.tick(100);
344
- expect(runsBlockExecuted).toEqual(true); //, 'should have executed runs block');
345
- });
346
-
347
- it("fails with message", function() {
348
- var spec;
349
- env.describe('foo', function() {
350
- spec = env.it('has a waits for', function() {
351
- this.runs(function() {
352
- });
353
-
354
- this.waitsFor(500, function() {
355
- return false; // force a timeout
356
- }, 'my awesome condition');
357
-
358
- this.runs(function() {
359
- });
360
- });
361
- });
362
-
363
- spec.execute();
364
- fakeTimer.tick(1000);
365
- expect(spec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for my awesome condition');
366
- });
367
-
368
- it("fails and skips the rest of the spec if timeout is reached and the latch function hasn't returned true", function() {
369
- var runsBlockExecuted = false;
370
- var subsequentSpecRan = false;
371
-
372
- var timeoutSpec, subsequentSpec;
373
- var suite = env.describe('foo', function() {
374
- timeoutSpec = env.it('has a waits for', function() {
375
- this.runs(function() {
376
- });
377
-
378
- this.waitsFor(500, function() {
379
- return false;
380
- });
381
-
382
- this.runs(function() {
383
- runsBlockExecuted = true;
384
- });
385
- });
386
-
387
- subsequentSpec = env.it('then carries on to the next test', function() {
388
- subsequentSpecRan = true;
389
- });
390
- });
391
-
392
- env.execute();
393
- expect(runsBlockExecuted).toEqual(false);
394
- fakeTimer.tick(100);
395
- expect(runsBlockExecuted).toEqual(false);
396
- fakeTimer.tick(400);
397
- expect(runsBlockExecuted).toEqual(false);
398
- expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen');
399
- expect(subsequentSpecRan).toEqual(true);
400
- });
401
-
402
- it("runs afterEach after timing out", function() {
403
- var afterEach = jasmine.createSpy('afterEach');
404
-
405
- env.describe('foo', function () {
406
- env.afterEach(afterEach);
407
-
408
- env.it('waitsFor', function () {
409
- this.waitsFor(100, function() {
410
- return false;
411
- });
412
- });
413
- }).execute();
414
-
415
- fakeTimer.tick(500);
416
- expect(afterEach).toHaveBeenCalled();
417
- });
418
-
419
- it("runs single-spec after functions after timing out", function() {
420
- var after = jasmine.createSpy('after');
421
-
422
- env.describe('foo', function () {
423
- env.it('waitsFor', function () {
424
- this.after(after);
425
- this.waitsFor(100, function() {
426
- return false;
427
- });
428
- });
429
- }).execute();
430
-
431
- fakeTimer.tick(500);
432
- expect(after).toHaveBeenCalled();
433
- });
434
-
435
- describe('with consecutive calls', function () {
436
- var foo;
437
- beforeEach(function () {
438
- foo = 0;
439
- });
440
-
441
- it('exits immediately (does not stack) if the latchFunction times out', function () {
442
- var reachedFirstWaitsFor = false;
443
- var reachedSecondWaitsFor = false;
444
- env.describe('suite that waits', function () {
445
- env.it('should stack timeouts', function() {
446
- this.waitsFor(500, function () {
447
- reachedFirstWaitsFor = true;
448
- return false;
449
- });
450
- this.waitsFor(500, function () {
451
- reachedSecondWaitsFor = true;
452
- });
453
- this.runs(function () {
454
- foo++;
455
- });
456
- });
457
- });
458
-
459
- expect(reachedFirstWaitsFor).toEqual(false);
460
- env.execute();
461
-
462
- expect(reachedFirstWaitsFor).toEqual(true);
463
- expect(foo).toEqual(0);
464
- expect(reachedSecondWaitsFor).toEqual(false);
465
- fakeTimer.tick(500);
466
- expect(reachedSecondWaitsFor).toEqual(false);
467
- expect(foo).toEqual(0);
468
- fakeTimer.tick(500);
469
- expect(reachedSecondWaitsFor).toEqual(false);
470
- expect(foo).toEqual(0);
471
- });
472
-
473
- it('stacks latchFunctions', function () {
474
- var firstWaitsResult = false;
475
- var secondWaitsResult = false;
476
- var waitsSuite = env.describe('suite that waits', function () {
477
- env.it('spec with waitsFors', function() {
478
- this.waitsFor(600, function () {
479
- fakeTimer.setTimeout(function () {
480
- firstWaitsResult = true;
481
- }, 300);
482
- return firstWaitsResult;
483
- });
484
- this.waitsFor(600, function () {
485
- fakeTimer.setTimeout(function () {
486
- secondWaitsResult = true;
487
- }, 300);
488
- return secondWaitsResult;
489
- });
490
- this.runs(function () {
491
- foo++;
492
- });
493
- });
494
- });
495
-
496
- expect(firstWaitsResult).toEqual(false);
497
- expect(secondWaitsResult).toEqual(false);
498
- waitsSuite.execute();
499
-
500
- expect(firstWaitsResult).toEqual(false);
501
- expect(secondWaitsResult).toEqual(false);
502
- expect(foo).toEqual(0);
503
-
504
- fakeTimer.tick(300);
505
-
506
- expect(firstWaitsResult).toEqual(true);
507
- expect(secondWaitsResult).toEqual(false);
508
- expect(foo).toEqual(0);
509
-
510
- fakeTimer.tick(300);
511
-
512
- expect(firstWaitsResult).toEqual(true);
513
- expect(secondWaitsResult).toEqual(true);
514
- expect(foo).toEqual(1);
515
-
516
- });
517
- });
518
- });
519
-
520
- it("testSpecAfter", function() {
521
- var log = "";
522
- var spec;
523
- var suite = env.describe("has after", function() {
524
- spec = env.it('spec with after', function() {
525
- this.runs(function() {
526
- log += "spec";
527
- });
528
- });
529
- });
530
- spec.after(function() {
531
- log += "after1";
532
- });
533
- spec.after(function() {
534
- log += "after2";
535
- });
536
-
537
- suite.execute();
538
-
539
- expect(log).toEqual("specafter2after1");
540
- });
541
-
542
- describe('test suite declaration', function() {
543
- var suite;
544
- var dummyFunction = function() {
545
- };
546
-
547
- it('should give the suite a description', function() {
548
- suite = env.describe('one suite description', dummyFunction);
549
- expect(suite.description).toEqual('one suite description');
550
- });
551
-
552
- it('should enqueue functions for multipart tests and support waits, and run any ready runs() blocks', function() {
553
- var foo = 0;
554
- var bar = 0;
555
-
556
- suite = env.describe('one suite description', function () {
557
- env.it('should be a test with queuedFunctions', function() {
558
- this.runs(function() {
559
- foo++;
560
- });
561
- this.waits(100);
562
- this.runs(function() {
563
- bar++;
564
- });
565
- });
566
- });
567
-
568
- suite.execute();
569
-
570
- expect(foo).toEqual(1);
571
- expect(bar).toEqual(0);
572
-
573
- fakeTimer.tick(100);
574
- expect(bar).toEqual(1);
575
- });
576
-
577
- });
578
-
579
- it("testBeforeAndAfterCallbacks", function () {
580
- var suiteWithBefore = env.describe('one suite with a before', function () {
581
-
582
- this.beforeEach(function () {
583
- this.foo = 1;
584
- });
585
-
586
- env.it('should be a spec', function () {
587
- this.runs(function() {
588
- this.foo++;
589
- this.expect(this.foo).toEqual(2);
590
- });
591
- });
592
-
593
- env.it('should be another spec', function () {
594
- this.runs(function() {
595
- this.foo++;
596
- this.expect(this.foo).toEqual(2);
597
- });
598
- });
599
- });
600
-
601
- suiteWithBefore.execute();
602
-
603
- var suite = suiteWithBefore;
604
-
605
- expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
606
- expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
607
-
608
-
609
- var foo = 1;
610
- var suiteWithAfter = env.describe('one suite with an after_each', function () {
611
-
612
- env.it('should be a spec with an after_each', function () {
613
- this.expect(foo).toEqual(1);
614
- foo++;
615
- this.expect(foo).toEqual(2);
616
- });
617
-
618
- env.it('should be another spec with an after_each', function () {
619
- this.expect(foo).toEqual(0);
620
- foo++;
621
- this.expect(foo).toEqual(1);
622
- });
623
-
624
- this.afterEach(function () {
625
- foo = 0;
626
- });
627
- });
628
-
629
- suiteWithAfter.execute();
630
-
631
- suite = suiteWithAfter;
632
- expect(suite.afterEach.length).toEqual(1);
633
- expect(suite.results().getItems()[0].passed()).toEqual(true);
634
- expect(suite.results().getItems()[1].passed()).toEqual(true);
635
- expect(foo).toEqual(0);
636
-
637
- });
638
-
639
- it('#waits should allow consecutive waits calls', function () {
640
- var foo = 0;
641
- var waitsSuite = env.describe('suite that waits', function () {
642
- env.it('should wait', function() {
643
- this.waits(500);
644
- this.waits(500);
645
- this.runs(function () {
646
- foo++;
647
- });
648
- });
649
- });
650
-
651
- waitsSuite.execute();
652
- expect(foo).toEqual(0);
653
- fakeTimer.tick(500);
654
- expect(foo).toEqual(0);
655
- fakeTimer.tick(500);
656
-
657
- expect(foo).toEqual(1);
658
- });
659
-
660
- it('nested suites', function () {
35
+ it('nested suites', function (done) {
661
36
 
662
37
  var foo = 0;
663
38
  var bar = 0;
@@ -688,279 +63,24 @@ describe("jasmine spec running", function () {
688
63
  expect(bar).toEqual(0);
689
64
  expect(baz).toEqual(0);
690
65
  expect(quux).toEqual(0);
691
- nested.execute();
692
-
693
- expect(foo).toEqual(1);
694
- expect(bar).toEqual(1);
695
- expect(baz).toEqual(1);
696
- expect(quux).toEqual(1);
697
- });
698
-
699
- it("#beforeEach should be able to eval runs and waits blocks", function () {
700
- var foo = 0;
701
- var bar = 0;
702
- var suiteWithBefore = env.describe('one suite with a before', function () {
703
- this.beforeEach(function () {
704
- this.runs(function () {
705
- foo++;
706
- });
707
- this.waits(500);
708
- this.runs(function () {
709
- foo++;
710
- });
711
- this.waits(500);
712
- });
713
-
714
- env.it('should be a spec', function () {
715
- bar = 1;
716
- foo++;
717
- });
718
-
719
- });
720
-
721
- expect(foo).toEqual(0);
722
- expect(bar).toEqual(0);
723
- suiteWithBefore.execute();
724
-
725
- expect(bar).toEqual(0);
726
- expect(foo).toEqual(1);
727
- fakeTimer.tick(500);
728
-
729
- expect(bar).toEqual(0);
730
- expect(foo).toEqual(2);
731
- fakeTimer.tick(500);
732
- expect(bar).toEqual(1);
733
- expect(foo).toEqual(3);
734
- });
735
-
736
- it("#afterEach should be able to eval runs and waits blocks", function () {
737
- var foo = 0;
738
- var firstSpecHasRun = false;
739
- var secondSpecHasRun = false;
740
- var suiteWithAfter = env.describe('one suite with a before', function () {
741
- this.afterEach(function () {
742
- this.waits(500);
743
- this.runs(function () {
744
- foo++;
745
- });
746
- this.waits(500);
747
- });
748
-
749
- env.it('should be the first spec', function () {
750
- firstSpecHasRun = true;
751
- });
752
-
753
- env.it('should be a spec', function () {
754
- secondSpecHasRun = true;
755
- foo++;
756
- });
757
-
758
- });
759
-
760
- expect(firstSpecHasRun).toEqual(false);
761
- expect(secondSpecHasRun).toEqual(false);
762
- expect(foo).toEqual(0);
763
-
764
- suiteWithAfter.execute();
765
-
766
-
767
- expect(firstSpecHasRun).toEqual(true);
768
- expect(secondSpecHasRun).toEqual(false);
769
- expect(foo).toEqual(0);
770
-
771
- fakeTimer.tick(500);
772
-
773
- expect(foo).toEqual(1);
774
- expect(secondSpecHasRun).toEqual(false);
775
- fakeTimer.tick(500);
776
-
777
- expect(foo).toEqual(2);
778
- expect(secondSpecHasRun).toEqual(true);
779
-
780
- });
781
-
782
- it("Spec#after should be able to eval runs and waits blocks", function () {
783
- var runsBeforeAfter = false;
784
- var firstSpecHasRun = false;
785
- var secondSpecHasRun = false;
786
- var afterHasRun = false;
787
- var suiteWithAfter = env.describe('one suite with a before', function () {
788
-
789
- env.it('should be the first spec', function () {
790
- firstSpecHasRun = true;
791
- this.after(function () {
792
- this.waits(500);
793
- this.runs(function () {
794
- afterHasRun = true;
795
- });
796
- this.waits(500);
797
- }, true);
798
- this.waits(500);
799
- this.runs(function () {
800
- runsBeforeAfter = true;
801
- });
802
- });
803
-
804
- env.it('should be a spec', function () {
805
- secondSpecHasRun = true;
806
- });
807
-
808
- });
809
-
810
- expect(firstSpecHasRun).toEqual(false);
811
- expect(runsBeforeAfter).toEqual(false);
812
- expect(afterHasRun).toEqual(false);
813
- expect(secondSpecHasRun).toEqual(false);
814
-
815
- suiteWithAfter.execute();
816
-
817
- expect(firstSpecHasRun).toEqual(true);
818
- expect(runsBeforeAfter).toEqual(false);
819
- expect(afterHasRun).toEqual(false);
820
- expect(secondSpecHasRun).toEqual(false);
821
-
822
- fakeTimer.tick(500);
823
-
824
- expect(firstSpecHasRun).toEqual(true);
825
- expect(runsBeforeAfter).toEqual(true);
826
- expect(afterHasRun).toEqual(false);
827
- expect(secondSpecHasRun).toEqual(false);
828
-
829
- fakeTimer.tick(500);
830
-
831
- expect(firstSpecHasRun).toEqual(true);
832
- expect(runsBeforeAfter).toEqual(true);
833
- expect(afterHasRun).toEqual(true);
834
- expect(secondSpecHasRun).toEqual(false);
835
-
836
- fakeTimer.tick(500);
837
-
838
- expect(firstSpecHasRun).toEqual(true);
839
- expect(runsBeforeAfter).toEqual(true);
840
- expect(afterHasRun).toEqual(true);
841
- expect(secondSpecHasRun).toEqual(true);
842
- });
843
-
844
- it("handles waits", function () {
845
- var firstSpecHasRun = false;
846
- var secondSpecHasRun = false;
847
- var suiteWithAfter = env.describe('one suite with a before', function () {
848
-
849
- env.it('should be the first spec', function () {
850
- this.waits(500);
851
- this.runs(function () {
852
- firstSpecHasRun = true;
853
- });
854
- });
855
-
856
- env.it('should be a spec', function () {
857
- secondSpecHasRun = true;
858
- });
859
-
860
- });
861
-
862
- expect(firstSpecHasRun).toEqual(false);
863
- expect(secondSpecHasRun).toEqual(false);
864
-
865
- suiteWithAfter.execute();
866
-
867
- expect(firstSpecHasRun).toEqual(false);
868
- expect(secondSpecHasRun).toEqual(false);
869
-
870
- fakeTimer.tick(500);
871
-
872
- expect(firstSpecHasRun).toEqual(true);
873
- expect(secondSpecHasRun).toEqual(true);
874
- });
875
-
876
- it("testBeforeExecutesSafely", function() {
877
- var report = "";
878
- var suite = env.describe('before fails on first test, passes on second', function() {
879
- var counter = 0;
880
- this.beforeEach(function() {
881
- counter++;
882
- if (counter == 1) {
883
- throw "before failure";
884
- }
885
- });
886
- env.it("first should not run because before fails", function() {
887
- this.runs(function() {
888
- report += "first";
889
- this.expect(true).toEqual(true);
890
- });
891
- });
892
- env.it("second should run and pass because before passes", function() {
893
- this.runs(function() {
894
- report += "second";
895
- this.expect(true).toEqual(true);
896
- });
897
- });
898
- });
899
-
900
- suite.execute();
901
-
902
- expect(report).toEqual("firstsecond");
903
- var suiteResults = suite.results();
904
- expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
905
- expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true);
906
- });
907
-
908
- it("testAfterExecutesSafely", function() {
909
- var report = "";
910
- var suite = env.describe('after fails on first test, then passes', function() {
911
- var counter = 0;
912
- this.afterEach(function() {
913
- counter++;
914
- if (counter == 1) {
915
- throw "after failure";
916
- }
917
- });
918
- env.it("first should run, expectation passes, but spec fails because after fails", function() {
919
- this.runs(function() {
920
- report += "first";
921
- this.expect(true).toEqual(true);
922
- });
923
- });
924
- env.it("second should run and pass because after passes", function() {
925
- this.runs(function() {
926
- report += "second";
927
- this.expect(true).toEqual(true);
928
- });
929
- });
930
- env.it("third should run and pass because after passes", function() {
931
- this.runs(function() {
932
- report += "third";
933
- this.expect(true).toEqual(true);
934
- });
935
- });
66
+ nested.execute(function() {
67
+ expect(foo).toEqual(1);
68
+ expect(bar).toEqual(1);
69
+ expect(baz).toEqual(1);
70
+ expect(quux).toEqual(1);
71
+ done();
936
72
  });
937
-
938
- suite.execute();
939
-
940
- expect(report).toEqual("firstsecondthird"); // "all tests should run");
941
- //After each errors should not go in spec results because it confuses the count.
942
- var suiteResults = suite.results();
943
- expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
944
-
945
- expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
946
- expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
947
- expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
948
-
949
- expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
950
- expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
951
- expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
952
- expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
953
73
  });
954
74
 
955
- it("should permit nested describes", function() {
75
+ it("should permit nested describes", function(done) {
956
76
  var actions = [];
957
77
 
958
78
  env.beforeEach(function () {
959
- actions.push('runner beforeEach');
79
+ actions.push('topSuite beforeEach');
960
80
  });
961
81
 
962
82
  env.afterEach(function () {
963
- actions.push('runner afterEach');
83
+ actions.push('topSuite afterEach');
964
84
  });
965
85
 
966
86
  env.describe('Something', function() {
@@ -1009,42 +129,46 @@ describe("jasmine spec running", function () {
1009
129
  });
1010
130
  });
1011
131
 
1012
- env.execute();
1013
-
1014
-
1015
- var expected = [
1016
- "runner beforeEach",
1017
- "outer beforeEach",
1018
- "outer it 1",
1019
- "outer afterEach",
1020
- "runner afterEach",
1021
-
1022
- "runner beforeEach",
1023
- "outer beforeEach",
1024
- "inner 1 beforeEach",
1025
- "inner 1 it",
1026
- "inner 1 afterEach",
1027
- "outer afterEach",
1028
- "runner afterEach",
132
+ var assertions = function() {
133
+ var expected = [
134
+ "topSuite beforeEach",
135
+ "outer beforeEach",
136
+ "outer it 1",
137
+ "outer afterEach",
138
+ "topSuite afterEach",
139
+
140
+ "topSuite beforeEach",
141
+ "outer beforeEach",
142
+ "inner 1 beforeEach",
143
+ "inner 1 it",
144
+ "inner 1 afterEach",
145
+ "outer afterEach",
146
+ "topSuite afterEach",
147
+
148
+ "topSuite beforeEach",
149
+ "outer beforeEach",
150
+ "outer it 2",
151
+ "outer afterEach",
152
+ "topSuite afterEach",
153
+
154
+ "topSuite beforeEach",
155
+ "outer beforeEach",
156
+ "inner 2 beforeEach",
157
+ "inner 2 it",
158
+ "inner 2 afterEach",
159
+ "outer afterEach",
160
+ "topSuite afterEach"
161
+ ];
162
+ expect(actions).toEqual(expected);
163
+ done();
164
+ }
1029
165
 
1030
- "runner beforeEach",
1031
- "outer beforeEach",
1032
- "outer it 2",
1033
- "outer afterEach",
1034
- "runner afterEach",
166
+ env.addReporter({jasmineDone: assertions});
1035
167
 
1036
- "runner beforeEach",
1037
- "outer beforeEach",
1038
- "inner 2 beforeEach",
1039
- "inner 2 it",
1040
- "inner 2 afterEach",
1041
- "outer afterEach",
1042
- "runner afterEach"
1043
- ];
1044
- expect(actions).toEqual(expected);
168
+ env.execute();
1045
169
  });
1046
170
 
1047
- it("should run multiple befores and afters in the order they are declared", function() {
171
+ it("should run multiple befores and afters in the order they are declared", function(done) {
1048
172
  var actions = [];
1049
173
 
1050
174
  env.beforeEach(function () {
@@ -1085,162 +209,60 @@ describe("jasmine spec running", function () {
1085
209
  });
1086
210
  });
1087
211
 
1088
- env.execute();
1089
-
1090
- var expected = [
1091
- "runner beforeEach1",
1092
- "runner beforeEach2",
1093
- "beforeEach1",
1094
- "beforeEach2",
1095
- "outer it 1",
1096
- "afterEach2",
1097
- "afterEach1",
1098
- "runner afterEach2",
1099
- "runner afterEach1"
1100
- ];
1101
- expect(actions).toEqual(expected);
1102
- });
1103
-
1104
- it("builds up nested names", function() {
1105
- var nestedSpec;
1106
- env.describe('Test Subject', function() {
1107
- env.describe('when under circumstance A', function() {
1108
- env.describe('and circumstance B', function() {
1109
- nestedSpec = env.it('behaves thusly', function() {
1110
- });
1111
- });
1112
- });
1113
- });
1114
-
1115
- expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
1116
- });
1117
-
1118
- it("should skip empty suites", function () {
1119
- env.describe('NonEmptySuite1', function() {
1120
- env.it('should pass', function() {
1121
- this.expect(true).toEqual(true);
1122
- });
1123
- env.describe('NestedEmptySuite', function() {
1124
- });
1125
- env.it('should pass', function() {
1126
- this.expect(true).toEqual(true);
1127
- });
1128
- });
1129
-
1130
- env.describe('EmptySuite', function() {
1131
- });
212
+ var assertions = function() {
213
+ var expected = [
214
+ "runner beforeEach1",
215
+ "runner beforeEach2",
216
+ "beforeEach1",
217
+ "beforeEach2",
218
+ "outer it 1",
219
+ "afterEach2",
220
+ "afterEach1",
221
+ "runner afterEach2",
222
+ "runner afterEach1"
223
+ ];
224
+ expect(actions).toEqual(expected);
225
+ done();
226
+ };
1132
227
 
1133
- env.describe('NonEmptySuite2', function() {
1134
- env.it('should pass', function() {
1135
- this.expect(true).toEqual(true);
1136
- });
1137
- });
228
+ env.addReporter({jasmineDone: assertions});
1138
229
 
1139
230
  env.execute();
1140
-
1141
- var runnerResults = env.currentRunner_.results();
1142
- expect(runnerResults.totalCount).toEqual(3);
1143
- expect(runnerResults.passedCount).toEqual(3);
1144
- expect(runnerResults.failedCount).toEqual(0);
1145
231
  });
1146
232
 
1147
- it("should bind 'this' to the running spec within the spec body", function() {
1148
- var spec;
1149
- var suite = env.describe('one suite description', function () {
1150
- env.it('should be a test with queuedFunctions', function() {
1151
- spec = this.runs(function() {
1152
- this.foo = 0;
1153
- this.foo++;
1154
- });
1155
-
1156
- this.runs(function() {
1157
- var that = this;
1158
- fakeTimer.setTimeout(function() {
1159
- that.foo++;
1160
- }, 250);
1161
- });
1162
-
1163
- this.runs(function() {
1164
- this.expect(this.foo).toEqual(2);
1165
- });
1166
-
1167
- this.waits(300);
1168
-
1169
- this.runs(function() {
1170
- this.expect(this.foo).toEqual(2);
1171
- });
233
+ it("shouldn't run disabled suites", function(done) {
234
+ var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
235
+ suite = env.describe('A Suite', function() {
236
+ env.xdescribe('with a disabled suite', function(){
237
+ env.it('spec inside a disabled suite', specInADisabledSuite);
1172
238
  });
1173
-
1174
239
  });
1175
240
 
1176
- suite.execute();
1177
- fakeTimer.tick(600);
1178
- expect(spec.foo).toEqual(2);
1179
- var suiteResults = suite.results();
1180
- expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
1181
- expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
1182
- expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true);
1183
- });
1184
-
1185
- it("shouldn't run disabled tests", function() {
1186
- var xitSpecWasRun = false;
1187
- var suite = env.describe('default current suite', function() {
1188
- env.xit('disabled spec').runs(function () {
1189
- xitSpecWasRun = true;
1190
- });
1191
-
1192
- env.it('enabled spec').runs(function () {
1193
- var foo = 'bar';
1194
- expect(foo).toEqual('bar');
1195
- });
241
+ suite.execute(function() {
242
+ expect(specInADisabledSuite).not.toHaveBeenCalled();
243
+ done();
1196
244
  });
1197
-
1198
- suite.execute();
1199
- expect(xitSpecWasRun).toEqual(false);
1200
245
  });
1201
246
 
1202
- it('shouldn\'t execute specs in disabled suites', function() {
1203
- var spy = jasmine.createSpy();
1204
- var disabledSuite = env.xdescribe('a disabled suite', function() {
1205
- env.it('enabled spec, but should not be run', function() {
1206
- spy();
247
+ it("should set all pending specs to pending when a suite is run", function(done) {
248
+ var pendingSpec,
249
+ suite = env.describe('default current suite', function() {
250
+ pendingSpec = env.it("I am a pending spec");
1207
251
  });
1208
- });
1209
-
1210
- disabledSuite.execute();
1211
-
1212
- expect(spy).not.toHaveBeenCalled();
1213
- });
1214
252
 
1215
- it('#explodes should throw an exception when it is called inside a spec', function() {
1216
- var exceptionMessage = false;
1217
- var anotherSuite = env.describe('Spec', function () {
1218
- env.it('plodes', function() {
1219
- try {
1220
- this.explodes();
1221
- }
1222
- catch (e) {
1223
- exceptionMessage = e;
1224
- }
1225
- expect(exceptionMessage).toNotEqual(false);
1226
- });
253
+ suite.execute(function() {
254
+ expect(pendingSpec.status()).toBe("pending");
255
+ done();
1227
256
  });
1228
-
1229
- anotherSuite.execute();
1230
-
1231
- expect(exceptionMessage).toEqual('explodes function should not have been called');
1232
257
  });
1233
258
 
1234
- it("should recover gracefully when there are errors in describe functions", function() {
259
+
260
+ // TODO: is this useful? It doesn't catch syntax errors
261
+ xit("should recover gracefully when there are errors in describe functions", function() {
1235
262
  var specs = [];
1236
- var superSimpleReporter = new jasmine.Reporter();
1237
- superSimpleReporter.reportSpecResults = function(spec) {
1238
- specs.push("Spec: " + spec.getFullName());
1239
- var results = spec.results().getItems();
1240
- for (var i = 0; i < results.length; i++) {
1241
- var result = results[i];
1242
- specs.push("Result: " + result);
1243
- }
263
+ var superSimpleReporter = new j$.Reporter();
264
+ superSimpleReporter.reportSpecResults = function(result) {
265
+ specs.push("Spec: " + result.fullName);
1244
266
  };
1245
267
 
1246
268
  try {
@@ -1276,16 +298,11 @@ describe("jasmine spec running", function () {
1276
298
 
1277
299
  expect(specs.join('')).toMatch(new RegExp(
1278
300
  'Spec: outer1 inner1 should thingy.' +
1279
- 'Result: Passed.' +
1280
- 'Spec: outer1 inner1 encountered a declaration exception.' +
1281
- 'Result: Error: fake error.*' +
1282
- 'Spec: outer1 inner2 should other thingy.' +
1283
- 'Result: Passed.' +
1284
- 'Spec: outer1 encountered a declaration exception.' +
1285
- 'Result: Error: fake error.*' +
1286
- 'Spec: outer2 should xxx.' +
1287
- 'Result: Passed.'
1288
- ));
1289
- });
301
+ 'Spec: outer1 inner1 encountered a declaration exception.' +
302
+ 'Spec: outer1 inner2 should other thingy.' +
303
+ 'Spec: outer1 encountered a declaration exception.' +
304
+ 'Spec: outer2 should xxx.'
305
+ ));
1290
306
 
1291
- });
307
+ });
308
+ });