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
@@ -1,6 +1,6 @@
1
1
  /*
2
- http://www.JSON.org/json2.js
3
- 2009-08-17
2
+ json2.js
3
+ 2014-02-04
4
4
 
5
5
  Public Domain.
6
6
 
@@ -8,6 +8,14 @@
8
8
 
9
9
  See http://www.JSON.org/js.html
10
10
 
11
+
12
+ This code should be minified before deployment.
13
+ See http://javascript.crockford.com/jsmin.html
14
+
15
+ USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
16
+ NOT CONTROL.
17
+
18
+
11
19
  This file creates a global JSON object containing two methods: stringify
12
20
  and parse.
13
21
 
@@ -136,15 +144,9 @@
136
144
 
137
145
  This is a reference implementation. You are free to copy, modify, or
138
146
  redistribute.
139
-
140
- This code should be minified before deployment.
141
- See http://javascript.crockford.com/jsmin.html
142
-
143
- USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
144
- NOT CONTROL.
145
147
  */
146
148
 
147
- /*jslint evil: true */
149
+ /*jslint evil: true, regexp: true */
148
150
 
149
151
  /*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
150
152
  call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
@@ -153,16 +155,16 @@
153
155
  test, toJSON, toString, valueOf
154
156
  */
155
157
 
156
- "use strict";
157
158
 
158
159
  // Create a JSON object only if one does not already exist. We create the
159
160
  // methods in a closure to avoid creating global variables.
160
161
 
161
- if (!this.JSON) {
162
- this.JSON = {};
162
+ if (typeof JSON !== 'object') {
163
+ JSON = {};
163
164
  }
164
165
 
165
166
  (function () {
167
+ 'use strict';
166
168
 
167
169
  function f(n) {
168
170
  // Format integers to have at least two digits.
@@ -171,37 +173,30 @@ if (!this.JSON) {
171
173
 
172
174
  if (typeof Date.prototype.toJSON !== 'function') {
173
175
 
174
- Date.prototype.toJSON = function (key) {
176
+ Date.prototype.toJSON = function () {
175
177
 
176
- return isFinite(this.valueOf()) ?
177
- this.getUTCFullYear() + '-' +
178
- f(this.getUTCMonth() + 1) + '-' +
179
- f(this.getUTCDate()) + 'T' +
180
- f(this.getUTCHours()) + ':' +
181
- f(this.getUTCMinutes()) + ':' +
182
- f(this.getUTCSeconds()) + 'Z' : null;
178
+ return isFinite(this.valueOf())
179
+ ? this.getUTCFullYear() + '-' +
180
+ f(this.getUTCMonth() + 1) + '-' +
181
+ f(this.getUTCDate()) + 'T' +
182
+ f(this.getUTCHours()) + ':' +
183
+ f(this.getUTCMinutes()) + ':' +
184
+ f(this.getUTCSeconds()) + 'Z'
185
+ : null;
183
186
  };
184
187
 
185
- String.prototype.toJSON =
186
- Number.prototype.toJSON =
187
- Boolean.prototype.toJSON = function (key) {
188
- return this.valueOf();
189
- };
188
+ String.prototype.toJSON =
189
+ Number.prototype.toJSON =
190
+ Boolean.prototype.toJSON = function () {
191
+ return this.valueOf();
192
+ };
190
193
  }
191
194
 
192
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
193
- escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
195
+ var cx,
196
+ escapable,
194
197
  gap,
195
198
  indent,
196
- meta = { // table of character substitutions
197
- '\b': '\\b',
198
- '\t': '\\t',
199
- '\n': '\\n',
200
- '\f': '\\f',
201
- '\r': '\\r',
202
- '"' : '\\"',
203
- '\\': '\\\\'
204
- },
199
+ meta,
205
200
  rep;
206
201
 
207
202
 
@@ -213,17 +208,17 @@ if (!this.JSON) {
213
208
  // sequences.
214
209
 
215
210
  escapable.lastIndex = 0;
216
- return escapable.test(string) ?
217
- '"' + string.replace(escapable, function (a) {
218
- var c = meta[a];
219
- return typeof c === 'string' ? c :
220
- '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
221
- }) + '"' :
222
- '"' + string + '"';
211
+ return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
212
+ var c = meta[a];
213
+ return typeof c === 'string'
214
+ ? c
215
+ : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
216
+ }) + '"' : '"' + string + '"';
223
217
  }
224
218
 
225
219
 
226
220
  function str(key, holder) {
221
+
227
222
  // Produce a string from holder[key].
228
223
 
229
224
  var i, // The loop counter.
@@ -301,11 +296,11 @@ if (!this.JSON) {
301
296
  // Join all of the elements together, separated with commas, and wrap them in
302
297
  // brackets.
303
298
 
304
- v = partial.length === 0 ? '[]' :
305
- gap ? '[\n' + gap +
306
- partial.join(',\n' + gap) + '\n' +
307
- mind + ']' :
308
- '[' + partial.join(',') + ']';
299
+ v = partial.length === 0
300
+ ? '[]'
301
+ : gap
302
+ ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
303
+ : '[' + partial.join(',') + ']';
309
304
  gap = mind;
310
305
  return v;
311
306
  }
@@ -315,8 +310,8 @@ if (!this.JSON) {
315
310
  if (rep && typeof rep === 'object') {
316
311
  length = rep.length;
317
312
  for (i = 0; i < length; i += 1) {
318
- k = rep[i];
319
- if (typeof k === 'string') {
313
+ if (typeof rep[i] === 'string') {
314
+ k = rep[i];
320
315
  v = str(k, value);
321
316
  if (v) {
322
317
  partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -328,7 +323,7 @@ if (!this.JSON) {
328
323
  // Otherwise, iterate through all of the keys in the object.
329
324
 
330
325
  for (k in value) {
331
- if (Object.hasOwnProperty.call(value, k)) {
326
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
332
327
  v = str(k, value);
333
328
  if (v) {
334
329
  partial.push(quote(k) + (gap ? ': ' : ':') + v);
@@ -340,9 +335,11 @@ if (!this.JSON) {
340
335
  // Join all of the member texts together, separated with commas,
341
336
  // and wrap them in braces.
342
337
 
343
- v = partial.length === 0 ? '{}' :
344
- gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
345
- mind + '}' : '{' + partial.join(',') + '}';
338
+ v = partial.length === 0
339
+ ? '{}'
340
+ : gap
341
+ ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
342
+ : '{' + partial.join(',') + '}';
346
343
  gap = mind;
347
344
  return v;
348
345
  }
@@ -351,7 +348,18 @@ if (!this.JSON) {
351
348
  // If the JSON object does not yet have a stringify method, give it one.
352
349
 
353
350
  if (typeof JSON.stringify !== 'function') {
351
+ escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
352
+ meta = { // table of character substitutions
353
+ '\b': '\\b',
354
+ '\t': '\\t',
355
+ '\n': '\\n',
356
+ '\f': '\\f',
357
+ '\r': '\\r',
358
+ '"' : '\\"',
359
+ '\\': '\\\\'
360
+ };
354
361
  JSON.stringify = function (value, replacer, space) {
362
+
355
363
  // The stringify method takes a value and an optional replacer, and an optional
356
364
  // space parameter, and returns a JSON text. The replacer can be a function
357
365
  // that can replace values, or an array of strings that will select the keys.
@@ -382,7 +390,7 @@ if (!this.JSON) {
382
390
  rep = replacer;
383
391
  if (replacer && typeof replacer !== 'function' &&
384
392
  (typeof replacer !== 'object' ||
385
- typeof replacer.length !== 'number')) {
393
+ typeof replacer.length !== 'number')) {
386
394
  throw new Error('JSON.stringify');
387
395
  }
388
396
 
@@ -397,6 +405,7 @@ if (!this.JSON) {
397
405
  // If the JSON object does not yet have a parse method, give it one.
398
406
 
399
407
  if (typeof JSON.parse !== 'function') {
408
+ cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
400
409
  JSON.parse = function (text, reviver) {
401
410
 
402
411
  // The parse method takes a text and an optional reviver function, and returns
@@ -412,7 +421,7 @@ if (!this.JSON) {
412
421
  var k, v, value = holder[key];
413
422
  if (value && typeof value === 'object') {
414
423
  for (k in value) {
415
- if (Object.hasOwnProperty.call(value, k)) {
424
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
416
425
  v = walk(value, k);
417
426
  if (v !== undefined) {
418
427
  value[k] = v;
@@ -430,6 +439,7 @@ if (!this.JSON) {
430
439
  // Unicode characters with escape sequences. JavaScript handles many characters
431
440
  // incorrectly, either silently deleting them, or treating them as line endings.
432
441
 
442
+ text = String(text);
433
443
  cx.lastIndex = 0;
434
444
  if (cx.test(text)) {
435
445
  text = text.replace(cx, function (a) {
@@ -451,10 +461,10 @@ if (!this.JSON) {
451
461
  // we look to see that the remaining characters are only whitespace or ']' or
452
462
  // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
453
463
 
454
- if (/^[\],:{}\s]*$/.
455
- test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
456
- replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
457
- replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
464
+ if (/^[\],:{}\s]*$/
465
+ .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
466
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
467
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
458
468
 
459
469
  // In the third stage we use the eval function to compile the text into a
460
470
  // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
@@ -466,8 +476,9 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
466
476
  // In the optional fourth stage, we recursively walk the new structure, passing
467
477
  // each name/value pair to a reviver function for possible transformation.
468
478
 
469
- return typeof reviver === 'function' ?
470
- walk({'': j}, '') : j;
479
+ return typeof reviver === 'function'
480
+ ? walk({'': j}, '')
481
+ : j;
471
482
  }
472
483
 
473
484
  // If the text is not JSON parseable, then a SyntaxError is thrown.
@@ -9,7 +9,7 @@ describe("ConsoleReporter", function() {
9
9
  output += str;
10
10
  },
11
11
  getOutput: function() {
12
- return output;
12
+ return output.replace('ConsoleReporter is deprecated and will be removed in a future version.', '');
13
13
  },
14
14
  clear: function() {
15
15
  output = "";
@@ -171,27 +171,44 @@ describe("ConsoleReporter", function() {
171
171
 
172
172
  out.clear();
173
173
 
174
- reporter.jasmineDone({});
174
+ reporter.jasmineDone();
175
175
 
176
176
  expect(out.getOutput()).toMatch(/true to be false/);
177
177
  expect(out.getOutput()).toMatch(/foo bar baz/);
178
178
  });
179
179
 
180
- it("calls the onComplete callback when the suite is done", function() {
181
- var onComplete = jasmine.createSpy('onComplete'),
180
+ describe('onComplete callback', function(){
181
+ var onComplete, reporter;
182
+
183
+ beforeEach(function() {
184
+ onComplete = jasmine.createSpy('onComplete');
182
185
  reporter = new j$.ConsoleReporter({
183
186
  print: out.print,
184
187
  onComplete: onComplete
185
188
  });
189
+ reporter.jasmineStarted();
190
+ });
186
191
 
187
- reporter.jasmineDone({});
192
+ it("is called when the suite is done", function() {
193
+ reporter.jasmineDone();
194
+ expect(onComplete).toHaveBeenCalledWith(true);
195
+ });
188
196
 
189
- expect(onComplete).toHaveBeenCalled();
190
- });
197
+ it('calls it with false if there are spec failures', function() {
198
+ reporter.specDone({status: "failed", failedExpectations: []});
199
+ reporter.jasmineDone();
200
+ expect(onComplete).toHaveBeenCalledWith(false);
201
+ });
191
202
 
203
+ it('calls it with false if there are suite failures', function() {
204
+ reporter.specDone({status: "passed"});
205
+ reporter.suiteDone({failedExpectations: [{ message: 'bananas' }] });
206
+ reporter.jasmineDone();
207
+ expect(onComplete).toHaveBeenCalledWith(false);
208
+ });
209
+ });
192
210
 
193
211
  describe("with color", function() {
194
-
195
212
  it("reports that the suite has started to the console", function() {
196
213
  var reporter = new j$.ConsoleReporter({
197
214
  print: out.print,
@@ -235,5 +252,19 @@ describe("ConsoleReporter", function() {
235
252
 
236
253
  expect(out.getOutput()).toEqual("\x1B[31mF\x1B[0m");
237
254
  });
255
+
256
+ it("displays all afterAll exceptions", function() {
257
+ var reporter = new j$.ConsoleReporter({
258
+ print: out.print,
259
+ showColors: true
260
+ });
261
+
262
+ reporter.suiteDone({ failedExpectations: [{ message: 'After All Exception' }] });
263
+ reporter.suiteDone({ failedExpectations: [{ message: 'Some Other Exception' }] });
264
+ reporter.jasmineDone();
265
+
266
+ expect(out.getOutput()).toMatch(/After All Exception/);
267
+ expect(out.getOutput()).toMatch(/Some Other Exception/);
268
+ });
238
269
  });
239
270
  });
@@ -323,6 +323,24 @@ describe("Clock (acceptance)", function() {
323
323
  expect(clearedFn).not.toHaveBeenCalled();
324
324
  });
325
325
 
326
+ it("can clear a previously set interval using that interval's handler", function() {
327
+ var spy = jasmine.createSpy('spy'),
328
+ delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
329
+ mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
330
+ clock = new j$.Clock({setInterval: function() {}}, delayedFunctionScheduler, mockDate),
331
+ intervalId;
332
+
333
+ clock.install();
334
+
335
+ intervalId = clock.setInterval(function() {
336
+ spy();
337
+ clock.clearInterval(intervalId);
338
+ }, 100);
339
+ clock.tick(200);
340
+
341
+ expect(spy.calls.count()).toEqual(1);
342
+ });
343
+
326
344
  it("correctly schedules functions after the Clock has advanced", function() {
327
345
  var delayedFn1 = jasmine.createSpy('delayedFn1'),
328
346
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
@@ -371,7 +389,7 @@ describe("Clock (acceptance)", function() {
371
389
 
372
390
  clock.tick(6);
373
391
  expect(delayedFn1).toHaveBeenCalled();
374
- expect(delayedFn2).toHaveBeenCalled();
392
+ expect(delayedFn2).toHaveBeenCalled();
375
393
  });
376
394
 
377
395
  it("does not mock the Date object by default", function() {
@@ -242,5 +242,18 @@ describe("DelayedFunctionScheduler", function() {
242
242
  expect(innerFn).toHaveBeenCalled();
243
243
  });
244
244
 
245
+ it("executes recurring functions after rescheduling them", function () {
246
+ var scheduler = new j$.DelayedFunctionScheduler(),
247
+ recurring = function() {
248
+ expect(scheduler.scheduleFunction).toHaveBeenCalled();
249
+ };
250
+
251
+ scheduler.scheduleFunction(recurring, 10, [], true);
252
+
253
+ spyOn(scheduler, "scheduleFunction");
254
+
255
+ scheduler.tick(10);
256
+ });
257
+
245
258
  });
246
259
 
@@ -5,68 +5,6 @@ describe("Env", function() {
5
5
  env = new j$.Env();
6
6
  });
7
7
 
8
- it('removes all spies when env is executed', function(done) {
9
- var originalFoo = function() {},
10
- testObj = {
11
- foo: originalFoo
12
- },
13
- firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
14
- env.spyOn(testObj, 'foo');
15
- }),
16
- secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
17
- expect(testObj.foo).toBe(originalFoo);
18
- });
19
- env.describe('test suite', function() {
20
- env.it('spec 0', firstSpec);
21
- env.it('spec 1', secondSpec);
22
- });
23
-
24
- var assertions = function() {
25
- expect(firstSpec).toHaveBeenCalled();
26
- expect(secondSpec).toHaveBeenCalled();
27
- done();
28
- };
29
-
30
- env.addReporter({ jasmineDone: assertions });
31
-
32
- env.execute();
33
- });
34
-
35
- describe("#spyOn", function() {
36
- it("checks for the existence of the object", function() {
37
- expect(function() {
38
- env.spyOn(void 0, 'pants');
39
- }).toThrowError(/could not find an object/);
40
- });
41
-
42
- it("checks for the existence of the method", function() {
43
- var subject = {};
44
-
45
- expect(function() {
46
- env.spyOn(subject, 'pants');
47
- }).toThrowError(/method does not exist/);
48
- });
49
-
50
- it("checks if it has already been spied upon", function() {
51
- var subject = { spiedFunc: function() {} };
52
-
53
- env.spyOn(subject, 'spiedFunc');
54
-
55
- expect(function() {
56
- env.spyOn(subject, 'spiedFunc');
57
- }).toThrowError(/has already been spied upon/);
58
- });
59
-
60
- it("overrides the method on the object and returns the spy", function() {
61
- var originalFunctionWasCalled = false;
62
- var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
63
-
64
- var spy = env.spyOn(subject, 'spiedFunc');
65
-
66
- expect(subject.spiedFunc).toEqual(spy);
67
- });
68
- });
69
-
70
8
  describe("#pending", function() {
71
9
  it("throws the Pending Spec exception", function() {
72
10
  expect(function() {
@@ -82,4 +20,3 @@ describe("Env", function() {
82
20
  });
83
21
  });
84
22
  });
85
-