jasmine-core 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/jasmine-core.rb +17 -0
  2. data/lib/jasmine-core/example/SpecRunner.html +54 -0
  3. data/lib/jasmine-core/example/spec/PlayerSpec.js +58 -0
  4. data/lib/jasmine-core/example/spec/SpecHelper.js +9 -0
  5. data/lib/jasmine-core/example/src/Player.js +22 -0
  6. data/lib/jasmine-core/example/src/Song.js +7 -0
  7. data/lib/jasmine-core/jasmine-html.js +190 -0
  8. data/lib/jasmine-core/jasmine.css +166 -0
  9. data/lib/jasmine-core/jasmine.js +2476 -0
  10. data/lib/jasmine-core/json2.js +478 -0
  11. data/lib/jasmine-core/version.rb +8 -0
  12. data/spec/console/ConsoleReporterSpec.js +451 -0
  13. data/spec/core/BaseSpec.js +27 -0
  14. data/spec/core/CustomMatchersSpec.js +97 -0
  15. data/spec/core/EnvSpec.js +159 -0
  16. data/spec/core/ExceptionsSpec.js +149 -0
  17. data/spec/core/JsApiReporterSpec.js +103 -0
  18. data/spec/core/MatchersSpec.js +838 -0
  19. data/spec/core/MockClockSpec.js +38 -0
  20. data/spec/core/MultiReporterSpec.js +45 -0
  21. data/spec/core/NestedResultsSpec.js +54 -0
  22. data/spec/core/PrettyPrintSpec.js +87 -0
  23. data/spec/core/QueueSpec.js +23 -0
  24. data/spec/core/ReporterSpec.js +56 -0
  25. data/spec/core/RunnerSpec.js +267 -0
  26. data/spec/core/SpecRunningSpec.js +1258 -0
  27. data/spec/core/SpecSpec.js +124 -0
  28. data/spec/core/SpySpec.js +201 -0
  29. data/spec/core/SuiteSpec.js +120 -0
  30. data/spec/core/UtilSpec.js +39 -0
  31. data/spec/core/WaitsForBlockSpec.js +118 -0
  32. data/spec/html/MatchersHtmlSpec.js +38 -0
  33. data/spec/html/PrettyPrintHtmlSpec.js +8 -0
  34. data/spec/html/TrivialReporterSpec.js +239 -0
  35. data/spec/node_suite.js +127 -0
  36. data/spec/runner.html +79 -0
  37. data/spec/templates/runner.html.erb +49 -0
  38. data/spec/templates/script_tag.html.erb +1 -0
  39. metadata +164 -0
@@ -0,0 +1,8 @@
1
+ module Jasmine
2
+ module Core
3
+ require 'json'
4
+ VERSION_HASH = JSON.parse(File.new(File.join(File.dirname(__FILE__), "..", "..", "src", "version.json")).read);
5
+ VERSION = "#{VERSION_HASH['major']}.#{VERSION_HASH['minor']}.#{VERSION_HASH['build']}"
6
+ VERSION << ".rc#{VERSION_HASH['release_candidate']}" if VERSION_HASH['release_candidate']
7
+ end
8
+ end
@@ -0,0 +1,451 @@
1
+ describe("ConsoleReporter", function() {
2
+ //keep these literal. otherwise the test loses value as a test.
3
+ function green(str) {
4
+ return '\033[32m' + str + '\033[0m';
5
+ }
6
+
7
+ function red(str) {
8
+ return '\033[31m' + str + '\033[0m';
9
+ }
10
+
11
+ function yellow(str) {
12
+ return '\033[33m' + str + '\033[0m';
13
+ }
14
+
15
+ function prefixGreen(str) {
16
+ return '\033[32m' + str;
17
+ }
18
+
19
+ function prefixRed(str) {
20
+ return '\033[31m' + str;
21
+ }
22
+
23
+ var newline = "\n";
24
+
25
+ var passingSpec = {
26
+ results: function() {
27
+ return {
28
+ passed: function() {
29
+ return true;
30
+ }
31
+ };
32
+ }
33
+ },
34
+ failingSpec = {
35
+ results: function() {
36
+ return {
37
+ passed: function() {
38
+ return false;
39
+ }
40
+ };
41
+ }
42
+ },
43
+ skippedSpec = {
44
+ results: function() {
45
+ return {skipped: true};
46
+ }
47
+ },
48
+ passingRun = {
49
+ specs: function() {
50
+ return [null, null, null];
51
+ },
52
+ results: function() {
53
+ return {failedCount: 0, items_: [null, null, null]};
54
+ }
55
+ },
56
+ failingRun = {
57
+ specs: function() {
58
+ return [null, null, null];
59
+ },
60
+ results: function() {
61
+ return {
62
+ failedCount: 7, items_: [null, null, null]};
63
+ }
64
+ };
65
+
66
+ function repeatedlyInvoke(f, times) {
67
+ for (var i = 0; i < times; i++) f(times + 1);
68
+ }
69
+
70
+ function repeat(thing, times) {
71
+ var arr = [];
72
+ for (var i = 0; i < times; i++) arr.push(thing);
73
+ return arr;
74
+ }
75
+
76
+ function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) {
77
+ reporter.reportRunnerStarting();
78
+ for (var i = 0; i < specResults.length; i++) {
79
+ reporter.reportSpecResults(specResults[i]);
80
+ }
81
+ for (i = 0; i < suiteResults.length; i++) {
82
+ reporter.reportSuiteResults(suiteResults[i]);
83
+ }
84
+ reporter.runnerStartTime = startTime;
85
+ reporter.now = function() {
86
+ return endTime;
87
+ };
88
+ reporter.reportRunnerResults(finalRunner);
89
+ }
90
+
91
+ var reporter, out, done;
92
+
93
+ beforeEach(function() {
94
+ out = (function() {
95
+ var output = "";
96
+ return {
97
+ print:function(str) {
98
+ output += str;
99
+ },
100
+ getOutput:function() {
101
+ return output;
102
+ },
103
+ clear: function() {
104
+ output = "";
105
+ }
106
+ };
107
+ })();
108
+
109
+ done = false;
110
+ reporter = new jasmine.ConsoleReporter(out.print, function(runner) {
111
+ done = true
112
+ });
113
+ });
114
+
115
+
116
+ describe('Integration', function() {
117
+ it("prints the proper output under a pass scenario - small numbers.", function() {
118
+ simulateRun(reporter,
119
+ repeat(passingSpec, 3),
120
+ [],
121
+ {
122
+ specs: function() {
123
+ return [null, null, null];
124
+ },
125
+ results:function() {
126
+ return {
127
+ items_: [null, null, null],
128
+ totalCount: 7,
129
+ failedCount: 0
130
+ };
131
+ }
132
+ },
133
+ 1000,
134
+ 1777
135
+ );
136
+
137
+ var output = out.getOutput();
138
+ expect(output).toMatch(/^Started/);
139
+ expect(output).toMatch(/\.\.\./);
140
+ expect(output).toMatch(/3 specs, 0 failures/);
141
+ });
142
+
143
+ it("prints the proper output under a pass scenario. large numbers.", function() {
144
+ simulateRun(reporter,
145
+ repeat(passingSpec, 57),
146
+ [],
147
+ {
148
+ specs: function() {
149
+ return [null, null, null];
150
+ },
151
+ results:function() {
152
+ return {
153
+ items_: [null, null, null],
154
+ totalCount: 7,
155
+ failedCount: 0
156
+ };
157
+ }
158
+ },
159
+ 1000,
160
+ 1777);
161
+
162
+ var output = out.getOutput();
163
+ expect(output).toMatch(/^Started/);
164
+ expect(output).toMatch(/\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\./);
165
+ expect(output).toMatch(/3 specs, 0 failures/);
166
+ });
167
+
168
+ it("prints the proper output under a failure scenario.", function() {
169
+ simulateRun(reporter,
170
+ [failingSpec, passingSpec, failingSpec],
171
+ [
172
+ {description:"The oven",
173
+ results:function() {
174
+ return {
175
+ items_:[
176
+ {failedCount:2,
177
+ description:"heats up",
178
+ items_:[
179
+ {trace:{stack:"stack trace one\n second line"}},
180
+ {trace:{stack:"stack trace two"}}
181
+ ]}
182
+ ]
183
+ };
184
+ }},
185
+ {description:"The washing machine",
186
+ results:function() {
187
+ return {
188
+ items_:[
189
+ {failedCount:2,
190
+ description:"washes clothes",
191
+ items_:[
192
+ {trace:{stack:"stack trace one"}}
193
+ ]}
194
+ ]
195
+ };
196
+ }}
197
+ ],
198
+ {
199
+ specs: function() {
200
+ return [null, null, null];
201
+ },
202
+ results:function() {
203
+ return {
204
+ items_: [null, null, null],
205
+ totalCount: 7,
206
+ failedCount: 2
207
+ };
208
+ }
209
+ },
210
+ 1000,
211
+ 1777);
212
+
213
+ var output = out.getOutput();
214
+ expect(output).toMatch(/^Started/);
215
+ expect(output).toMatch(/F\.F/);
216
+ expect(output).toMatch(/The oven heats up\n stack trace one\n second line\n stack trace two/);
217
+ expect(output).toMatch(/The washing machine washes clothes\n stack trace one/);
218
+ expect(output).toMatch(/3 specs, 2 failures/);
219
+ });
220
+ });
221
+
222
+ describe('When a Jasmine environment executes', function() {
223
+ beforeEach(function() {
224
+ reporter.reportRunnerStarting();
225
+ });
226
+
227
+ it("should print 'Started' to the console", function() {
228
+ expect(out.getOutput()).toEqual("Started" + newline);
229
+ });
230
+
231
+ describe('when a spec reports', function() {
232
+ beforeEach(function() {
233
+ out.clear();
234
+ });
235
+
236
+ it("prints a green dot if the spec passes", function() {
237
+ reporter.reportSpecResults(passingSpec);
238
+
239
+ expect(out.getOutput()).toMatch(/\./);
240
+ });
241
+
242
+ it("prints a red dot if the spec fails", function() {
243
+ reporter.reportSpecResults(failingSpec);
244
+
245
+ expect(out.getOutput()).toMatch(/F/);
246
+ });
247
+
248
+ it("prints a yellow star if the spec was skipped", function() {
249
+ reporter.reportSpecResults(skippedSpec);
250
+
251
+ expect(out.getOutput()).toMatch(/\*/);
252
+ });
253
+ });
254
+
255
+ describe('when a suite reports', function() {
256
+ var emptyResults;
257
+ beforeEach(function() {
258
+ emptyResults = function() {
259
+ return {
260
+ items_:[]
261
+ };
262
+ };
263
+ });
264
+
265
+ it("remembers suite results", function() {
266
+ reporter.reportSuiteResults({description: "Oven", results: emptyResults});
267
+ reporter.reportSuiteResults({description: "Mixer", results: emptyResults});
268
+
269
+ expect(reporter.suiteResults[0].description).toEqual('Oven');
270
+ expect(reporter.suiteResults[1].description).toEqual('Mixer');
271
+ });
272
+
273
+ it("creates a description out of the current suite and any parent suites", function() {
274
+ var grandparentSuite = {
275
+ description: "My house",
276
+ results: emptyResults
277
+ };
278
+ var parentSuite = {
279
+ description: "kitchen",
280
+ parentSuite: grandparentSuite,
281
+ results: emptyResults
282
+ };
283
+ reporter.reportSuiteResults({ description: "oven", parentSuite: parentSuite, results: emptyResults });
284
+
285
+ expect(reporter.suiteResults[0].description).toEqual("My house kitchen oven");
286
+ });
287
+
288
+ it("gathers failing spec results from the suite - the spec must have a description.", function() {
289
+ reporter.reportSuiteResults({description:"Oven",
290
+ results: function() {
291
+ return {
292
+ items_:[
293
+ { failedCount: 0, description: "specOne" },
294
+ { failedCount: 99, description: "specTwo" },
295
+ { failedCount: 0, description: "specThree" },
296
+ { failedCount: 88, description: "specFour" },
297
+ { failedCount: 3 }
298
+ ]
299
+ };
300
+ }});
301
+
302
+ expect(reporter.suiteResults[0].failedSpecResults).
303
+ toEqual([
304
+ { failedCount: 99, description: "specTwo" },
305
+ { failedCount: 88, description: "specFour" }
306
+ ]);
307
+ });
308
+
309
+ });
310
+
311
+ describe('and finishes', function() {
312
+
313
+ describe('when reporting spec failure information', function() {
314
+
315
+ it("prints suite and spec descriptions together as a sentence", function() {
316
+ reporter.suiteResults = [
317
+ {description:"The oven", failedSpecResults:[
318
+ {description:"heats up", items_:[]},
319
+ {description:"cleans itself", items_:[]}
320
+ ]},
321
+ {description:"The mixer", failedSpecResults:[
322
+ {description:"blends things together", items_:[]}
323
+ ]}
324
+ ];
325
+
326
+ reporter.reportRunnerResults(failingRun);
327
+
328
+ expect(out.getOutput()).toContain("The oven heats up");
329
+ expect(out.getOutput()).toContain("The oven cleans itself");
330
+ expect(out.getOutput()).toContain("The mixer blends things together");
331
+ });
332
+
333
+ it("prints stack trace of spec failure", function() {
334
+ reporter.suiteResults = [
335
+ {description:"The oven", failedSpecResults:[
336
+ {description:"heats up",
337
+ items_:[
338
+ {trace:{stack:"stack trace one"}},
339
+ {trace:{stack:"stack trace two"}}
340
+ ]}
341
+ ]}
342
+ ];
343
+
344
+ reporter.reportRunnerResults(failingRun);
345
+
346
+ expect(out.getOutput()).toContain("The oven heats up");
347
+ expect(out.getOutput()).toContain("stack trace one");
348
+ expect(out.getOutput()).toContain("stack trace two");
349
+ });
350
+
351
+ });
352
+
353
+ describe('when reporting the execution time', function() {
354
+
355
+ it("prints the full finished message", function() {
356
+ reporter.now = function() {
357
+ return 1000;
358
+ };
359
+ reporter.reportRunnerStarting();
360
+ reporter.now = function() {
361
+ return 1777;
362
+ };
363
+ reporter.reportRunnerResults(failingRun);
364
+ expect(out.getOutput()).toContain("Finished in 0.777 seconds");
365
+ });
366
+
367
+ it("prints round time numbers correctly", function() {
368
+ function run(startTime, endTime) {
369
+ out.clear();
370
+ reporter.runnerStartTime = startTime;
371
+ reporter.now = function() {
372
+ return endTime;
373
+ };
374
+ reporter.reportRunnerResults(passingRun);
375
+ }
376
+
377
+ run(1000, 11000);
378
+ expect(out.getOutput()).toContain("10 seconds");
379
+
380
+ run(1000, 2000);
381
+ expect(out.getOutput()).toContain("1 seconds");
382
+
383
+ run(1000, 1100);
384
+ expect(out.getOutput()).toContain("0.1 seconds");
385
+
386
+ run(1000, 1010);
387
+ expect(out.getOutput()).toContain("0.01 seconds");
388
+
389
+ run(1000, 1001);
390
+ expect(out.getOutput()).toContain("0.001 seconds");
391
+ });
392
+ });
393
+
394
+ describe("when reporting the results summary", function() {
395
+ it("prints statistics in green if there were no failures", function() {
396
+ reporter.reportRunnerResults({
397
+ specs: function() {
398
+ return [null, null, null];
399
+ },
400
+ results:function() {
401
+ return {items_: [null, null, null], totalCount: 7, failedCount: 0};
402
+ }
403
+ });
404
+ expect(out.getOutput()).
405
+ toContain("3 specs, 0 failures");
406
+ });
407
+
408
+ it("prints statistics in red if there was a failure", function() {
409
+ reporter.reportRunnerResults({
410
+ specs: function() {
411
+ return [null, null, null];
412
+ },
413
+ results:function() {
414
+ return {items_: [null, null, null], totalCount: 7, failedCount: 3};
415
+ }
416
+ });
417
+ expect(out.getOutput()).
418
+ toContain("3 specs, 3 failures");
419
+ });
420
+
421
+ it("handles pluralization with 1's ones appropriately", function() {
422
+ reporter.reportRunnerResults({
423
+ specs: function() {
424
+ return [null];
425
+ },
426
+ results:function() {
427
+ return {items_: [null], totalCount: 1, failedCount: 1};
428
+ }
429
+ });
430
+ expect(out.getOutput()).
431
+ toContain("1 spec, 1 failure");
432
+ });
433
+ });
434
+
435
+ describe("done callback", function() {
436
+ it("calls back when done", function() {
437
+ expect(done).toBeFalsy();
438
+ reporter.reportRunnerResults({
439
+ specs: function() {
440
+ return [null, null, null];
441
+ },
442
+ results:function() {
443
+ return {items_: [null, null, null], totalCount: 7, failedCount: 0};
444
+ }
445
+ });
446
+ expect(done).toBeTruthy();
447
+ });
448
+ });
449
+ });
450
+ });
451
+ });