jasmine-core 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/console/console.js +26 -2
  3. data/lib/jasmine-core.js +31 -23
  4. data/lib/jasmine-core/boot.js +1 -1
  5. data/lib/jasmine-core/boot/boot.js +1 -1
  6. data/lib/jasmine-core/example/node_example/spec/PlayerSpec.js +2 -2
  7. data/lib/jasmine-core/jasmine-html.js +16 -2
  8. data/lib/jasmine-core/jasmine.css +11 -10
  9. data/lib/jasmine-core/jasmine.js +709 -395
  10. data/lib/jasmine-core/json2.js +73 -62
  11. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +39 -8
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +19 -1
  13. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +13 -0
  14. data/lib/jasmine-core/spec/core/EnvSpec.js +0 -63
  15. data/lib/jasmine-core/spec/core/ExpectationSpec.js +15 -53
  16. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +37 -0
  17. data/lib/jasmine-core/spec/core/MockDateSpec.js +1 -0
  18. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +8 -2
  19. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +91 -66
  20. data/lib/jasmine-core/spec/core/SpecSpec.js +25 -26
  21. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +55 -0
  22. data/lib/jasmine-core/spec/core/SpySpec.js +10 -0
  23. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +13 -0
  24. data/lib/jasmine-core/spec/core/SuiteSpec.js +108 -10
  25. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +34 -32
  26. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +950 -35
  27. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +279 -3
  28. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +10 -1
  29. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +5 -5
  30. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +30 -2
  31. data/lib/jasmine-core/spec/node_suite.js +195 -0
  32. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +104 -0
  33. data/lib/jasmine-core/version.rb +1 -1
  34. metadata +6 -3
@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
159
159
  ];
160
160
  expect(actions).toEqual(expected);
161
161
  done();
162
- }
162
+ };
163
163
 
164
164
  env.addReporter({jasmineDone: assertions});
165
165
 
@@ -228,6 +228,257 @@ describe("jasmine spec running", function () {
228
228
  env.execute();
229
229
  });
230
230
 
231
+ it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function() {
232
+ var actions = [];
233
+
234
+ env.beforeAll(function() {
235
+ actions.push('runner beforeAll');
236
+ });
237
+
238
+ env.afterAll(function() {
239
+ actions.push('runner afterAll');
240
+ });
241
+
242
+ env.beforeEach(function () {
243
+ actions.push('runner beforeEach');
244
+ });
245
+
246
+ env.afterEach(function () {
247
+ actions.push('runner afterEach');
248
+ });
249
+
250
+ env.describe('Something', function() {
251
+ env.beforeEach(function() {
252
+ actions.push('inner beforeEach');
253
+ });
254
+
255
+ env.afterEach(function() {
256
+ actions.push('inner afterEach');
257
+ });
258
+
259
+ env.beforeAll(function() {
260
+ actions.push('inner beforeAll');
261
+ });
262
+
263
+ env.afterAll(function() {
264
+ actions.push('inner afterAll');
265
+ });
266
+
267
+ env.it('does something or other', function() {
268
+ actions.push('it');
269
+ });
270
+ });
271
+
272
+ var assertions = function() {
273
+ var expected = [
274
+ "runner beforeAll",
275
+ "inner beforeAll",
276
+ "runner beforeEach",
277
+ "inner beforeEach",
278
+ "it",
279
+ "inner afterEach",
280
+ "runner afterEach",
281
+ "inner afterAll",
282
+ "runner afterAll"
283
+ ];
284
+ expect(actions).toEqual(expected);
285
+ done();
286
+ };
287
+
288
+ env.addReporter({jasmineDone: assertions});
289
+ env.execute();
290
+ });
291
+
292
+ it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function() {
293
+ var actions = [],
294
+ spec,
295
+ spec2;
296
+
297
+ env.beforeAll(function() {
298
+ actions.push('runner beforeAll');
299
+ });
300
+
301
+ env.afterAll(function() {
302
+ actions.push('runner afterAll');
303
+ });
304
+
305
+ env.beforeEach(function () {
306
+ actions.push('runner beforeEach');
307
+ });
308
+
309
+ env.afterEach(function () {
310
+ actions.push('runner afterEach');
311
+ });
312
+
313
+ env.describe('Something', function() {
314
+ env.beforeEach(function() {
315
+ actions.push('inner beforeEach');
316
+ });
317
+
318
+ env.afterEach(function() {
319
+ actions.push('inner afterEach');
320
+ });
321
+
322
+ env.beforeAll(function() {
323
+ actions.push('inner beforeAll');
324
+ });
325
+
326
+ env.afterAll(function() {
327
+ actions.push('inner afterAll');
328
+ });
329
+
330
+ spec = env.it('does something', function() {
331
+ actions.push('it');
332
+ });
333
+
334
+ spec2 = env.it('does something or other', function() {
335
+ actions.push('it2');
336
+ });
337
+ });
338
+
339
+ var assertions = function() {
340
+ var expected = [
341
+ "runner beforeAll",
342
+ "inner beforeAll",
343
+ "runner beforeEach",
344
+ "inner beforeEach",
345
+ "it",
346
+ "inner afterEach",
347
+ "runner afterEach",
348
+ "inner afterAll",
349
+ "runner afterAll",
350
+
351
+ "runner beforeAll",
352
+ "inner beforeAll",
353
+ "runner beforeEach",
354
+ "inner beforeEach",
355
+ "it2",
356
+ "inner afterEach",
357
+ "runner afterEach",
358
+ "inner afterAll",
359
+ "runner afterAll"
360
+ ];
361
+ expect(actions).toEqual(expected);
362
+ done();
363
+ };
364
+
365
+ env.addReporter({jasmineDone: assertions});
366
+ env.execute([spec.id, spec2.id]);
367
+ });
368
+
369
+ describe('focused runnables', function() {
370
+ it('runs the relevant alls and eachs for each runnable', function(done) {
371
+ var actions = [];
372
+ env.beforeAll(function() {actions.push('beforeAll')});
373
+ env.afterAll(function() {actions.push('afterAll')});
374
+ env.beforeEach(function() {actions.push('beforeEach')});
375
+ env.afterEach(function() {actions.push('afterEach')});
376
+
377
+ env.fdescribe('a focused suite', function() {
378
+ env.it('is run', function() {
379
+ actions.push('spec in fdescribe')
380
+ });
381
+ });
382
+
383
+ env.describe('an unfocused suite', function() {
384
+ env.fit('has a focused spec', function() {
385
+ actions.push('focused spec')
386
+ });
387
+ });
388
+
389
+ var assertions = function() {
390
+ var expected = [
391
+ 'beforeAll',
392
+ 'beforeEach',
393
+ 'spec in fdescribe',
394
+ 'afterEach',
395
+ 'afterAll',
396
+
397
+ 'beforeAll',
398
+ 'beforeEach',
399
+ 'focused spec',
400
+ 'afterEach',
401
+ 'afterAll'
402
+ ];
403
+ expect(actions).toEqual(expected);
404
+ done();
405
+ };
406
+
407
+ env.addReporter({jasmineDone: assertions});
408
+ env.execute();
409
+ });
410
+
411
+ it('focused specs in focused suites cause non-focused siblings to not run', function(done){
412
+ var actions = [];
413
+
414
+ env.fdescribe('focused suite', function() {
415
+ env.it('unfocused spec', function() {
416
+ actions.push('unfocused spec')
417
+ });
418
+ env.fit('focused spec', function() {
419
+ actions.push('focused spec')
420
+ });
421
+ });
422
+
423
+ var assertions = function() {
424
+ var expected = ['focused spec'];
425
+ expect(actions).toEqual(expected);
426
+ done();
427
+ };
428
+
429
+ env.addReporter({jasmineDone: assertions});
430
+ env.execute();
431
+ });
432
+
433
+ it('focused suites in focused suites cause non-focused siblings to not run', function(done){
434
+ var actions = [];
435
+
436
+ env.fdescribe('focused suite', function() {
437
+ env.it('unfocused spec', function() {
438
+ actions.push('unfocused spec')
439
+ });
440
+ env.fdescribe('inner focused suite', function() {
441
+ env.it('inner spec', function() {
442
+ actions.push('inner spec');
443
+ });
444
+ });
445
+ });
446
+
447
+ var assertions = function() {
448
+ var expected = ['inner spec'];
449
+ expect(actions).toEqual(expected);
450
+ done();
451
+ };
452
+
453
+ env.addReporter({jasmineDone: assertions});
454
+ env.execute();
455
+ });
456
+
457
+ it('focused runnables unfocus ancestor focused suites', function() {
458
+ var actions = [];
459
+
460
+ env.fdescribe('focused suite', function() {
461
+ env.it('unfocused spec', function() {
462
+ actions.push('unfocused spec')
463
+ });
464
+ env.describe('inner focused suite', function() {
465
+ env.fit('focused spec', function() {
466
+ actions.push('focused spec');
467
+ });
468
+ });
469
+ });
470
+
471
+ var assertions = function() {
472
+ var expected = ['focused spec'];
473
+ expect(actions).toEqual(expected);
474
+ done();
475
+ };
476
+
477
+ env.addReporter({jasmineDone: assertions});
478
+ env.execute();
479
+ });
480
+ });
481
+
231
482
  it("shouldn't run disabled suites", function(done) {
232
483
  var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
233
484
  suite = env.describe('A Suite', function() {
@@ -236,10 +487,36 @@ describe("jasmine spec running", function () {
236
487
  });
237
488
  });
238
489
 
239
- suite.execute(function() {
490
+ var assertions = function() {
240
491
  expect(specInADisabledSuite).not.toHaveBeenCalled();
241
492
  done();
493
+ };
494
+
495
+ env.addReporter({jasmineDone: assertions});
496
+
497
+ env.execute();
498
+ });
499
+
500
+ it("should allow top level suites to be disabled", function() {
501
+ var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
502
+ otherSpec = jasmine.createSpy("otherSpec");
503
+
504
+ env.xdescribe('A disabled suite', function() {
505
+ env.it('spec inside a disabled suite', specInADisabledSuite);
506
+ });
507
+ env.describe('Another suite', function() {
508
+ env.it('another spec', otherSpec);
242
509
  });
510
+
511
+ var assertions = function() {
512
+ expect(specInADisabledSuite).not.toHaveBeenCalled();
513
+ expect(otherSpec).toHaveBeenCalled();
514
+ done();
515
+ };
516
+
517
+ env.addReporter({jasmineDone: assertions});
518
+
519
+ env.execute();
243
520
  });
244
521
 
245
522
  it("should set all pending specs to pending when a suite is run", function(done) {
@@ -254,7 +531,6 @@ describe("jasmine spec running", function () {
254
531
  });
255
532
  });
256
533
 
257
-
258
534
  // TODO: is this useful? It doesn't catch syntax errors
259
535
  xit("should recover gracefully when there are errors in describe functions", function() {
260
536
  var specs = [];
@@ -174,7 +174,7 @@ describe("matchersUtil", function() {
174
174
 
175
175
  describe("contains", function() {
176
176
  it("passes when expected is a substring of actual", function() {
177
- expect(j$.matchersUtil.contains("ABC", "B")).toBe(true);
177
+ expect(j$.matchersUtil.contains("ABC", "BC")).toBe(true);
178
178
  });
179
179
 
180
180
  it("fails when expected is a not substring of actual", function() {
@@ -207,6 +207,15 @@ describe("matchersUtil", function() {
207
207
  it("fails when actual is null", function() {
208
208
  expect(j$.matchersUtil.contains(null, 'A')).toBe(false);
209
209
  });
210
+
211
+ it("passes with array-like objects", function() {
212
+ var capturedArgs = null;
213
+ function testFunction(){
214
+ capturedArgs = arguments;
215
+ }
216
+ testFunction('foo', 'bar');
217
+ expect(j$.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
218
+ });
210
219
  });
211
220
 
212
221
  describe("buildMessage", function() {
@@ -155,7 +155,7 @@ describe("toThrowError", function() {
155
155
  result = matcher.compare(fn, Error);
156
156
 
157
157
  expect(result.pass).toBe(true);
158
- expect(result.message).toEqual("Expected function not to throw Error.");
158
+ expect(result.message()).toEqual("Expected function not to throw Error.");
159
159
  });
160
160
 
161
161
  it("passes if thrown is a custom error that takes arguments and the expected is the same error", function() {
@@ -175,7 +175,7 @@ describe("toThrowError", function() {
175
175
  result = matcher.compare(fn, CustomError);
176
176
 
177
177
  expect(result.pass).toBe(true);
178
- expect(result.message).toEqual("Expected function not to throw CustomError.");
178
+ expect(result.message()).toEqual("Expected function not to throw CustomError.");
179
179
  });
180
180
 
181
181
  it("fails if thrown is an Error and the expected is a different Error", function() {
@@ -191,7 +191,7 @@ describe("toThrowError", function() {
191
191
  result = matcher.compare(fn, TypeError);
192
192
 
193
193
  expect(result.pass).toBe(false);
194
- expect(result.message).toEqual("Expected function to throw TypeError, but it threw Error.");
194
+ expect(result.message()).toEqual("Expected function to throw TypeError, but it threw Error.");
195
195
  });
196
196
 
197
197
  it("passes if thrown is a type of Error and it is equal to the expected Error and message", function() {
@@ -259,7 +259,7 @@ describe("toThrowError", function() {
259
259
  result = matcher.compare(fn, TypeError, /foo/);
260
260
 
261
261
  expect(result.pass).toBe(true);
262
- expect(result.message()).toEqual("Expected function not to throw TypeError with message matching /foo/.");
262
+ expect(result.message()).toEqual("Expected function not to throw TypeError with a message matching /foo/.");
263
263
  });
264
264
 
265
265
  it("fails if thrown is a type of Error and the expected is a different Error", function() {
@@ -275,6 +275,6 @@ describe("toThrowError", function() {
275
275
  result = matcher.compare(fn, TypeError, /bar/);
276
276
 
277
277
  expect(result.pass).toBe(false);
278
- expect(result.message()).toEqual("Expected function to throw TypeError with message matching /bar/, but it threw TypeError with message 'foo'.");
278
+ expect(result.message()).toEqual("Expected function to throw TypeError with a message matching /bar/, but it threw TypeError with message 'foo'.");
279
279
  });
280
280
  });
@@ -65,8 +65,8 @@ describe("New HtmlReporter", function() {
65
65
 
66
66
  describe("when a spec is done", function() {
67
67
  it("logs errors to the console and prints a special symbol if it is an empty spec", function() {
68
- if (!window.console) {
69
- window.console = { error: function(){} };
68
+ if (typeof console === "undefined") {
69
+ console = { error: function(){} };
70
70
  }
71
71
 
72
72
  var env = new j$.Env(),
@@ -179,6 +179,34 @@ describe("New HtmlReporter", function() {
179
179
  });
180
180
  });
181
181
 
182
+ describe("when there are suite failures", function () {
183
+ it("displays the exceptions in their own alert bars", function(){
184
+ var env = new j$.Env(),
185
+ container = document.createElement("div"),
186
+ getContainer = function() { return container; },
187
+ reporter = new j$.HtmlReporter({
188
+ env: env,
189
+ getContainer: getContainer,
190
+ createElement: function() { return document.createElement.apply(document, arguments); },
191
+ createTextNode: function() { return document.createTextNode.apply(document, arguments); }
192
+ });
193
+
194
+ reporter.initialize();
195
+
196
+ reporter.jasmineStarted({});
197
+ reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My After All Exception' }] });
198
+ reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My Other Exception' }] });
199
+ reporter.jasmineDone({});
200
+
201
+ var alertBars = container.querySelectorAll(".alert .bar");
202
+
203
+ expect(alertBars.length).toEqual(3);
204
+ expect(alertBars[1].innerHTML).toMatch(/My After All Exception/);
205
+ expect(alertBars[1].getAttribute("class")).toEqual('bar errored');
206
+ expect(alertBars[2].innerHTML).toMatch(/My Other Exception/);
207
+ });
208
+ });
209
+
182
210
  describe("when Jasmine is done", function() {
183
211
  it("adds EMPTY to the link title of specs that have no expectations", function() {
184
212
  if (!window.console) {
@@ -0,0 +1,195 @@
1
+ var fs = require('fs');
2
+ var util = require('util');
3
+ var path = require('path');
4
+
5
+ // boot code for jasmine
6
+ var jasmineRequire = require('../lib/jasmine-core/jasmine.js');
7
+ var jasmine = jasmineRequire.core(jasmineRequire);
8
+
9
+ var consoleFns = require('../lib/console/console.js');
10
+ extend(jasmineRequire, consoleFns);
11
+ jasmineRequire.console(jasmineRequire, jasmine);
12
+
13
+ var env = jasmine.getEnv();
14
+
15
+ var jasmineInterface = {
16
+ describe: function(description, specDefinitions) {
17
+ return env.describe(description, specDefinitions);
18
+ },
19
+
20
+ xdescribe: function(description, specDefinitions) {
21
+ return env.xdescribe(description, specDefinitions);
22
+ },
23
+
24
+ it: function(desc, func) {
25
+ return env.it(desc, func);
26
+ },
27
+
28
+ xit: function(desc, func) {
29
+ return env.xit(desc, func);
30
+ },
31
+
32
+ beforeEach: function(beforeEachFunction) {
33
+ return env.beforeEach(beforeEachFunction);
34
+ },
35
+
36
+ afterEach: function(afterEachFunction) {
37
+ return env.afterEach(afterEachFunction);
38
+ },
39
+
40
+ expect: function(actual) {
41
+ return env.expect(actual);
42
+ },
43
+
44
+ spyOn: function(obj, methodName) {
45
+ return env.spyOn(obj, methodName);
46
+ },
47
+
48
+ jsApiReporter: new jasmine.JsApiReporter({
49
+ timer: new jasmine.Timer()
50
+ }),
51
+
52
+ beforeAll: function(beforeAllFunction) {
53
+ return env.beforeAll(beforeAllFunction);
54
+ },
55
+
56
+ afterAll: function(afterAllFunction) {
57
+ return env.afterAll(afterAllFunction);
58
+ }
59
+ };
60
+
61
+ extend(global, jasmineInterface);
62
+
63
+ function extend(destination, source) {
64
+ for (var property in source) destination[property] = source[property];
65
+ return destination;
66
+ }
67
+
68
+ jasmine.addCustomEqualityTester = function(tester) {
69
+ env.addCustomEqualityTester(tester);
70
+ };
71
+
72
+ jasmine.addMatchers = function(matchers) {
73
+ return env.addMatchers(matchers);
74
+ };
75
+
76
+ jasmine.clock = function() {
77
+ return env.clock;
78
+ };
79
+
80
+ // Jasmine "runner"
81
+ function executeSpecs(specs, done, isVerbose, showColors) {
82
+ global.jasmine = jasmine;
83
+
84
+ for (var i = 0; i < specs.length; i++) {
85
+ var filename = specs[i];
86
+ require(filename.replace(/\.\w+$/, ""));
87
+ }
88
+
89
+ var env = jasmine.getEnv();
90
+ var consoleReporter = new jasmine.ConsoleReporter({
91
+ print: util.print,
92
+ onComplete: done,
93
+ showColors: showColors,
94
+ timer: new jasmine.Timer()
95
+ });
96
+
97
+ env.addReporter(consoleReporter);
98
+ env.execute();
99
+ }
100
+
101
+ function getFiles(dir, matcher) {
102
+ var allFiles = [];
103
+
104
+ if (fs.statSync(dir).isFile() && dir.match(matcher)) {
105
+ allFiles.push(dir);
106
+ } else {
107
+ var files = fs.readdirSync(dir);
108
+ for (var i = 0, len = files.length; i < len; ++i) {
109
+ var filename = dir + '/' + files[i];
110
+ if (fs.statSync(filename).isFile() && filename.match(matcher)) {
111
+ allFiles.push(filename);
112
+ } else if (fs.statSync(filename).isDirectory()) {
113
+ var subfiles = getFiles(filename);
114
+ subfiles.forEach(function(result) {
115
+ allFiles.push(result);
116
+ });
117
+ }
118
+ }
119
+ }
120
+ return allFiles;
121
+ }
122
+
123
+ function getSpecFiles(dir) {
124
+ return getFiles(dir, new RegExp("Spec.js$"));
125
+ }
126
+
127
+ var j$require = (function() {
128
+ var exported = {},
129
+ j$req;
130
+
131
+ global.getJasmineRequireObj = getJasmineRequireObj;
132
+
133
+ j$req = require(__dirname + "/../src/core/requireCore.js");
134
+ extend(j$req, require(__dirname + "/../src/console/requireConsole.js"));
135
+
136
+ var srcFiles = getFiles(__dirname + "/../src/core");
137
+ srcFiles.push(__dirname + "/../src/version.js");
138
+ srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js");
139
+
140
+ for (var i = 0; i < srcFiles.length; i++) {
141
+ require(srcFiles[i]);
142
+ }
143
+ extend(j$req, exported);
144
+
145
+ delete global.getJasmineRequireObj;
146
+
147
+ return j$req;
148
+
149
+ function getJasmineRequireObj() {
150
+ return exported;
151
+ }
152
+ }());
153
+
154
+ j$ = j$require.core(j$require);
155
+ j$require.console(j$require, j$);
156
+
157
+ // options from command line
158
+ var isVerbose = false;
159
+ var showColors = true;
160
+ var perfSuite = false;
161
+
162
+ process.argv.forEach(function(arg) {
163
+ switch (arg) {
164
+ case '--color':
165
+ showColors = true;
166
+ break;
167
+ case '--noColor':
168
+ showColors = false;
169
+ break;
170
+ case '--verbose':
171
+ isVerbose = true;
172
+ break;
173
+ case '--perf':
174
+ perfSuite = true;
175
+ break;
176
+ }
177
+ });
178
+
179
+ specs = [];
180
+
181
+ if (perfSuite) {
182
+ specs = getFiles(__dirname + '/performance', new RegExp("test.js$"));
183
+ } else {
184
+ var consoleSpecs = getSpecFiles(__dirname + "/console"),
185
+ coreSpecs = getSpecFiles(__dirname + "/core"),
186
+ specs = consoleSpecs.concat(coreSpecs);
187
+ }
188
+
189
+ executeSpecs(specs, function(passed) {
190
+ if (passed) {
191
+ process.exit(0);
192
+ } else {
193
+ process.exit(1);
194
+ }
195
+ }, isVerbose, showColors);