new 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +79 -0
  6. data/Guardfile +14 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +121 -0
  9. data/bin/new +6 -0
  10. data/lib/new/cli.rb +94 -0
  11. data/lib/new/core.rb +6 -0
  12. data/lib/new/dsl.rb +42 -0
  13. data/lib/new/interpolate.rb +100 -0
  14. data/lib/new/project.rb +34 -0
  15. data/lib/new/task.rb +41 -0
  16. data/lib/new/template.rb +64 -0
  17. data/lib/new/version.rb +41 -0
  18. data/lib/new.rb +72 -0
  19. data/spec/fixtures/custom/tasks/custom_bar_task/custom_bar_task.rb +3 -0
  20. data/spec/fixtures/custom/templates/custom_bar_template/custom_bar.txt +0 -0
  21. data/spec/fixtures/tasks/custom_bar_task/custom_bar_task.rb +1 -0
  22. data/spec/fixtures/tasks/foo_task/foo_task.rb +7 -0
  23. data/spec/fixtures/templates/foo_template/[FOO.BAR].txt.erb +1 -0
  24. data/spec/fixtures/templates/foo_template/nested_[FOO.BAR]/foo.txt.erb +1 -0
  25. data/spec/lib/new/cli_spec.rb +104 -0
  26. data/spec/lib/new/interpolate_spec.rb +41 -0
  27. data/spec/lib/new/project_spec.rb +30 -0
  28. data/spec/lib/new/task_spec.rb +39 -0
  29. data/spec/lib/new/template_spec.rb +59 -0
  30. data/spec/lib/new/version_spec.rb +28 -0
  31. data/spec/lib/new_spec.rb +19 -0
  32. data/spec/spec_helper.rb +26 -0
  33. data/tasks/gem/README.md +36 -0
  34. data/tasks/gem/gem.rb +118 -0
  35. data/templates/js/Gemfile +30 -0
  36. data/templates/js/Guardfile +7 -0
  37. data/templates/js/LICENSE-MIT.erb +22 -0
  38. data/templates/js/README.md.erb +61 -0
  39. data/templates/js/demo/index.html.erb +7 -0
  40. data/templates/js/lib/README.md +2 -0
  41. data/templates/js/spec/[PROJECT_NAME].spec.js.coffee.erb +1 -0
  42. data/templates/js/spec/index.html.erb +29 -0
  43. data/templates/js/spec/spec_helper.js.coffee +0 -0
  44. data/templates/js/spec/vendor/chai.js +3765 -0
  45. data/templates/js/spec/vendor/sinon-chai.js +106 -0
  46. data/templates/js/spec/vendor/sinon.js +4246 -0
  47. data/templates/js/src/README.md +3 -0
  48. data/templates/js/src/[PROJECT_NAME].js.coffee.erb +10 -0
  49. data/templates/js/testem.yml +12 -0
  50. metadata +102 -0
@@ -0,0 +1,4246 @@
1
+ /**
2
+ * Sinon.JS 1.6.0, 2013/02/18
3
+ *
4
+ * @author Christian Johansen (christian@cjohansen.no)
5
+ * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
6
+ *
7
+ * (The BSD License)
8
+ *
9
+ * Copyright (c) 2010-2013, Christian Johansen, christian@cjohansen.no
10
+ * All rights reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without modification,
13
+ * are permitted provided that the following conditions are met:
14
+ *
15
+ * * Redistributions of source code must retain the above copyright notice,
16
+ * this list of conditions and the following disclaimer.
17
+ * * Redistributions in binary form must reproduce the above copyright notice,
18
+ * this list of conditions and the following disclaimer in the documentation
19
+ * and/or other materials provided with the distribution.
20
+ * * Neither the name of Christian Johansen nor the names of his contributors
21
+ * may be used to endorse or promote products derived from this software
22
+ * without specific prior written permission.
23
+ *
24
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ */
35
+
36
+ var sinon = (function() {
37
+ "use strict";
38
+
39
+ var buster = (function(setTimeout, B) {
40
+ var isNode = typeof require == "function" && typeof module == "object";
41
+ var div = typeof document != "undefined" && document.createElement("div");
42
+ var F = function() {};
43
+
44
+ var buster = {
45
+ bind: function bind(obj, methOrProp) {
46
+ var method = typeof methOrProp == "string" ? obj[methOrProp] : methOrProp;
47
+ var args = Array.prototype.slice.call(arguments, 2);
48
+ return function() {
49
+ var allArgs = args.concat(Array.prototype.slice.call(arguments));
50
+ return method.apply(obj, allArgs);
51
+ };
52
+ },
53
+
54
+ partial: function partial(fn) {
55
+ var args = [].slice.call(arguments, 1);
56
+ return function() {
57
+ return fn.apply(this, args.concat([].slice.call(arguments)));
58
+ };
59
+ },
60
+
61
+ create: function create(object) {
62
+ F.prototype = object;
63
+ return new F();
64
+ },
65
+
66
+ extend: function extend(target) {
67
+ if (!target) {
68
+ return;
69
+ }
70
+ for (var i = 1, l = arguments.length, prop; i < l; ++i) {
71
+ for (prop in arguments[i]) {
72
+ target[prop] = arguments[i][prop];
73
+ }
74
+ }
75
+ return target;
76
+ },
77
+
78
+ nextTick: function nextTick(callback) {
79
+ if (typeof process != "undefined" && process.nextTick) {
80
+ return process.nextTick(callback);
81
+ }
82
+ setTimeout(callback, 0);
83
+ },
84
+
85
+ functionName: function functionName(func) {
86
+ if (!func) return "";
87
+ if (func.displayName) return func.displayName;
88
+ if (func.name) return func.name;
89
+ var matches = func.toString().match(/function\s+([^\(]+)/m);
90
+ return matches && matches[1] || "";
91
+ },
92
+
93
+ isNode: function isNode(obj) {
94
+ if (!div) return false;
95
+ try {
96
+ obj.appendChild(div);
97
+ obj.removeChild(div);
98
+ } catch (e) {
99
+ return false;
100
+ }
101
+ return true;
102
+ },
103
+
104
+ isElement: function isElement(obj) {
105
+ return obj && obj.nodeType === 1 && buster.isNode(obj);
106
+ },
107
+
108
+ isArray: function isArray(arr) {
109
+ return Object.prototype.toString.call(arr) == "[object Array]";
110
+ },
111
+
112
+ flatten: function flatten(arr) {
113
+ var result = [],
114
+ arr = arr || [];
115
+ for (var i = 0, l = arr.length; i < l; ++i) {
116
+ result = result.concat(buster.isArray(arr[i]) ? flatten(arr[i]) : arr[i]);
117
+ }
118
+ return result;
119
+ },
120
+
121
+ each: function each(arr, callback) {
122
+ for (var i = 0, l = arr.length; i < l; ++i) {
123
+ callback(arr[i]);
124
+ }
125
+ },
126
+
127
+ map: function map(arr, callback) {
128
+ var results = [];
129
+ for (var i = 0, l = arr.length; i < l; ++i) {
130
+ results.push(callback(arr[i]));
131
+ }
132
+ return results;
133
+ },
134
+
135
+ parallel: function parallel(fns, callback) {
136
+ function cb(err, res) {
137
+ if (typeof callback == "function") {
138
+ callback(err, res);
139
+ callback = null;
140
+ }
141
+ }
142
+ if (fns.length == 0) {
143
+ return cb(null, []);
144
+ }
145
+ var remaining = fns.length,
146
+ results = [];
147
+
148
+ function makeDone(num) {
149
+ return function done(err, result) {
150
+ if (err) {
151
+ return cb(err);
152
+ }
153
+ results[num] = result;
154
+ if (--remaining == 0) {
155
+ cb(null, results);
156
+ }
157
+ };
158
+ }
159
+ for (var i = 0, l = fns.length; i < l; ++i) {
160
+ fns[i](makeDone(i));
161
+ }
162
+ },
163
+
164
+ series: function series(fns, callback) {
165
+ function cb(err, res) {
166
+ if (typeof callback == "function") {
167
+ callback(err, res);
168
+ }
169
+ }
170
+ var remaining = fns.slice();
171
+ var results = [];
172
+
173
+ function callNext() {
174
+ if (remaining.length == 0) return cb(null, results);
175
+ var promise = remaining.shift()(next);
176
+ if (promise && typeof promise.then == "function") {
177
+ promise.then(buster.partial(next, null), next);
178
+ }
179
+ }
180
+
181
+ function next(err, result) {
182
+ if (err) return cb(err);
183
+ results.push(result);
184
+ callNext();
185
+ }
186
+ callNext();
187
+ },
188
+
189
+ countdown: function countdown(num, done) {
190
+ return function() {
191
+ if (--num == 0) done();
192
+ };
193
+ }
194
+ };
195
+
196
+ if (typeof process === "object" && typeof require === "function" && typeof module === "object") {
197
+ var crypto = require("crypto");
198
+ var path = require("path");
199
+
200
+ buster.tmpFile = function(fileName) {
201
+ var hashed = crypto.createHash("sha1");
202
+ hashed.update(fileName);
203
+ var tmpfileName = hashed.digest("hex");
204
+
205
+ if (process.platform == "win32") {
206
+ return path.join(process.env["TEMP"], tmpfileName);
207
+ } else {
208
+ return path.join("/tmp", tmpfileName);
209
+ }
210
+ };
211
+ }
212
+
213
+ if (Array.prototype.some) {
214
+ buster.some = function(arr, fn, thisp) {
215
+ return arr.some(fn, thisp);
216
+ };
217
+ } else {
218
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
219
+ buster.some = function(arr, fun, thisp) {
220
+ if (arr == null) {
221
+ throw new TypeError();
222
+ }
223
+ arr = Object(arr);
224
+ var len = arr.length >>> 0;
225
+ if (typeof fun !== "function") {
226
+ throw new TypeError();
227
+ }
228
+
229
+ for (var i = 0; i < len; i++) {
230
+ if (arr.hasOwnProperty(i) && fun.call(thisp, arr[i], i, arr)) {
231
+ return true;
232
+ }
233
+ }
234
+
235
+ return false;
236
+ };
237
+ }
238
+
239
+ if (Array.prototype.filter) {
240
+ buster.filter = function(arr, fn, thisp) {
241
+ return arr.filter(fn, thisp);
242
+ };
243
+ } else {
244
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
245
+ buster.filter = function(fn, thisp) {
246
+ if (this == null) {
247
+ throw new TypeError();
248
+ }
249
+
250
+ var t = Object(this);
251
+ var len = t.length >>> 0;
252
+ if (typeof fn != "function") {
253
+ throw new TypeError();
254
+ }
255
+
256
+ var res = [];
257
+ for (var i = 0; i < len; i++) {
258
+ if (i in t) {
259
+ var val = t[i]; // in case fun mutates this
260
+ if (fn.call(thisp, val, i, t)) {
261
+ res.push(val);
262
+ }
263
+ }
264
+ }
265
+
266
+ return res;
267
+ };
268
+ }
269
+
270
+ if (isNode) {
271
+ module.exports = buster;
272
+ buster.eventEmitter = require("./buster-event-emitter");
273
+ Object.defineProperty(buster, "defineVersionGetter", {
274
+ get: function() {
275
+ return require("./define-version-getter");
276
+ }
277
+ });
278
+ }
279
+
280
+ return buster.extend(B || {}, buster);
281
+ }(setTimeout, buster));
282
+ if (typeof buster === "undefined") {
283
+ var buster = {};
284
+ }
285
+
286
+ if (typeof module === "object" && typeof require === "function") {
287
+ buster = require("buster-core");
288
+ }
289
+
290
+ buster.format = buster.format || {};
291
+ buster.format.excludeConstructors = ["Object", /^.$/];
292
+ buster.format.quoteStrings = true;
293
+
294
+ buster.format.ascii = (function() {
295
+
296
+ var hasOwn = Object.prototype.hasOwnProperty;
297
+
298
+ var specialObjects = [];
299
+ if (typeof global != "undefined") {
300
+ specialObjects.push({
301
+ obj: global,
302
+ value: "[object global]"
303
+ });
304
+ }
305
+ if (typeof document != "undefined") {
306
+ specialObjects.push({
307
+ obj: document,
308
+ value: "[object HTMLDocument]"
309
+ });
310
+ }
311
+ if (typeof window != "undefined") {
312
+ specialObjects.push({
313
+ obj: window,
314
+ value: "[object Window]"
315
+ });
316
+ }
317
+
318
+ function keys(object) {
319
+ var k = Object.keys && Object.keys(object) || [];
320
+
321
+ if (k.length == 0) {
322
+ for (var prop in object) {
323
+ if (hasOwn.call(object, prop)) {
324
+ k.push(prop);
325
+ }
326
+ }
327
+ }
328
+
329
+ return k.sort();
330
+ }
331
+
332
+ function isCircular(object, objects) {
333
+ if (typeof object != "object") {
334
+ return false;
335
+ }
336
+
337
+ for (var i = 0, l = objects.length; i < l; ++i) {
338
+ if (objects[i] === object) {
339
+ return true;
340
+ }
341
+ }
342
+
343
+ return false;
344
+ }
345
+
346
+ function ascii(object, processed, indent) {
347
+ if (typeof object == "string") {
348
+ var quote = typeof this.quoteStrings != "boolean" || this.quoteStrings;
349
+ return processed || quote ? '"' + object + '"' : object;
350
+ }
351
+
352
+ if (typeof object == "function" && !(object instanceof RegExp)) {
353
+ return ascii.func(object);
354
+ }
355
+
356
+ processed = processed || [];
357
+
358
+ if (isCircular(object, processed)) {
359
+ return "[Circular]";
360
+ }
361
+
362
+ if (Object.prototype.toString.call(object) == "[object Array]") {
363
+ return ascii.array.call(this, object, processed);
364
+ }
365
+
366
+ if (!object) {
367
+ return "" + object;
368
+ }
369
+
370
+ if (buster.isElement(object)) {
371
+ return ascii.element(object);
372
+ }
373
+
374
+ if (typeof object.toString == "function" && object.toString !== Object.prototype.toString) {
375
+ return object.toString();
376
+ }
377
+
378
+ for (var i = 0, l = specialObjects.length; i < l; i++) {
379
+ if (object === specialObjects[i].obj) {
380
+ return specialObjects[i].value;
381
+ }
382
+ }
383
+
384
+ return ascii.object.call(this, object, processed, indent);
385
+ }
386
+
387
+ ascii.func = function(func) {
388
+ return "function " + buster.functionName(func) + "() {}";
389
+ };
390
+
391
+ ascii.array = function(array, processed) {
392
+ processed = processed || [];
393
+ processed.push(array);
394
+ var pieces = [];
395
+
396
+ for (var i = 0, l = array.length; i < l; ++i) {
397
+ pieces.push(ascii.call(this, array[i], processed));
398
+ }
399
+
400
+ return "[" + pieces.join(", ") + "]";
401
+ };
402
+
403
+ ascii.object = function(object, processed, indent) {
404
+ processed = processed || [];
405
+ processed.push(object);
406
+ indent = indent || 0;
407
+ var pieces = [],
408
+ properties = keys(object),
409
+ prop, str, obj;
410
+ var is = "";
411
+ var length = 3;
412
+
413
+ for (var i = 0, l = indent; i < l; ++i) {
414
+ is += " ";
415
+ }
416
+
417
+ for (i = 0, l = properties.length; i < l; ++i) {
418
+ prop = properties[i];
419
+ obj = object[prop];
420
+
421
+ if (isCircular(obj, processed)) {
422
+ str = "[Circular]";
423
+ } else {
424
+ str = ascii.call(this, obj, processed, indent + 2);
425
+ }
426
+
427
+ str = (/\s/.test(prop) ? '"' + prop + '"' : prop) + ": " + str;
428
+ length += str.length;
429
+ pieces.push(str);
430
+ }
431
+
432
+ var cons = ascii.constructorName.call(this, object);
433
+ var prefix = cons ? "[" + cons + "] " : ""
434
+
435
+ return (length + indent) > 80 ? prefix + "{\n " + is + pieces.join(",\n " + is) + "\n" + is + "}" : prefix + "{ " + pieces.join(", ") + " }";
436
+ };
437
+
438
+ ascii.element = function(element) {
439
+ var tagName = element.tagName.toLowerCase();
440
+ var attrs = element.attributes,
441
+ attribute, pairs = [],
442
+ attrName;
443
+
444
+ for (var i = 0, l = attrs.length; i < l; ++i) {
445
+ attribute = attrs.item(i);
446
+ attrName = attribute.nodeName.toLowerCase().replace("html:", "");
447
+
448
+ if (attrName == "contenteditable" && attribute.nodeValue == "inherit") {
449
+ continue;
450
+ }
451
+
452
+ if ( !! attribute.nodeValue) {
453
+ pairs.push(attrName + "=\"" + attribute.nodeValue + "\"");
454
+ }
455
+ }
456
+
457
+ var formatted = "<" + tagName + (pairs.length > 0 ? " " : "");
458
+ var content = element.innerHTML;
459
+
460
+ if (content.length > 20) {
461
+ content = content.substr(0, 20) + "[...]";
462
+ }
463
+
464
+ var res = formatted + pairs.join(" ") + ">" + content + "</" + tagName + ">";
465
+
466
+ return res.replace(/ contentEditable="inherit"/, "");
467
+ };
468
+
469
+ ascii.constructorName = function(object) {
470
+ var name = buster.functionName(object && object.constructor);
471
+ var excludes = this.excludeConstructors || buster.format.excludeConstructors || [];
472
+
473
+ for (var i = 0, l = excludes.length; i < l; ++i) {
474
+ if (typeof excludes[i] == "string" && excludes[i] == name) {
475
+ return "";
476
+ } else if (excludes[i].test && excludes[i].test(name)) {
477
+ return "";
478
+ }
479
+ }
480
+
481
+ return name;
482
+ };
483
+
484
+ return ascii;
485
+ }());
486
+
487
+ if (typeof module != "undefined") {
488
+ module.exports = buster.format;
489
+ }
490
+ /*jslint eqeqeq: false, onevar: false, forin: true, nomen: false, regexp: false, plusplus: false*/
491
+ /*global module, require, __dirname, document*/
492
+ /**
493
+ * Sinon core utilities. For internal use only.
494
+ *
495
+ * @author Christian Johansen (christian@cjohansen.no)
496
+ * @license BSD
497
+ *
498
+ * Copyright (c) 2010-2013 Christian Johansen
499
+ */
500
+
501
+ var sinon = (function(buster) {
502
+ var div = typeof document != "undefined" && document.createElement("div");
503
+ var hasOwn = Object.prototype.hasOwnProperty;
504
+
505
+ function isDOMNode(obj) {
506
+ var success = false;
507
+
508
+ try {
509
+ obj.appendChild(div);
510
+ success = div.parentNode == obj;
511
+ } catch (e) {
512
+ return false;
513
+ } finally {
514
+ try {
515
+ obj.removeChild(div);
516
+ } catch (e) {
517
+ // Remove failed, not much we can do about that
518
+ }
519
+ }
520
+
521
+ return success;
522
+ }
523
+
524
+ function isElement(obj) {
525
+ return div && obj && obj.nodeType === 1 && isDOMNode(obj);
526
+ }
527
+
528
+ function isFunction(obj) {
529
+ return typeof obj === "function" || !! (obj && obj.constructor && obj.call && obj.apply);
530
+ }
531
+
532
+ function mirrorProperties(target, source) {
533
+ for (var prop in source) {
534
+ if (!hasOwn.call(target, prop)) {
535
+ target[prop] = source[prop];
536
+ }
537
+ }
538
+ }
539
+
540
+ var sinon = {
541
+ wrapMethod: function wrapMethod(object, property, method) {
542
+ if (!object) {
543
+ throw new TypeError("Should wrap property of object");
544
+ }
545
+
546
+ if (typeof method != "function") {
547
+ throw new TypeError("Method wrapper should be function");
548
+ }
549
+
550
+ var wrappedMethod = object[property];
551
+
552
+ if (!isFunction(wrappedMethod)) {
553
+ throw new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + property + " as function");
554
+ }
555
+
556
+ if (wrappedMethod.restore && wrappedMethod.restore.sinon) {
557
+ throw new TypeError("Attempted to wrap " + property + " which is already wrapped");
558
+ }
559
+
560
+ if (wrappedMethod.calledBefore) {
561
+ var verb = !! wrappedMethod.returns ? "stubbed" : "spied on";
562
+ throw new TypeError("Attempted to wrap " + property + " which is already " + verb);
563
+ }
564
+
565
+ // IE 8 does not support hasOwnProperty on the window object.
566
+ var owned = hasOwn.call(object, property);
567
+ object[property] = method;
568
+ method.displayName = property;
569
+
570
+ method.restore = function() {
571
+ // For prototype properties try to reset by delete first.
572
+ // If this fails (ex: localStorage on mobile safari) then force a reset
573
+ // via direct assignment.
574
+ if (!owned) {
575
+ delete object[property];
576
+ }
577
+ if (object[property] === method) {
578
+ object[property] = wrappedMethod;
579
+ }
580
+ };
581
+
582
+ method.restore.sinon = true;
583
+ mirrorProperties(method, wrappedMethod);
584
+
585
+ return method;
586
+ },
587
+
588
+ extend: function extend(target) {
589
+ for (var i = 1, l = arguments.length; i < l; i += 1) {
590
+ for (var prop in arguments[i]) {
591
+ if (arguments[i].hasOwnProperty(prop)) {
592
+ target[prop] = arguments[i][prop];
593
+ }
594
+
595
+ // DONT ENUM bug, only care about toString
596
+ if (arguments[i].hasOwnProperty("toString") && arguments[i].toString != target.toString) {
597
+ target.toString = arguments[i].toString;
598
+ }
599
+ }
600
+ }
601
+
602
+ return target;
603
+ },
604
+
605
+ create: function create(proto) {
606
+ var F = function() {};
607
+ F.prototype = proto;
608
+ return new F();
609
+ },
610
+
611
+ deepEqual: function deepEqual(a, b) {
612
+ if (sinon.match && sinon.match.isMatcher(a)) {
613
+ return a.test(b);
614
+ }
615
+ if (typeof a != "object" || typeof b != "object") {
616
+ return a === b;
617
+ }
618
+
619
+ if (isElement(a) || isElement(b)) {
620
+ return a === b;
621
+ }
622
+
623
+ if (a === b) {
624
+ return true;
625
+ }
626
+
627
+ if ((a === null && b !== null) || (a !== null && b === null)) {
628
+ return false;
629
+ }
630
+
631
+ var aString = Object.prototype.toString.call(a);
632
+ if (aString != Object.prototype.toString.call(b)) {
633
+ return false;
634
+ }
635
+
636
+ if (aString == "[object Array]") {
637
+ if (a.length !== b.length) {
638
+ return false;
639
+ }
640
+
641
+ for (var i = 0, l = a.length; i < l; i += 1) {
642
+ if (!deepEqual(a[i], b[i])) {
643
+ return false;
644
+ }
645
+ }
646
+
647
+ return true;
648
+ }
649
+
650
+ var prop, aLength = 0,
651
+ bLength = 0;
652
+
653
+ for (prop in a) {
654
+ aLength += 1;
655
+
656
+ if (!deepEqual(a[prop], b[prop])) {
657
+ return false;
658
+ }
659
+ }
660
+
661
+ for (prop in b) {
662
+ bLength += 1;
663
+ }
664
+
665
+ if (aLength != bLength) {
666
+ return false;
667
+ }
668
+
669
+ return true;
670
+ },
671
+
672
+ functionName: function functionName(func) {
673
+ var name = func.displayName || func.name;
674
+
675
+ // Use function decomposition as a last resort to get function
676
+ // name. Does not rely on function decomposition to work - if it
677
+ // doesn't debugging will be slightly less informative
678
+ // (i.e. toString will say 'spy' rather than 'myFunc').
679
+ if (!name) {
680
+ var matches = func.toString().match(/function ([^\s\(]+)/);
681
+ name = matches && matches[1];
682
+ }
683
+
684
+ return name;
685
+ },
686
+
687
+ functionToString: function toString() {
688
+ if (this.getCall && this.callCount) {
689
+ var thisValue, prop, i = this.callCount;
690
+
691
+ while (i--) {
692
+ thisValue = this.getCall(i).thisValue;
693
+
694
+ for (prop in thisValue) {
695
+ if (thisValue[prop] === this) {
696
+ return prop;
697
+ }
698
+ }
699
+ }
700
+ }
701
+
702
+ return this.displayName || "sinon fake";
703
+ },
704
+
705
+ getConfig: function(custom) {
706
+ var config = {};
707
+ custom = custom || {};
708
+ var defaults = sinon.defaultConfig;
709
+
710
+ for (var prop in defaults) {
711
+ if (defaults.hasOwnProperty(prop)) {
712
+ config[prop] = custom.hasOwnProperty(prop) ? custom[prop] : defaults[prop];
713
+ }
714
+ }
715
+
716
+ return config;
717
+ },
718
+
719
+ format: function(val) {
720
+ return "" + val;
721
+ },
722
+
723
+ defaultConfig: {
724
+ injectIntoThis: true,
725
+ injectInto: null,
726
+ properties: ["spy", "stub", "mock", "clock", "server", "requests"],
727
+ useFakeTimers: true,
728
+ useFakeServer: true
729
+ },
730
+
731
+ timesInWords: function timesInWords(count) {
732
+ return count == 1 && "once" || count == 2 && "twice" || count == 3 && "thrice" || (count || 0) + " times";
733
+ },
734
+
735
+ calledInOrder: function(spies) {
736
+ for (var i = 1, l = spies.length; i < l; i++) {
737
+ if (!spies[i - 1].calledBefore(spies[i]) || !spies[i].called) {
738
+ return false;
739
+ }
740
+ }
741
+
742
+ return true;
743
+ },
744
+
745
+ orderByFirstCall: function(spies) {
746
+ return spies.sort(function(a, b) {
747
+ // uuid, won't ever be equal
748
+ var aCall = a.getCall(0);
749
+ var bCall = b.getCall(0);
750
+ var aId = aCall && aCall.callId || -1;
751
+ var bId = bCall && bCall.callId || -1;
752
+
753
+ return aId < bId ? -1 : 1;
754
+ });
755
+ },
756
+
757
+ log: function() {},
758
+
759
+ logError: function(label, err) {
760
+ var msg = label + " threw exception: "
761
+ sinon.log(msg + "[" + err.name + "] " + err.message);
762
+ if (err.stack) {
763
+ sinon.log(err.stack);
764
+ }
765
+
766
+ setTimeout(function() {
767
+ err.message = msg + err.message;
768
+ throw err;
769
+ }, 0);
770
+ },
771
+
772
+ typeOf: function(value) {
773
+ if (value === null) {
774
+ return "null";
775
+ } else if (value === undefined) {
776
+ return "undefined";
777
+ }
778
+ var string = Object.prototype.toString.call(value);
779
+ return string.substring(8, string.length - 1).toLowerCase();
780
+ },
781
+
782
+ createStubInstance: function(constructor) {
783
+ if (typeof constructor !== "function") {
784
+ throw new TypeError("The constructor should be a function.");
785
+ }
786
+ return sinon.stub(sinon.create(constructor.prototype));
787
+ }
788
+ };
789
+
790
+ var isNode = typeof module == "object" && typeof require == "function";
791
+
792
+ if (isNode) {
793
+ try {
794
+ buster = {
795
+ format: require("buster-format")
796
+ };
797
+ } catch (e) {}
798
+ module.exports = sinon;
799
+ module.exports.spy = require("./sinon/spy");
800
+ module.exports.stub = require("./sinon/stub");
801
+ module.exports.mock = require("./sinon/mock");
802
+ module.exports.collection = require("./sinon/collection");
803
+ module.exports.assert = require("./sinon/assert");
804
+ module.exports.sandbox = require("./sinon/sandbox");
805
+ module.exports.test = require("./sinon/test");
806
+ module.exports.testCase = require("./sinon/test_case");
807
+ module.exports.assert = require("./sinon/assert");
808
+ module.exports.match = require("./sinon/match");
809
+ }
810
+
811
+ if (buster) {
812
+ var formatter = sinon.create(buster.format);
813
+ formatter.quoteStrings = false;
814
+ sinon.format = function() {
815
+ return formatter.ascii.apply(formatter, arguments);
816
+ };
817
+ } else if (isNode) {
818
+ try {
819
+ var util = require("util");
820
+ sinon.format = function(value) {
821
+ return typeof value == "object" && value.toString === Object.prototype.toString ? util.inspect(value) : value;
822
+ };
823
+ } catch (e) {
824
+ /* Node, but no util module - would be very old, but better safe than
825
+ sorry */
826
+ }
827
+ }
828
+
829
+ return sinon;
830
+ }(typeof buster == "object" && buster));
831
+
832
+ /* @depend ../sinon.js */
833
+ /*jslint eqeqeq: false, onevar: false, plusplus: false*/
834
+ /*global module, require, sinon*/
835
+ /**
836
+ * Match functions
837
+ *
838
+ * @author Maximilian Antoni (mail@maxantoni.de)
839
+ * @license BSD
840
+ *
841
+ * Copyright (c) 2012 Maximilian Antoni
842
+ */
843
+
844
+ (function(sinon) {
845
+ var commonJSModule = typeof module == "object" && typeof require == "function";
846
+
847
+ if (!sinon && commonJSModule) {
848
+ sinon = require("../sinon");
849
+ }
850
+
851
+ if (!sinon) {
852
+ return;
853
+ }
854
+
855
+ function assertType(value, type, name) {
856
+ var actual = sinon.typeOf(value);
857
+ if (actual !== type) {
858
+ throw new TypeError("Expected type of " + name + " to be " + type + ", but was " + actual);
859
+ }
860
+ }
861
+
862
+ var matcher = {
863
+ toString: function() {
864
+ return this.message;
865
+ }
866
+ };
867
+
868
+ function isMatcher(object) {
869
+ return matcher.isPrototypeOf(object);
870
+ }
871
+
872
+ function matchObject(expectation, actual) {
873
+ if (actual === null || actual === undefined) {
874
+ return false;
875
+ }
876
+ for (var key in expectation) {
877
+ if (expectation.hasOwnProperty(key)) {
878
+ var exp = expectation[key];
879
+ var act = actual[key];
880
+ if (match.isMatcher(exp)) {
881
+ if (!exp.test(act)) {
882
+ return false;
883
+ }
884
+ } else if (sinon.typeOf(exp) === "object") {
885
+ if (!matchObject(exp, act)) {
886
+ return false;
887
+ }
888
+ } else if (!sinon.deepEqual(exp, act)) {
889
+ return false;
890
+ }
891
+ }
892
+ }
893
+ return true;
894
+ }
895
+
896
+ matcher.or = function(m2) {
897
+ if (!isMatcher(m2)) {
898
+ throw new TypeError("Matcher expected");
899
+ }
900
+ var m1 = this;
901
+ var or = sinon.create(matcher);
902
+ or.test = function(actual) {
903
+ return m1.test(actual) || m2.test(actual);
904
+ };
905
+ or.message = m1.message + ".or(" + m2.message + ")";
906
+ return or;
907
+ };
908
+
909
+ matcher.and = function(m2) {
910
+ if (!isMatcher(m2)) {
911
+ throw new TypeError("Matcher expected");
912
+ }
913
+ var m1 = this;
914
+ var and = sinon.create(matcher);
915
+ and.test = function(actual) {
916
+ return m1.test(actual) && m2.test(actual);
917
+ };
918
+ and.message = m1.message + ".and(" + m2.message + ")";
919
+ return and;
920
+ };
921
+
922
+ var match = function(expectation, message) {
923
+ var m = sinon.create(matcher);
924
+ var type = sinon.typeOf(expectation);
925
+ switch (type) {
926
+ case "object":
927
+ if (typeof expectation.test === "function") {
928
+ m.test = function(actual) {
929
+ return expectation.test(actual) === true;
930
+ };
931
+ m.message = "match(" + sinon.functionName(expectation.test) + ")";
932
+ return m;
933
+ }
934
+ var str = [];
935
+ for (var key in expectation) {
936
+ if (expectation.hasOwnProperty(key)) {
937
+ str.push(key + ": " + expectation[key]);
938
+ }
939
+ }
940
+ m.test = function(actual) {
941
+ return matchObject(expectation, actual);
942
+ };
943
+ m.message = "match(" + str.join(", ") + ")";
944
+ break;
945
+ case "number":
946
+ m.test = function(actual) {
947
+ return expectation == actual;
948
+ };
949
+ break;
950
+ case "string":
951
+ m.test = function(actual) {
952
+ if (typeof actual !== "string") {
953
+ return false;
954
+ }
955
+ return actual.indexOf(expectation) !== -1;
956
+ };
957
+ m.message = "match(\"" + expectation + "\")";
958
+ break;
959
+ case "regexp":
960
+ m.test = function(actual) {
961
+ if (typeof actual !== "string") {
962
+ return false;
963
+ }
964
+ return expectation.test(actual);
965
+ };
966
+ break;
967
+ case "function":
968
+ m.test = expectation;
969
+ if (message) {
970
+ m.message = message;
971
+ } else {
972
+ m.message = "match(" + sinon.functionName(expectation) + ")";
973
+ }
974
+ break;
975
+ default:
976
+ m.test = function(actual) {
977
+ return sinon.deepEqual(expectation, actual);
978
+ };
979
+ }
980
+ if (!m.message) {
981
+ m.message = "match(" + expectation + ")";
982
+ }
983
+ return m;
984
+ };
985
+
986
+ match.isMatcher = isMatcher;
987
+
988
+ match.any = match(function() {
989
+ return true;
990
+ }, "any");
991
+
992
+ match.defined = match(function(actual) {
993
+ return actual !== null && actual !== undefined;
994
+ }, "defined");
995
+
996
+ match.truthy = match(function(actual) {
997
+ return !!actual;
998
+ }, "truthy");
999
+
1000
+ match.falsy = match(function(actual) {
1001
+ return !actual;
1002
+ }, "falsy");
1003
+
1004
+ match.same = function(expectation) {
1005
+ return match(function(actual) {
1006
+ return expectation === actual;
1007
+ }, "same(" + expectation + ")");
1008
+ };
1009
+
1010
+ match.typeOf = function(type) {
1011
+ assertType(type, "string", "type");
1012
+ return match(function(actual) {
1013
+ return sinon.typeOf(actual) === type;
1014
+ }, "typeOf(\"" + type + "\")");
1015
+ };
1016
+
1017
+ match.instanceOf = function(type) {
1018
+ assertType(type, "function", "type");
1019
+ return match(function(actual) {
1020
+ return actual instanceof type;
1021
+ }, "instanceOf(" + sinon.functionName(type) + ")");
1022
+ };
1023
+
1024
+ function createPropertyMatcher(propertyTest, messagePrefix) {
1025
+ return function(property, value) {
1026
+ assertType(property, "string", "property");
1027
+ var onlyProperty = arguments.length === 1;
1028
+ var message = messagePrefix + "(\"" + property + "\"";
1029
+ if (!onlyProperty) {
1030
+ message += ", " + value;
1031
+ }
1032
+ message += ")";
1033
+ return match(function(actual) {
1034
+ if (actual === undefined || actual === null || !propertyTest(actual, property)) {
1035
+ return false;
1036
+ }
1037
+ return onlyProperty || sinon.deepEqual(value, actual[property]);
1038
+ }, message);
1039
+ };
1040
+ }
1041
+
1042
+ match.has = createPropertyMatcher(function(actual, property) {
1043
+ if (typeof actual === "object") {
1044
+ return property in actual;
1045
+ }
1046
+ return actual[property] !== undefined;
1047
+ }, "has");
1048
+
1049
+ match.hasOwn = createPropertyMatcher(function(actual, property) {
1050
+ return actual.hasOwnProperty(property);
1051
+ }, "hasOwn");
1052
+
1053
+ match.bool = match.typeOf("boolean");
1054
+ match.number = match.typeOf("number");
1055
+ match.string = match.typeOf("string");
1056
+ match.object = match.typeOf("object");
1057
+ match.func = match.typeOf("function");
1058
+ match.array = match.typeOf("array");
1059
+ match.regexp = match.typeOf("regexp");
1060
+ match.date = match.typeOf("date");
1061
+
1062
+ if (commonJSModule) {
1063
+ module.exports = match;
1064
+ } else {
1065
+ sinon.match = match;
1066
+ }
1067
+ }(typeof sinon == "object" && sinon || null));
1068
+
1069
+ /**
1070
+ * @depend ../sinon.js
1071
+ * @depend match.js
1072
+ */
1073
+ /*jslint eqeqeq: false, onevar: false, plusplus: false*/
1074
+ /*global module, require, sinon*/
1075
+ /**
1076
+ * Spy functions
1077
+ *
1078
+ * @author Christian Johansen (christian@cjohansen.no)
1079
+ * @license BSD
1080
+ *
1081
+ * Copyright (c) 2010-2013 Christian Johansen
1082
+ */
1083
+
1084
+ (function(sinon) {
1085
+ var commonJSModule = typeof module == "object" && typeof require == "function";
1086
+ var spyCall;
1087
+ var callId = 0;
1088
+ var push = [].push;
1089
+ var slice = Array.prototype.slice;
1090
+
1091
+ if (!sinon && commonJSModule) {
1092
+ sinon = require("../sinon");
1093
+ }
1094
+
1095
+ if (!sinon) {
1096
+ return;
1097
+ }
1098
+
1099
+ function spy(object, property) {
1100
+ if (!property && typeof object == "function") {
1101
+ return spy.create(object);
1102
+ }
1103
+
1104
+ if (!object && !property) {
1105
+ return spy.create(function() {});
1106
+ }
1107
+
1108
+ var method = object[property];
1109
+ return sinon.wrapMethod(object, property, spy.create(method));
1110
+ }
1111
+
1112
+ sinon.extend(spy, (function() {
1113
+
1114
+ function delegateToCalls(api, method, matchAny, actual, notCalled) {
1115
+ api[method] = function() {
1116
+ if (!this.called) {
1117
+ if (notCalled) {
1118
+ return notCalled.apply(this, arguments);
1119
+ }
1120
+ return false;
1121
+ }
1122
+
1123
+ var currentCall;
1124
+ var matches = 0;
1125
+
1126
+ for (var i = 0, l = this.callCount; i < l; i += 1) {
1127
+ currentCall = this.getCall(i);
1128
+
1129
+ if (currentCall[actual || method].apply(currentCall, arguments)) {
1130
+ matches += 1;
1131
+
1132
+ if (matchAny) {
1133
+ return true;
1134
+ }
1135
+ }
1136
+ }
1137
+
1138
+ return matches === this.callCount;
1139
+ };
1140
+ }
1141
+
1142
+ function matchingFake(fakes, args, strict) {
1143
+ if (!fakes) {
1144
+ return;
1145
+ }
1146
+
1147
+ var alen = args.length;
1148
+
1149
+ for (var i = 0, l = fakes.length; i < l; i++) {
1150
+ if (fakes[i].matches(args, strict)) {
1151
+ return fakes[i];
1152
+ }
1153
+ }
1154
+ }
1155
+
1156
+ function incrementCallCount() {
1157
+ this.called = true;
1158
+ this.callCount += 1;
1159
+ this.notCalled = false;
1160
+ this.calledOnce = this.callCount == 1;
1161
+ this.calledTwice = this.callCount == 2;
1162
+ this.calledThrice = this.callCount == 3;
1163
+ }
1164
+
1165
+ function createCallProperties() {
1166
+ this.firstCall = this.getCall(0);
1167
+ this.secondCall = this.getCall(1);
1168
+ this.thirdCall = this.getCall(2);
1169
+ this.lastCall = this.getCall(this.callCount - 1);
1170
+ }
1171
+
1172
+ var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
1173
+
1174
+ function createProxy(func) {
1175
+ // Retain the function length:
1176
+ var p;
1177
+ if (func.length) {
1178
+ eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) + ") { return p.invoke(func, this, slice.call(arguments)); });");
1179
+ } else {
1180
+ p = function proxy() {
1181
+ return p.invoke(func, this, slice.call(arguments));
1182
+ };
1183
+ }
1184
+ return p;
1185
+ }
1186
+
1187
+ var uuid = 0;
1188
+
1189
+ // Public API
1190
+ var spyApi = {
1191
+ reset: function() {
1192
+ this.called = false;
1193
+ this.notCalled = true;
1194
+ this.calledOnce = false;
1195
+ this.calledTwice = false;
1196
+ this.calledThrice = false;
1197
+ this.callCount = 0;
1198
+ this.firstCall = null;
1199
+ this.secondCall = null;
1200
+ this.thirdCall = null;
1201
+ this.lastCall = null;
1202
+ this.args = [];
1203
+ this.returnValues = [];
1204
+ this.thisValues = [];
1205
+ this.exceptions = [];
1206
+ this.callIds = [];
1207
+ if (this.fakes) {
1208
+ for (var i = 0; i < this.fakes.length; i++) {
1209
+ this.fakes[i].reset();
1210
+ }
1211
+ }
1212
+ },
1213
+
1214
+ create: function create(func) {
1215
+ var name;
1216
+
1217
+ if (typeof func != "function") {
1218
+ func = function() {};
1219
+ } else {
1220
+ name = sinon.functionName(func);
1221
+ }
1222
+
1223
+ var proxy = createProxy(func);
1224
+
1225
+ sinon.extend(proxy, spy);
1226
+ delete proxy.create;
1227
+ sinon.extend(proxy, func);
1228
+
1229
+ proxy.reset();
1230
+ proxy.prototype = func.prototype;
1231
+ proxy.displayName = name || "spy";
1232
+ proxy.toString = sinon.functionToString;
1233
+ proxy._create = sinon.spy.create;
1234
+ proxy.id = "spy#" + uuid++;
1235
+
1236
+ return proxy;
1237
+ },
1238
+
1239
+ invoke: function invoke(func, thisValue, args) {
1240
+ var matching = matchingFake(this.fakes, args);
1241
+ var exception, returnValue;
1242
+
1243
+ incrementCallCount.call(this);
1244
+ push.call(this.thisValues, thisValue);
1245
+ push.call(this.args, args);
1246
+ push.call(this.callIds, callId++);
1247
+
1248
+ try {
1249
+ if (matching) {
1250
+ returnValue = matching.invoke(func, thisValue, args);
1251
+ } else {
1252
+ returnValue = (this.func || func).apply(thisValue, args);
1253
+ }
1254
+ } catch (e) {
1255
+ push.call(this.returnValues, undefined);
1256
+ exception = e;
1257
+ throw e;
1258
+ } finally {
1259
+ push.call(this.exceptions, exception);
1260
+ }
1261
+
1262
+ push.call(this.returnValues, returnValue);
1263
+
1264
+ createCallProperties.call(this);
1265
+
1266
+ return returnValue;
1267
+ },
1268
+
1269
+ getCall: function getCall(i) {
1270
+ if (i < 0 || i >= this.callCount) {
1271
+ return null;
1272
+ }
1273
+
1274
+ return spyCall.create(this, this.thisValues[i], this.args[i], this.returnValues[i], this.exceptions[i], this.callIds[i]);
1275
+ },
1276
+
1277
+ calledBefore: function calledBefore(spyFn) {
1278
+ if (!this.called) {
1279
+ return false;
1280
+ }
1281
+
1282
+ if (!spyFn.called) {
1283
+ return true;
1284
+ }
1285
+
1286
+ return this.callIds[0] < spyFn.callIds[spyFn.callIds.length - 1];
1287
+ },
1288
+
1289
+ calledAfter: function calledAfter(spyFn) {
1290
+ if (!this.called || !spyFn.called) {
1291
+ return false;
1292
+ }
1293
+
1294
+ return this.callIds[this.callCount - 1] > spyFn.callIds[spyFn.callCount - 1];
1295
+ },
1296
+
1297
+ withArgs: function() {
1298
+ var args = slice.call(arguments);
1299
+
1300
+ if (this.fakes) {
1301
+ var match = matchingFake(this.fakes, args, true);
1302
+
1303
+ if (match) {
1304
+ return match;
1305
+ }
1306
+ } else {
1307
+ this.fakes = [];
1308
+ }
1309
+
1310
+ var original = this;
1311
+ var fake = this._create();
1312
+ fake.matchingAguments = args;
1313
+ push.call(this.fakes, fake);
1314
+
1315
+ fake.withArgs = function() {
1316
+ return original.withArgs.apply(original, arguments);
1317
+ };
1318
+
1319
+ for (var i = 0; i < this.args.length; i++) {
1320
+ if (fake.matches(this.args[i])) {
1321
+ incrementCallCount.call(fake);
1322
+ push.call(fake.thisValues, this.thisValues[i]);
1323
+ push.call(fake.args, this.args[i]);
1324
+ push.call(fake.returnValues, this.returnValues[i]);
1325
+ push.call(fake.exceptions, this.exceptions[i]);
1326
+ push.call(fake.callIds, this.callIds[i]);
1327
+ }
1328
+ }
1329
+ createCallProperties.call(fake);
1330
+
1331
+ return fake;
1332
+ },
1333
+
1334
+ matches: function(args, strict) {
1335
+ var margs = this.matchingAguments;
1336
+
1337
+ if (margs.length <= args.length && sinon.deepEqual(margs, args.slice(0, margs.length))) {
1338
+ return !strict || margs.length == args.length;
1339
+ }
1340
+ },
1341
+
1342
+ printf: function(format) {
1343
+ var spy = this;
1344
+ var args = slice.call(arguments, 1);
1345
+ var formatter;
1346
+
1347
+ return (format || "").replace(/%(.)/g, function(match, specifyer) {
1348
+ formatter = spyApi.formatters[specifyer];
1349
+
1350
+ if (typeof formatter == "function") {
1351
+ return formatter.call(null, spy, args);
1352
+ } else if (!isNaN(parseInt(specifyer), 10)) {
1353
+ return sinon.format(args[specifyer - 1]);
1354
+ }
1355
+
1356
+ return "%" + specifyer;
1357
+ });
1358
+ }
1359
+ };
1360
+
1361
+ delegateToCalls(spyApi, "calledOn", true);
1362
+ delegateToCalls(spyApi, "alwaysCalledOn", false, "calledOn");
1363
+ delegateToCalls(spyApi, "calledWith", true);
1364
+ delegateToCalls(spyApi, "calledWithMatch", true);
1365
+ delegateToCalls(spyApi, "alwaysCalledWith", false, "calledWith");
1366
+ delegateToCalls(spyApi, "alwaysCalledWithMatch", false, "calledWithMatch");
1367
+ delegateToCalls(spyApi, "calledWithExactly", true);
1368
+ delegateToCalls(spyApi, "alwaysCalledWithExactly", false, "calledWithExactly");
1369
+ delegateToCalls(spyApi, "neverCalledWith", false, "notCalledWith", function() {
1370
+ return true;
1371
+ });
1372
+ delegateToCalls(spyApi, "neverCalledWithMatch", false, "notCalledWithMatch", function() {
1373
+ return true;
1374
+ });
1375
+ delegateToCalls(spyApi, "threw", true);
1376
+ delegateToCalls(spyApi, "alwaysThrew", false, "threw");
1377
+ delegateToCalls(spyApi, "returned", true);
1378
+ delegateToCalls(spyApi, "alwaysReturned", false, "returned");
1379
+ delegateToCalls(spyApi, "calledWithNew", true);
1380
+ delegateToCalls(spyApi, "alwaysCalledWithNew", false, "calledWithNew");
1381
+ delegateToCalls(spyApi, "callArg", false, "callArgWith", function() {
1382
+ throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
1383
+ });
1384
+ spyApi.callArgWith = spyApi.callArg;
1385
+ delegateToCalls(spyApi, "callArgOn", false, "callArgOnWith", function() {
1386
+ throw new Error(this.toString() + " cannot call arg since it was not yet invoked.");
1387
+ });
1388
+ spyApi.callArgOnWith = spyApi.callArgOn;
1389
+ delegateToCalls(spyApi, "yield", false, "yield", function() {
1390
+ throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
1391
+ });
1392
+ // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode.
1393
+ spyApi.invokeCallback = spyApi.yield;
1394
+ delegateToCalls(spyApi, "yieldOn", false, "yieldOn", function() {
1395
+ throw new Error(this.toString() + " cannot yield since it was not yet invoked.");
1396
+ });
1397
+ delegateToCalls(spyApi, "yieldTo", false, "yieldTo", function(property) {
1398
+ throw new Error(this.toString() + " cannot yield to '" + property + "' since it was not yet invoked.");
1399
+ });
1400
+ delegateToCalls(spyApi, "yieldToOn", false, "yieldToOn", function(property) {
1401
+ throw new Error(this.toString() + " cannot yield to '" + property + "' since it was not yet invoked.");
1402
+ });
1403
+
1404
+ spyApi.formatters = {
1405
+ "c": function(spy) {
1406
+ return sinon.timesInWords(spy.callCount);
1407
+ },
1408
+
1409
+ "n": function(spy) {
1410
+ return spy.toString();
1411
+ },
1412
+
1413
+ "C": function(spy) {
1414
+ var calls = [];
1415
+
1416
+ for (var i = 0, l = spy.callCount; i < l; ++i) {
1417
+ var stringifiedCall = " " + spy.getCall(i).toString();
1418
+ if (/\n/.test(calls[i - 1])) {
1419
+ stringifiedCall = "\n" + stringifiedCall;
1420
+ }
1421
+ push.call(calls, stringifiedCall);
1422
+ }
1423
+
1424
+ return calls.length > 0 ? "\n" + calls.join("\n") : "";
1425
+ },
1426
+
1427
+ "t": function(spy) {
1428
+ var objects = [];
1429
+
1430
+ for (var i = 0, l = spy.callCount; i < l; ++i) {
1431
+ push.call(objects, sinon.format(spy.thisValues[i]));
1432
+ }
1433
+
1434
+ return objects.join(", ");
1435
+ },
1436
+
1437
+ "*": function(spy, args) {
1438
+ var formatted = [];
1439
+
1440
+ for (var i = 0, l = args.length; i < l; ++i) {
1441
+ push.call(formatted, sinon.format(args[i]));
1442
+ }
1443
+
1444
+ return formatted.join(", ");
1445
+ }
1446
+ };
1447
+
1448
+ return spyApi;
1449
+ }()));
1450
+
1451
+ spyCall = (function() {
1452
+
1453
+ function throwYieldError(proxy, text, args) {
1454
+ var msg = sinon.functionName(proxy) + text;
1455
+ if (args.length) {
1456
+ msg += " Received [" + slice.call(args).join(", ") + "]";
1457
+ }
1458
+ throw new Error(msg);
1459
+ }
1460
+
1461
+ var callApi = {
1462
+ create: function create(spy, thisValue, args, returnValue, exception, id) {
1463
+ var proxyCall = sinon.create(spyCall);
1464
+ delete proxyCall.create;
1465
+ proxyCall.proxy = spy;
1466
+ proxyCall.thisValue = thisValue;
1467
+ proxyCall.args = args;
1468
+ proxyCall.returnValue = returnValue;
1469
+ proxyCall.exception = exception;
1470
+ proxyCall.callId = typeof id == "number" && id || callId++;
1471
+
1472
+ return proxyCall;
1473
+ },
1474
+
1475
+ calledOn: function calledOn(thisValue) {
1476
+ if (sinon.match && sinon.match.isMatcher(thisValue)) {
1477
+ return thisValue.test(this.thisValue);
1478
+ }
1479
+ return this.thisValue === thisValue;
1480
+ },
1481
+
1482
+ calledWith: function calledWith() {
1483
+ for (var i = 0, l = arguments.length; i < l; i += 1) {
1484
+ if (!sinon.deepEqual(arguments[i], this.args[i])) {
1485
+ return false;
1486
+ }
1487
+ }
1488
+
1489
+ return true;
1490
+ },
1491
+
1492
+ calledWithMatch: function calledWithMatch() {
1493
+ for (var i = 0, l = arguments.length; i < l; i += 1) {
1494
+ var actual = this.args[i];
1495
+ var expectation = arguments[i];
1496
+ if (!sinon.match || !sinon.match(expectation).test(actual)) {
1497
+ return false;
1498
+ }
1499
+ }
1500
+ return true;
1501
+ },
1502
+
1503
+ calledWithExactly: function calledWithExactly() {
1504
+ return arguments.length == this.args.length && this.calledWith.apply(this, arguments);
1505
+ },
1506
+
1507
+ notCalledWith: function notCalledWith() {
1508
+ return !this.calledWith.apply(this, arguments);
1509
+ },
1510
+
1511
+ notCalledWithMatch: function notCalledWithMatch() {
1512
+ return !this.calledWithMatch.apply(this, arguments);
1513
+ },
1514
+
1515
+ returned: function returned(value) {
1516
+ return sinon.deepEqual(value, this.returnValue);
1517
+ },
1518
+
1519
+ threw: function threw(error) {
1520
+ if (typeof error == "undefined" || !this.exception) {
1521
+ return !!this.exception;
1522
+ }
1523
+
1524
+ if (typeof error == "string") {
1525
+ return this.exception.name == error;
1526
+ }
1527
+
1528
+ return this.exception === error;
1529
+ },
1530
+
1531
+ calledWithNew: function calledWithNew(thisValue) {
1532
+ return this.thisValue instanceof this.proxy;
1533
+ },
1534
+
1535
+ calledBefore: function(other) {
1536
+ return this.callId < other.callId;
1537
+ },
1538
+
1539
+ calledAfter: function(other) {
1540
+ return this.callId > other.callId;
1541
+ },
1542
+
1543
+ callArg: function(pos) {
1544
+ this.args[pos]();
1545
+ },
1546
+
1547
+ callArgOn: function(pos, thisValue) {
1548
+ this.args[pos].apply(thisValue);
1549
+ },
1550
+
1551
+ callArgWith: function(pos) {
1552
+ this.callArgOnWith.apply(this, [pos, null].concat(slice.call(arguments, 1)));
1553
+ },
1554
+
1555
+ callArgOnWith: function(pos, thisValue) {
1556
+ var args = slice.call(arguments, 2);
1557
+ this.args[pos].apply(thisValue, args);
1558
+ },
1559
+
1560
+ "yield": function() {
1561
+ this.yieldOn.apply(this, [null].concat(slice.call(arguments, 0)));
1562
+ },
1563
+
1564
+ yieldOn: function(thisValue) {
1565
+ var args = this.args;
1566
+ for (var i = 0, l = args.length; i < l; ++i) {
1567
+ if (typeof args[i] === "function") {
1568
+ args[i].apply(thisValue, slice.call(arguments, 1));
1569
+ return;
1570
+ }
1571
+ }
1572
+ throwYieldError(this.proxy, " cannot yield since no callback was passed.", args);
1573
+ },
1574
+
1575
+ yieldTo: function(prop) {
1576
+ this.yieldToOn.apply(this, [prop, null].concat(slice.call(arguments, 1)));
1577
+ },
1578
+
1579
+ yieldToOn: function(prop, thisValue) {
1580
+ var args = this.args;
1581
+ for (var i = 0, l = args.length; i < l; ++i) {
1582
+ if (args[i] && typeof args[i][prop] === "function") {
1583
+ args[i][prop].apply(thisValue, slice.call(arguments, 2));
1584
+ return;
1585
+ }
1586
+ }
1587
+ throwYieldError(this.proxy, " cannot yield to '" + prop + "' since no callback was passed.", args);
1588
+ },
1589
+
1590
+ toString: function() {
1591
+ var callStr = this.proxy.toString() + "(";
1592
+ var args = [];
1593
+
1594
+ for (var i = 0, l = this.args.length; i < l; ++i) {
1595
+ push.call(args, sinon.format(this.args[i]));
1596
+ }
1597
+
1598
+ callStr = callStr + args.join(", ") + ")";
1599
+
1600
+ if (typeof this.returnValue != "undefined") {
1601
+ callStr += " => " + sinon.format(this.returnValue);
1602
+ }
1603
+
1604
+ if (this.exception) {
1605
+ callStr += " !" + this.exception.name;
1606
+
1607
+ if (this.exception.message) {
1608
+ callStr += "(" + this.exception.message + ")";
1609
+ }
1610
+ }
1611
+
1612
+ return callStr;
1613
+ }
1614
+ };
1615
+ callApi.invokeCallback = callApi.yield;
1616
+ return callApi;
1617
+ }());
1618
+
1619
+ spy.spyCall = spyCall;
1620
+
1621
+ // This steps outside the module sandbox and will be removed
1622
+ sinon.spyCall = spyCall;
1623
+
1624
+ if (commonJSModule) {
1625
+ module.exports = spy;
1626
+ } else {
1627
+ sinon.spy = spy;
1628
+ }
1629
+ }(typeof sinon == "object" && sinon || null));
1630
+
1631
+ /**
1632
+ * @depend ../sinon.js
1633
+ * @depend spy.js
1634
+ */
1635
+ /*jslint eqeqeq: false, onevar: false*/
1636
+ /*global module, require, sinon*/
1637
+ /**
1638
+ * Stub functions
1639
+ *
1640
+ * @author Christian Johansen (christian@cjohansen.no)
1641
+ * @license BSD
1642
+ *
1643
+ * Copyright (c) 2010-2013 Christian Johansen
1644
+ */
1645
+
1646
+ (function(sinon) {
1647
+ var commonJSModule = typeof module == "object" && typeof require == "function";
1648
+
1649
+ if (!sinon && commonJSModule) {
1650
+ sinon = require("../sinon");
1651
+ }
1652
+
1653
+ if (!sinon) {
1654
+ return;
1655
+ }
1656
+
1657
+ function stub(object, property, func) {
1658
+ if ( !! func && typeof func != "function") {
1659
+ throw new TypeError("Custom stub should be function");
1660
+ }
1661
+
1662
+ var wrapper;
1663
+
1664
+ if (func) {
1665
+ wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func;
1666
+ } else {
1667
+ wrapper = stub.create();
1668
+ }
1669
+
1670
+ if (!object && !property) {
1671
+ return sinon.stub.create();
1672
+ }
1673
+
1674
+ if (!property && !! object && typeof object == "object") {
1675
+ for (var prop in object) {
1676
+ if (typeof object[prop] === "function") {
1677
+ stub(object, prop);
1678
+ }
1679
+ }
1680
+
1681
+ return object;
1682
+ }
1683
+
1684
+ return sinon.wrapMethod(object, property, wrapper);
1685
+ }
1686
+
1687
+ function getChangingValue(stub, property) {
1688
+ var index = stub.callCount - 1;
1689
+ var values = stub[property];
1690
+ var prop = index in values ? values[index] : values[values.length - 1];
1691
+ stub[property + "Last"] = prop;
1692
+
1693
+ return prop;
1694
+ }
1695
+
1696
+ function getCallback(stub, args) {
1697
+ var callArgAt = getChangingValue(stub, "callArgAts");
1698
+
1699
+ if (callArgAt < 0) {
1700
+ var callArgProp = getChangingValue(stub, "callArgProps");
1701
+
1702
+ for (var i = 0, l = args.length; i < l; ++i) {
1703
+ if (!callArgProp && typeof args[i] == "function") {
1704
+ return args[i];
1705
+ }
1706
+
1707
+ if (callArgProp && args[i] && typeof args[i][callArgProp] == "function") {
1708
+ return args[i][callArgProp];
1709
+ }
1710
+ }
1711
+
1712
+ return null;
1713
+ }
1714
+
1715
+ return args[callArgAt];
1716
+ }
1717
+
1718
+ var join = Array.prototype.join;
1719
+
1720
+ function getCallbackError(stub, func, args) {
1721
+ if (stub.callArgAtsLast < 0) {
1722
+ var msg;
1723
+
1724
+ if (stub.callArgPropsLast) {
1725
+ msg = sinon.functionName(stub) + " expected to yield to '" + stub.callArgPropsLast + "', but no object with such a property was passed."
1726
+ } else {
1727
+ msg = sinon.functionName(stub) + " expected to yield, but no callback was passed."
1728
+ }
1729
+
1730
+ if (args.length > 0) {
1731
+ msg += " Received [" + join.call(args, ", ") + "]";
1732
+ }
1733
+
1734
+ return msg;
1735
+ }
1736
+
1737
+ return "argument at index " + stub.callArgAtsLast + " is not a function: " + func;
1738
+ }
1739
+
1740
+ var nextTick = (function() {
1741
+ if (typeof process === "object" && typeof process.nextTick === "function") {
1742
+ return process.nextTick;
1743
+ } else if (typeof setImmediate === "function") {
1744
+ return setImmediate;
1745
+ } else {
1746
+ return function(callback) {
1747
+ setTimeout(callback, 0);
1748
+ };
1749
+ }
1750
+ })();
1751
+
1752
+ function callCallback(stub, args) {
1753
+ if (stub.callArgAts.length > 0) {
1754
+ var func = getCallback(stub, args);
1755
+
1756
+ if (typeof func != "function") {
1757
+ throw new TypeError(getCallbackError(stub, func, args));
1758
+ }
1759
+
1760
+ var callbackArguments = getChangingValue(stub, "callbackArguments");
1761
+ var callbackContext = getChangingValue(stub, "callbackContexts");
1762
+
1763
+ if (stub.callbackAsync) {
1764
+ nextTick(function() {
1765
+ func.apply(callbackContext, callbackArguments);
1766
+ });
1767
+ } else {
1768
+ func.apply(callbackContext, callbackArguments);
1769
+ }
1770
+ }
1771
+ }
1772
+
1773
+ var uuid = 0;
1774
+
1775
+ sinon.extend(stub, (function() {
1776
+ var slice = Array.prototype.slice,
1777
+ proto;
1778
+
1779
+ function throwsException(error, message) {
1780
+ if (typeof error == "string") {
1781
+ this.exception = new Error(message || "");
1782
+ this.exception.name = error;
1783
+ } else if (!error) {
1784
+ this.exception = new Error("Error");
1785
+ } else {
1786
+ this.exception = error;
1787
+ }
1788
+
1789
+ return this;
1790
+ }
1791
+
1792
+ proto = {
1793
+ create: function create() {
1794
+ var functionStub = function() {
1795
+
1796
+ callCallback(functionStub, arguments);
1797
+
1798
+ if (functionStub.exception) {
1799
+ throw functionStub.exception;
1800
+ } else if (typeof functionStub.returnArgAt == 'number') {
1801
+ return arguments[functionStub.returnArgAt];
1802
+ } else if (functionStub.returnThis) {
1803
+ return this;
1804
+ }
1805
+ return functionStub.returnValue;
1806
+ };
1807
+
1808
+ functionStub.id = "stub#" + uuid++;
1809
+ var orig = functionStub;
1810
+ functionStub = sinon.spy.create(functionStub);
1811
+ functionStub.func = orig;
1812
+
1813
+ functionStub.callArgAts = [];
1814
+ functionStub.callbackArguments = [];
1815
+ functionStub.callbackContexts = [];
1816
+ functionStub.callArgProps = [];
1817
+
1818
+ sinon.extend(functionStub, stub);
1819
+ functionStub._create = sinon.stub.create;
1820
+ functionStub.displayName = "stub";
1821
+ functionStub.toString = sinon.functionToString;
1822
+
1823
+ return functionStub;
1824
+ },
1825
+
1826
+ resetBehavior: function() {
1827
+ var i;
1828
+
1829
+ this.callArgAts = [];
1830
+ this.callbackArguments = [];
1831
+ this.callbackContexts = [];
1832
+ this.callArgProps = [];
1833
+
1834
+ delete this.returnValue;
1835
+ delete this.returnArgAt;
1836
+ this.returnThis = false;
1837
+
1838
+ if (this.fakes) {
1839
+ for (i = 0; i < this.fakes.length; i++) {
1840
+ this.fakes[i].resetBehavior();
1841
+ }
1842
+ }
1843
+ },
1844
+
1845
+ returns: function returns(value) {
1846
+ this.returnValue = value;
1847
+
1848
+ return this;
1849
+ },
1850
+
1851
+ returnsArg: function returnsArg(pos) {
1852
+ if (typeof pos != "number") {
1853
+ throw new TypeError("argument index is not number");
1854
+ }
1855
+
1856
+ this.returnArgAt = pos;
1857
+
1858
+ return this;
1859
+ },
1860
+
1861
+ returnsThis: function returnsThis() {
1862
+ this.returnThis = true;
1863
+
1864
+ return this;
1865
+ },
1866
+
1867
+ "throws": throwsException,
1868
+ throwsException: throwsException,
1869
+
1870
+ callsArg: function callsArg(pos) {
1871
+ if (typeof pos != "number") {
1872
+ throw new TypeError("argument index is not number");
1873
+ }
1874
+
1875
+ this.callArgAts.push(pos);
1876
+ this.callbackArguments.push([]);
1877
+ this.callbackContexts.push(undefined);
1878
+ this.callArgProps.push(undefined);
1879
+
1880
+ return this;
1881
+ },
1882
+
1883
+ callsArgOn: function callsArgOn(pos, context) {
1884
+ if (typeof pos != "number") {
1885
+ throw new TypeError("argument index is not number");
1886
+ }
1887
+ if (typeof context != "object") {
1888
+ throw new TypeError("argument context is not an object");
1889
+ }
1890
+
1891
+ this.callArgAts.push(pos);
1892
+ this.callbackArguments.push([]);
1893
+ this.callbackContexts.push(context);
1894
+ this.callArgProps.push(undefined);
1895
+
1896
+ return this;
1897
+ },
1898
+
1899
+ callsArgWith: function callsArgWith(pos) {
1900
+ if (typeof pos != "number") {
1901
+ throw new TypeError("argument index is not number");
1902
+ }
1903
+
1904
+ this.callArgAts.push(pos);
1905
+ this.callbackArguments.push(slice.call(arguments, 1));
1906
+ this.callbackContexts.push(undefined);
1907
+ this.callArgProps.push(undefined);
1908
+
1909
+ return this;
1910
+ },
1911
+
1912
+ callsArgOnWith: function callsArgWith(pos, context) {
1913
+ if (typeof pos != "number") {
1914
+ throw new TypeError("argument index is not number");
1915
+ }
1916
+ if (typeof context != "object") {
1917
+ throw new TypeError("argument context is not an object");
1918
+ }
1919
+
1920
+ this.callArgAts.push(pos);
1921
+ this.callbackArguments.push(slice.call(arguments, 2));
1922
+ this.callbackContexts.push(context);
1923
+ this.callArgProps.push(undefined);
1924
+
1925
+ return this;
1926
+ },
1927
+
1928
+ yields: function() {
1929
+ this.callArgAts.push(-1);
1930
+ this.callbackArguments.push(slice.call(arguments, 0));
1931
+ this.callbackContexts.push(undefined);
1932
+ this.callArgProps.push(undefined);
1933
+
1934
+ return this;
1935
+ },
1936
+
1937
+ yieldsOn: function(context) {
1938
+ if (typeof context != "object") {
1939
+ throw new TypeError("argument context is not an object");
1940
+ }
1941
+
1942
+ this.callArgAts.push(-1);
1943
+ this.callbackArguments.push(slice.call(arguments, 1));
1944
+ this.callbackContexts.push(context);
1945
+ this.callArgProps.push(undefined);
1946
+
1947
+ return this;
1948
+ },
1949
+
1950
+ yieldsTo: function(prop) {
1951
+ this.callArgAts.push(-1);
1952
+ this.callbackArguments.push(slice.call(arguments, 1));
1953
+ this.callbackContexts.push(undefined);
1954
+ this.callArgProps.push(prop);
1955
+
1956
+ return this;
1957
+ },
1958
+
1959
+ yieldsToOn: function(prop, context) {
1960
+ if (typeof context != "object") {
1961
+ throw new TypeError("argument context is not an object");
1962
+ }
1963
+
1964
+ this.callArgAts.push(-1);
1965
+ this.callbackArguments.push(slice.call(arguments, 2));
1966
+ this.callbackContexts.push(context);
1967
+ this.callArgProps.push(prop);
1968
+
1969
+ return this;
1970
+ }
1971
+ };
1972
+
1973
+ // create asynchronous versions of callsArg* and yields* methods
1974
+ for (var method in proto) {
1975
+ // need to avoid creating anotherasync versions of the newly added async methods
1976
+ if (proto.hasOwnProperty(method) && method.match(/^(callsArg|yields|thenYields$)/) && !method.match(/Async/)) {
1977
+ proto[method + 'Async'] = (function(syncFnName) {
1978
+ return function() {
1979
+ this.callbackAsync = true;
1980
+ return this[syncFnName].apply(this, arguments);
1981
+ };
1982
+ })(method);
1983
+ }
1984
+ }
1985
+
1986
+ return proto;
1987
+
1988
+ }()));
1989
+
1990
+ if (commonJSModule) {
1991
+ module.exports = stub;
1992
+ } else {
1993
+ sinon.stub = stub;
1994
+ }
1995
+ }(typeof sinon == "object" && sinon || null));
1996
+
1997
+ /**
1998
+ * @depend ../sinon.js
1999
+ * @depend stub.js
2000
+ */
2001
+ /*jslint eqeqeq: false, onevar: false, nomen: false*/
2002
+ /*global module, require, sinon*/
2003
+ /**
2004
+ * Mock functions.
2005
+ *
2006
+ * @author Christian Johansen (christian@cjohansen.no)
2007
+ * @license BSD
2008
+ *
2009
+ * Copyright (c) 2010-2013 Christian Johansen
2010
+ */
2011
+
2012
+ (function(sinon) {
2013
+ var commonJSModule = typeof module == "object" && typeof require == "function";
2014
+ var push = [].push;
2015
+
2016
+ if (!sinon && commonJSModule) {
2017
+ sinon = require("../sinon");
2018
+ }
2019
+
2020
+ if (!sinon) {
2021
+ return;
2022
+ }
2023
+
2024
+ function mock(object) {
2025
+ if (!object) {
2026
+ return sinon.expectation.create("Anonymous mock");
2027
+ }
2028
+
2029
+ return mock.create(object);
2030
+ }
2031
+
2032
+ sinon.mock = mock;
2033
+
2034
+ sinon.extend(mock, (function() {
2035
+ function each(collection, callback) {
2036
+ if (!collection) {
2037
+ return;
2038
+ }
2039
+
2040
+ for (var i = 0, l = collection.length; i < l; i += 1) {
2041
+ callback(collection[i]);
2042
+ }
2043
+ }
2044
+
2045
+ return {
2046
+ create: function create(object) {
2047
+ if (!object) {
2048
+ throw new TypeError("object is null");
2049
+ }
2050
+
2051
+ var mockObject = sinon.extend({}, mock);
2052
+ mockObject.object = object;
2053
+ delete mockObject.create;
2054
+
2055
+ return mockObject;
2056
+ },
2057
+
2058
+ expects: function expects(method) {
2059
+ if (!method) {
2060
+ throw new TypeError("method is falsy");
2061
+ }
2062
+
2063
+ if (!this.expectations) {
2064
+ this.expectations = {};
2065
+ this.proxies = [];
2066
+ }
2067
+
2068
+ if (!this.expectations[method]) {
2069
+ this.expectations[method] = [];
2070
+ var mockObject = this;
2071
+
2072
+ sinon.wrapMethod(this.object, method, function() {
2073
+ return mockObject.invokeMethod(method, this, arguments);
2074
+ });
2075
+
2076
+ push.call(this.proxies, method);
2077
+ }
2078
+
2079
+ var expectation = sinon.expectation.create(method);
2080
+ push.call(this.expectations[method], expectation);
2081
+
2082
+ return expectation;
2083
+ },
2084
+
2085
+ restore: function restore() {
2086
+ var object = this.object;
2087
+
2088
+ each(this.proxies, function(proxy) {
2089
+ if (typeof object[proxy].restore == "function") {
2090
+ object[proxy].restore();
2091
+ }
2092
+ });
2093
+ },
2094
+
2095
+ verify: function verify() {
2096
+ var expectations = this.expectations || {};
2097
+ var messages = [],
2098
+ met = [];
2099
+
2100
+ each(this.proxies, function(proxy) {
2101
+ each(expectations[proxy], function(expectation) {
2102
+ if (!expectation.met()) {
2103
+ push.call(messages, expectation.toString());
2104
+ } else {
2105
+ push.call(met, expectation.toString());
2106
+ }
2107
+ });
2108
+ });
2109
+
2110
+ this.restore();
2111
+
2112
+ if (messages.length > 0) {
2113
+ sinon.expectation.fail(messages.concat(met).join("\n"));
2114
+ } else {
2115
+ sinon.expectation.pass(messages.concat(met).join("\n"));
2116
+ }
2117
+
2118
+ return true;
2119
+ },
2120
+
2121
+ invokeMethod: function invokeMethod(method, thisValue, args) {
2122
+ var expectations = this.expectations && this.expectations[method];
2123
+ var length = expectations && expectations.length || 0,
2124
+ i;
2125
+
2126
+ for (i = 0; i < length; i += 1) {
2127
+ if (!expectations[i].met() && expectations[i].allowsCall(thisValue, args)) {
2128
+ return expectations[i].apply(thisValue, args);
2129
+ }
2130
+ }
2131
+
2132
+ var messages = [],
2133
+ available, exhausted = 0;
2134
+
2135
+ for (i = 0; i < length; i += 1) {
2136
+ if (expectations[i].allowsCall(thisValue, args)) {
2137
+ available = available || expectations[i];
2138
+ } else {
2139
+ exhausted += 1;
2140
+ }
2141
+ push.call(messages, " " + expectations[i].toString());
2142
+ }
2143
+
2144
+ if (exhausted === 0) {
2145
+ return available.apply(thisValue, args);
2146
+ }
2147
+
2148
+ messages.unshift("Unexpected call: " + sinon.spyCall.toString.call({
2149
+ proxy: method,
2150
+ args: args
2151
+ }));
2152
+
2153
+ sinon.expectation.fail(messages.join("\n"));
2154
+ }
2155
+ };
2156
+ }()));
2157
+
2158
+ var times = sinon.timesInWords;
2159
+
2160
+ sinon.expectation = (function() {
2161
+ var slice = Array.prototype.slice;
2162
+ var _invoke = sinon.spy.invoke;
2163
+
2164
+ function callCountInWords(callCount) {
2165
+ if (callCount == 0) {
2166
+ return "never called";
2167
+ } else {
2168
+ return "called " + times(callCount);
2169
+ }
2170
+ }
2171
+
2172
+ function expectedCallCountInWords(expectation) {
2173
+ var min = expectation.minCalls;
2174
+ var max = expectation.maxCalls;
2175
+
2176
+ if (typeof min == "number" && typeof max == "number") {
2177
+ var str = times(min);
2178
+
2179
+ if (min != max) {
2180
+ str = "at least " + str + " and at most " + times(max);
2181
+ }
2182
+
2183
+ return str;
2184
+ }
2185
+
2186
+ if (typeof min == "number") {
2187
+ return "at least " + times(min);
2188
+ }
2189
+
2190
+ return "at most " + times(max);
2191
+ }
2192
+
2193
+ function receivedMinCalls(expectation) {
2194
+ var hasMinLimit = typeof expectation.minCalls == "number";
2195
+ return !hasMinLimit || expectation.callCount >= expectation.minCalls;
2196
+ }
2197
+
2198
+ function receivedMaxCalls(expectation) {
2199
+ if (typeof expectation.maxCalls != "number") {
2200
+ return false;
2201
+ }
2202
+
2203
+ return expectation.callCount == expectation.maxCalls;
2204
+ }
2205
+
2206
+ return {
2207
+ minCalls: 1,
2208
+ maxCalls: 1,
2209
+
2210
+ create: function create(methodName) {
2211
+ var expectation = sinon.extend(sinon.stub.create(), sinon.expectation);
2212
+ delete expectation.create;
2213
+ expectation.method = methodName;
2214
+
2215
+ return expectation;
2216
+ },
2217
+
2218
+ invoke: function invoke(func, thisValue, args) {
2219
+ this.verifyCallAllowed(thisValue, args);
2220
+
2221
+ return _invoke.apply(this, arguments);
2222
+ },
2223
+
2224
+ atLeast: function atLeast(num) {
2225
+ if (typeof num != "number") {
2226
+ throw new TypeError("'" + num + "' is not number");
2227
+ }
2228
+
2229
+ if (!this.limitsSet) {
2230
+ this.maxCalls = null;
2231
+ this.limitsSet = true;
2232
+ }
2233
+
2234
+ this.minCalls = num;
2235
+
2236
+ return this;
2237
+ },
2238
+
2239
+ atMost: function atMost(num) {
2240
+ if (typeof num != "number") {
2241
+ throw new TypeError("'" + num + "' is not number");
2242
+ }
2243
+
2244
+ if (!this.limitsSet) {
2245
+ this.minCalls = null;
2246
+ this.limitsSet = true;
2247
+ }
2248
+
2249
+ this.maxCalls = num;
2250
+
2251
+ return this;
2252
+ },
2253
+
2254
+ never: function never() {
2255
+ return this.exactly(0);
2256
+ },
2257
+
2258
+ once: function once() {
2259
+ return this.exactly(1);
2260
+ },
2261
+
2262
+ twice: function twice() {
2263
+ return this.exactly(2);
2264
+ },
2265
+
2266
+ thrice: function thrice() {
2267
+ return this.exactly(3);
2268
+ },
2269
+
2270
+ exactly: function exactly(num) {
2271
+ if (typeof num != "number") {
2272
+ throw new TypeError("'" + num + "' is not a number");
2273
+ }
2274
+
2275
+ this.atLeast(num);
2276
+ return this.atMost(num);
2277
+ },
2278
+
2279
+ met: function met() {
2280
+ return !this.failed && receivedMinCalls(this);
2281
+ },
2282
+
2283
+ verifyCallAllowed: function verifyCallAllowed(thisValue, args) {
2284
+ if (receivedMaxCalls(this)) {
2285
+ this.failed = true;
2286
+ sinon.expectation.fail(this.method + " already called " + times(this.maxCalls));
2287
+ }
2288
+
2289
+ if ("expectedThis" in this && this.expectedThis !== thisValue) {
2290
+ sinon.expectation.fail(this.method + " called with " + thisValue + " as thisValue, expected " + this.expectedThis);
2291
+ }
2292
+
2293
+ if (!("expectedArguments" in this)) {
2294
+ return;
2295
+ }
2296
+
2297
+ if (!args) {
2298
+ sinon.expectation.fail(this.method + " received no arguments, expected " + sinon.format(this.expectedArguments));
2299
+ }
2300
+
2301
+ if (args.length < this.expectedArguments.length) {
2302
+ sinon.expectation.fail(this.method + " received too few arguments (" + sinon.format(args) + "), expected " + sinon.format(this.expectedArguments));
2303
+ }
2304
+
2305
+ if (this.expectsExactArgCount && args.length != this.expectedArguments.length) {
2306
+ sinon.expectation.fail(this.method + " received too many arguments (" + sinon.format(args) + "), expected " + sinon.format(this.expectedArguments));
2307
+ }
2308
+
2309
+ for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
2310
+ if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
2311
+ sinon.expectation.fail(this.method + " received wrong arguments " + sinon.format(args) + ", expected " + sinon.format(this.expectedArguments));
2312
+ }
2313
+ }
2314
+ },
2315
+
2316
+ allowsCall: function allowsCall(thisValue, args) {
2317
+ if (this.met() && receivedMaxCalls(this)) {
2318
+ return false;
2319
+ }
2320
+
2321
+ if ("expectedThis" in this && this.expectedThis !== thisValue) {
2322
+ return false;
2323
+ }
2324
+
2325
+ if (!("expectedArguments" in this)) {
2326
+ return true;
2327
+ }
2328
+
2329
+ args = args || [];
2330
+
2331
+ if (args.length < this.expectedArguments.length) {
2332
+ return false;
2333
+ }
2334
+
2335
+ if (this.expectsExactArgCount && args.length != this.expectedArguments.length) {
2336
+ return false;
2337
+ }
2338
+
2339
+ for (var i = 0, l = this.expectedArguments.length; i < l; i += 1) {
2340
+ if (!sinon.deepEqual(this.expectedArguments[i], args[i])) {
2341
+ return false;
2342
+ }
2343
+ }
2344
+
2345
+ return true;
2346
+ },
2347
+
2348
+ withArgs: function withArgs() {
2349
+ this.expectedArguments = slice.call(arguments);
2350
+ return this;
2351
+ },
2352
+
2353
+ withExactArgs: function withExactArgs() {
2354
+ this.withArgs.apply(this, arguments);
2355
+ this.expectsExactArgCount = true;
2356
+ return this;
2357
+ },
2358
+
2359
+ on: function on(thisValue) {
2360
+ this.expectedThis = thisValue;
2361
+ return this;
2362
+ },
2363
+
2364
+ toString: function() {
2365
+ var args = (this.expectedArguments || []).slice();
2366
+
2367
+ if (!this.expectsExactArgCount) {
2368
+ push.call(args, "[...]");
2369
+ }
2370
+
2371
+ var callStr = sinon.spyCall.toString.call({
2372
+ proxy: this.method || "anonymous mock expectation",
2373
+ args: args
2374
+ });
2375
+
2376
+ var message = callStr.replace(", [...", "[, ...") + " " + expectedCallCountInWords(this);
2377
+
2378
+ if (this.met()) {
2379
+ return "Expectation met: " + message;
2380
+ }
2381
+
2382
+ return "Expected " + message + " (" + callCountInWords(this.callCount) + ")";
2383
+ },
2384
+
2385
+ verify: function verify() {
2386
+ if (!this.met()) {
2387
+ sinon.expectation.fail(this.toString());
2388
+ } else {
2389
+ sinon.expectation.pass(this.toString());
2390
+ }
2391
+
2392
+ return true;
2393
+ },
2394
+
2395
+ pass: function(message) {
2396
+ sinon.assert.pass(message);
2397
+ },
2398
+ fail: function(message) {
2399
+ var exception = new Error(message);
2400
+ exception.name = "ExpectationError";
2401
+
2402
+ throw exception;
2403
+ }
2404
+ };
2405
+ }());
2406
+
2407
+ if (commonJSModule) {
2408
+ module.exports = mock;
2409
+ } else {
2410
+ sinon.mock = mock;
2411
+ }
2412
+ }(typeof sinon == "object" && sinon || null));
2413
+
2414
+ /**
2415
+ * @depend ../sinon.js
2416
+ * @depend stub.js
2417
+ * @depend mock.js
2418
+ */
2419
+ /*jslint eqeqeq: false, onevar: false, forin: true*/
2420
+ /*global module, require, sinon*/
2421
+ /**
2422
+ * Collections of stubs, spies and mocks.
2423
+ *
2424
+ * @author Christian Johansen (christian@cjohansen.no)
2425
+ * @license BSD
2426
+ *
2427
+ * Copyright (c) 2010-2013 Christian Johansen
2428
+ */
2429
+
2430
+ (function(sinon) {
2431
+ var commonJSModule = typeof module == "object" && typeof require == "function";
2432
+ var push = [].push;
2433
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
2434
+
2435
+ if (!sinon && commonJSModule) {
2436
+ sinon = require("../sinon");
2437
+ }
2438
+
2439
+ if (!sinon) {
2440
+ return;
2441
+ }
2442
+
2443
+ function getFakes(fakeCollection) {
2444
+ if (!fakeCollection.fakes) {
2445
+ fakeCollection.fakes = [];
2446
+ }
2447
+
2448
+ return fakeCollection.fakes;
2449
+ }
2450
+
2451
+ function each(fakeCollection, method) {
2452
+ var fakes = getFakes(fakeCollection);
2453
+
2454
+ for (var i = 0, l = fakes.length; i < l; i += 1) {
2455
+ if (typeof fakes[i][method] == "function") {
2456
+ fakes[i][method]();
2457
+ }
2458
+ }
2459
+ }
2460
+
2461
+ function compact(fakeCollection) {
2462
+ var fakes = getFakes(fakeCollection);
2463
+ var i = 0;
2464
+ while (i < fakes.length) {
2465
+ fakes.splice(i, 1);
2466
+ }
2467
+ }
2468
+
2469
+ var collection = {
2470
+ verify: function resolve() {
2471
+ each(this, "verify");
2472
+ },
2473
+
2474
+ restore: function restore() {
2475
+ each(this, "restore");
2476
+ compact(this);
2477
+ },
2478
+
2479
+ verifyAndRestore: function verifyAndRestore() {
2480
+ var exception;
2481
+
2482
+ try {
2483
+ this.verify();
2484
+ } catch (e) {
2485
+ exception = e;
2486
+ }
2487
+
2488
+ this.restore();
2489
+
2490
+ if (exception) {
2491
+ throw exception;
2492
+ }
2493
+ },
2494
+
2495
+ add: function add(fake) {
2496
+ push.call(getFakes(this), fake);
2497
+ return fake;
2498
+ },
2499
+
2500
+ spy: function spy() {
2501
+ return this.add(sinon.spy.apply(sinon, arguments));
2502
+ },
2503
+
2504
+ stub: function stub(object, property, value) {
2505
+ if (property) {
2506
+ var original = object[property];
2507
+
2508
+ if (typeof original != "function") {
2509
+ if (!hasOwnProperty.call(object, property)) {
2510
+ throw new TypeError("Cannot stub non-existent own property " + property);
2511
+ }
2512
+
2513
+ object[property] = value;
2514
+
2515
+ return this.add({
2516
+ restore: function() {
2517
+ object[property] = original;
2518
+ }
2519
+ });
2520
+ }
2521
+ }
2522
+ if (!property && !! object && typeof object == "object") {
2523
+ var stubbedObj = sinon.stub.apply(sinon, arguments);
2524
+
2525
+ for (var prop in stubbedObj) {
2526
+ if (typeof stubbedObj[prop] === "function") {
2527
+ this.add(stubbedObj[prop]);
2528
+ }
2529
+ }
2530
+
2531
+ return stubbedObj;
2532
+ }
2533
+
2534
+ return this.add(sinon.stub.apply(sinon, arguments));
2535
+ },
2536
+
2537
+ mock: function mock() {
2538
+ return this.add(sinon.mock.apply(sinon, arguments));
2539
+ },
2540
+
2541
+ inject: function inject(obj) {
2542
+ var col = this;
2543
+
2544
+ obj.spy = function() {
2545
+ return col.spy.apply(col, arguments);
2546
+ };
2547
+
2548
+ obj.stub = function() {
2549
+ return col.stub.apply(col, arguments);
2550
+ };
2551
+
2552
+ obj.mock = function() {
2553
+ return col.mock.apply(col, arguments);
2554
+ };
2555
+
2556
+ return obj;
2557
+ }
2558
+ };
2559
+
2560
+ if (commonJSModule) {
2561
+ module.exports = collection;
2562
+ } else {
2563
+ sinon.collection = collection;
2564
+ }
2565
+ }(typeof sinon == "object" && sinon || null));
2566
+
2567
+ /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/
2568
+ /*global module, require, window*/
2569
+ /**
2570
+ * Fake timer API
2571
+ * setTimeout
2572
+ * setInterval
2573
+ * clearTimeout
2574
+ * clearInterval
2575
+ * tick
2576
+ * reset
2577
+ * Date
2578
+ *
2579
+ * Inspired by jsUnitMockTimeOut from JsUnit
2580
+ *
2581
+ * @author Christian Johansen (christian@cjohansen.no)
2582
+ * @license BSD
2583
+ *
2584
+ * Copyright (c) 2010-2013 Christian Johansen
2585
+ */
2586
+
2587
+ if (typeof sinon == "undefined") {
2588
+ var sinon = {};
2589
+ }
2590
+
2591
+ (function(global) {
2592
+ var id = 1;
2593
+
2594
+ function addTimer(args, recurring) {
2595
+ if (args.length === 0) {
2596
+ throw new Error("Function requires at least 1 parameter");
2597
+ }
2598
+
2599
+ var toId = id++;
2600
+ var delay = args[1] || 0;
2601
+
2602
+ if (!this.timeouts) {
2603
+ this.timeouts = {};
2604
+ }
2605
+
2606
+ this.timeouts[toId] = {
2607
+ id: toId,
2608
+ func: args[0],
2609
+ callAt: this.now + delay,
2610
+ invokeArgs: Array.prototype.slice.call(args, 2)
2611
+ };
2612
+
2613
+ if (recurring === true) {
2614
+ this.timeouts[toId].interval = delay;
2615
+ }
2616
+
2617
+ return toId;
2618
+ }
2619
+
2620
+ function parseTime(str) {
2621
+ if (!str) {
2622
+ return 0;
2623
+ }
2624
+
2625
+ var strings = str.split(":");
2626
+ var l = strings.length,
2627
+ i = l;
2628
+ var ms = 0,
2629
+ parsed;
2630
+
2631
+ if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
2632
+ throw new Error("tick only understands numbers and 'h:m:s'");
2633
+ }
2634
+
2635
+ while (i--) {
2636
+ parsed = parseInt(strings[i], 10);
2637
+
2638
+ if (parsed >= 60) {
2639
+ throw new Error("Invalid time " + str);
2640
+ }
2641
+
2642
+ ms += parsed * Math.pow(60, (l - i - 1));
2643
+ }
2644
+
2645
+ return ms * 1000;
2646
+ }
2647
+
2648
+ function createObject(object) {
2649
+ var newObject;
2650
+
2651
+ if (Object.create) {
2652
+ newObject = Object.create(object);
2653
+ } else {
2654
+ var F = function() {};
2655
+ F.prototype = object;
2656
+ newObject = new F();
2657
+ }
2658
+
2659
+ newObject.Date.clock = newObject;
2660
+ return newObject;
2661
+ }
2662
+
2663
+ sinon.clock = {
2664
+ now: 0,
2665
+
2666
+ create: function create(now) {
2667
+ var clock = createObject(this);
2668
+
2669
+ if (typeof now == "number") {
2670
+ clock.now = now;
2671
+ }
2672
+
2673
+ if ( !! now && typeof now == "object") {
2674
+ throw new TypeError("now should be milliseconds since UNIX epoch");
2675
+ }
2676
+
2677
+ return clock;
2678
+ },
2679
+
2680
+ setTimeout: function setTimeout(callback, timeout) {
2681
+ return addTimer.call(this, arguments, false);
2682
+ },
2683
+
2684
+ clearTimeout: function clearTimeout(timerId) {
2685
+ if (!this.timeouts) {
2686
+ this.timeouts = [];
2687
+ }
2688
+
2689
+ if (timerId in this.timeouts) {
2690
+ delete this.timeouts[timerId];
2691
+ }
2692
+ },
2693
+
2694
+ setInterval: function setInterval(callback, timeout) {
2695
+ return addTimer.call(this, arguments, true);
2696
+ },
2697
+
2698
+ clearInterval: function clearInterval(timerId) {
2699
+ this.clearTimeout(timerId);
2700
+ },
2701
+
2702
+ tick: function tick(ms) {
2703
+ ms = typeof ms == "number" ? ms : parseTime(ms);
2704
+ var tickFrom = this.now,
2705
+ tickTo = this.now + ms,
2706
+ previous = this.now;
2707
+ var timer = this.firstTimerInRange(tickFrom, tickTo);
2708
+
2709
+ var firstException;
2710
+ while (timer && tickFrom <= tickTo) {
2711
+ if (this.timeouts[timer.id]) {
2712
+ tickFrom = this.now = timer.callAt;
2713
+ try {
2714
+ this.callTimer(timer);
2715
+ } catch (e) {
2716
+ firstException = firstException || e;
2717
+ }
2718
+ }
2719
+
2720
+ timer = this.firstTimerInRange(previous, tickTo);
2721
+ previous = tickFrom;
2722
+ }
2723
+
2724
+ this.now = tickTo;
2725
+
2726
+ if (firstException) {
2727
+ throw firstException;
2728
+ }
2729
+
2730
+ return this.now;
2731
+ },
2732
+
2733
+ firstTimerInRange: function(from, to) {
2734
+ var timer, smallest, originalTimer;
2735
+
2736
+ for (var id in this.timeouts) {
2737
+ if (this.timeouts.hasOwnProperty(id)) {
2738
+ if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) {
2739
+ continue;
2740
+ }
2741
+
2742
+ if (!smallest || this.timeouts[id].callAt < smallest) {
2743
+ originalTimer = this.timeouts[id];
2744
+ smallest = this.timeouts[id].callAt;
2745
+
2746
+ timer = {
2747
+ func: this.timeouts[id].func,
2748
+ callAt: this.timeouts[id].callAt,
2749
+ interval: this.timeouts[id].interval,
2750
+ id: this.timeouts[id].id,
2751
+ invokeArgs: this.timeouts[id].invokeArgs
2752
+ };
2753
+ }
2754
+ }
2755
+ }
2756
+
2757
+ return timer || null;
2758
+ },
2759
+
2760
+ callTimer: function(timer) {
2761
+ if (typeof timer.interval == "number") {
2762
+ this.timeouts[timer.id].callAt += timer.interval;
2763
+ } else {
2764
+ delete this.timeouts[timer.id];
2765
+ }
2766
+
2767
+ try {
2768
+ if (typeof timer.func == "function") {
2769
+ timer.func.apply(null, timer.invokeArgs);
2770
+ } else {
2771
+ eval(timer.func);
2772
+ }
2773
+ } catch (e) {
2774
+ var exception = e;
2775
+ }
2776
+
2777
+ if (!this.timeouts[timer.id]) {
2778
+ if (exception) {
2779
+ throw exception;
2780
+ }
2781
+ return;
2782
+ }
2783
+
2784
+ if (exception) {
2785
+ throw exception;
2786
+ }
2787
+ },
2788
+
2789
+ reset: function reset() {
2790
+ this.timeouts = {};
2791
+ },
2792
+
2793
+ Date: (function() {
2794
+ var NativeDate = Date;
2795
+
2796
+ function ClockDate(year, month, date, hour, minute, second, ms) {
2797
+ // Defensive and verbose to avoid potential harm in passing
2798
+ // explicit undefined when user does not pass argument
2799
+ switch (arguments.length) {
2800
+ case 0:
2801
+ return new NativeDate(ClockDate.clock.now);
2802
+ case 1:
2803
+ return new NativeDate(year);
2804
+ case 2:
2805
+ return new NativeDate(year, month);
2806
+ case 3:
2807
+ return new NativeDate(year, month, date);
2808
+ case 4:
2809
+ return new NativeDate(year, month, date, hour);
2810
+ case 5:
2811
+ return new NativeDate(year, month, date, hour, minute);
2812
+ case 6:
2813
+ return new NativeDate(year, month, date, hour, minute, second);
2814
+ default:
2815
+ return new NativeDate(year, month, date, hour, minute, second, ms);
2816
+ }
2817
+ }
2818
+
2819
+ return mirrorDateProperties(ClockDate, NativeDate);
2820
+ }())
2821
+ };
2822
+
2823
+ function mirrorDateProperties(target, source) {
2824
+ if (source.now) {
2825
+ target.now = function now() {
2826
+ return target.clock.now;
2827
+ };
2828
+ } else {
2829
+ delete target.now;
2830
+ }
2831
+
2832
+ if (source.toSource) {
2833
+ target.toSource = function toSource() {
2834
+ return source.toSource();
2835
+ };
2836
+ } else {
2837
+ delete target.toSource;
2838
+ }
2839
+
2840
+ target.toString = function toString() {
2841
+ return source.toString();
2842
+ };
2843
+
2844
+ target.prototype = source.prototype;
2845
+ target.parse = source.parse;
2846
+ target.UTC = source.UTC;
2847
+ target.prototype.toUTCString = source.prototype.toUTCString;
2848
+ return target;
2849
+ }
2850
+
2851
+ var methods = ["Date", "setTimeout", "setInterval", "clearTimeout", "clearInterval"];
2852
+
2853
+ function restore() {
2854
+ var method;
2855
+
2856
+ for (var i = 0, l = this.methods.length; i < l; i++) {
2857
+ method = this.methods[i];
2858
+ if (global[method].hadOwnProperty) {
2859
+ global[method] = this["_" + method];
2860
+ } else {
2861
+ delete global[method];
2862
+ }
2863
+ }
2864
+
2865
+ // Prevent multiple executions which will completely remove these props
2866
+ this.methods = [];
2867
+ }
2868
+
2869
+ function stubGlobal(method, clock) {
2870
+ clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method);
2871
+ clock["_" + method] = global[method];
2872
+
2873
+ if (method == "Date") {
2874
+ var date = mirrorDateProperties(clock[method], global[method]);
2875
+ global[method] = date;
2876
+ } else {
2877
+ global[method] = function() {
2878
+ return clock[method].apply(clock, arguments);
2879
+ };
2880
+
2881
+ for (var prop in clock[method]) {
2882
+ if (clock[method].hasOwnProperty(prop)) {
2883
+ global[method][prop] = clock[method][prop];
2884
+ }
2885
+ }
2886
+ }
2887
+
2888
+ global[method].clock = clock;
2889
+ }
2890
+
2891
+ sinon.useFakeTimers = function useFakeTimers(now) {
2892
+ var clock = sinon.clock.create(now);
2893
+ clock.restore = restore;
2894
+ clock.methods = Array.prototype.slice.call(arguments, typeof now == "number" ? 1 : 0);
2895
+
2896
+ if (clock.methods.length === 0) {
2897
+ clock.methods = methods;
2898
+ }
2899
+
2900
+ for (var i = 0, l = clock.methods.length; i < l; i++) {
2901
+ stubGlobal(clock.methods[i], clock);
2902
+ }
2903
+
2904
+ return clock;
2905
+ };
2906
+ }(typeof global != "undefined" && typeof global !== "function" ? global : this));
2907
+
2908
+ sinon.timers = {
2909
+ setTimeout: setTimeout,
2910
+ clearTimeout: clearTimeout,
2911
+ setInterval: setInterval,
2912
+ clearInterval: clearInterval,
2913
+ Date: Date
2914
+ };
2915
+
2916
+ if (typeof module == "object" && typeof require == "function") {
2917
+ module.exports = sinon;
2918
+ }
2919
+
2920
+ /*jslint eqeqeq: false, onevar: false*/
2921
+ /*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/
2922
+ /**
2923
+ * Minimal Event interface implementation
2924
+ *
2925
+ * Original implementation by Sven Fuchs: https://gist.github.com/995028
2926
+ * Modifications and tests by Christian Johansen.
2927
+ *
2928
+ * @author Sven Fuchs (svenfuchs@artweb-design.de)
2929
+ * @author Christian Johansen (christian@cjohansen.no)
2930
+ * @license BSD
2931
+ *
2932
+ * Copyright (c) 2011 Sven Fuchs, Christian Johansen
2933
+ */
2934
+
2935
+ if (typeof sinon == "undefined") {
2936
+ this.sinon = {};
2937
+ }
2938
+
2939
+ (function() {
2940
+ var push = [].push;
2941
+
2942
+ sinon.Event = function Event(type, bubbles, cancelable) {
2943
+ this.initEvent(type, bubbles, cancelable);
2944
+ };
2945
+
2946
+ sinon.Event.prototype = {
2947
+ initEvent: function(type, bubbles, cancelable) {
2948
+ this.type = type;
2949
+ this.bubbles = bubbles;
2950
+ this.cancelable = cancelable;
2951
+ },
2952
+
2953
+ stopPropagation: function() {},
2954
+
2955
+ preventDefault: function() {
2956
+ this.defaultPrevented = true;
2957
+ }
2958
+ };
2959
+
2960
+ sinon.EventTarget = {
2961
+ addEventListener: function addEventListener(event, listener, useCapture) {
2962
+ this.eventListeners = this.eventListeners || {};
2963
+ this.eventListeners[event] = this.eventListeners[event] || [];
2964
+ push.call(this.eventListeners[event], listener);
2965
+ },
2966
+
2967
+ removeEventListener: function removeEventListener(event, listener, useCapture) {
2968
+ var listeners = this.eventListeners && this.eventListeners[event] || [];
2969
+
2970
+ for (var i = 0, l = listeners.length; i < l; ++i) {
2971
+ if (listeners[i] == listener) {
2972
+ return listeners.splice(i, 1);
2973
+ }
2974
+ }
2975
+ },
2976
+
2977
+ dispatchEvent: function dispatchEvent(event) {
2978
+ var type = event.type;
2979
+ var listeners = this.eventListeners && this.eventListeners[type] || [];
2980
+
2981
+ for (var i = 0; i < listeners.length; i++) {
2982
+ if (typeof listeners[i] == "function") {
2983
+ listeners[i].call(this, event);
2984
+ } else {
2985
+ listeners[i].handleEvent(event);
2986
+ }
2987
+ }
2988
+
2989
+ return !!event.defaultPrevented;
2990
+ }
2991
+ };
2992
+ }());
2993
+
2994
+ /**
2995
+ * @depend ../../sinon.js
2996
+ * @depend event.js
2997
+ */
2998
+ /*jslint eqeqeq: false, onevar: false*/
2999
+ /*global sinon, module, require, ActiveXObject, XMLHttpRequest, DOMParser*/
3000
+ /**
3001
+ * Fake XMLHttpRequest object
3002
+ *
3003
+ * @author Christian Johansen (christian@cjohansen.no)
3004
+ * @license BSD
3005
+ *
3006
+ * Copyright (c) 2010-2013 Christian Johansen
3007
+ */
3008
+
3009
+ if (typeof sinon == "undefined") {
3010
+ this.sinon = {};
3011
+ }
3012
+ sinon.xhr = {
3013
+ XMLHttpRequest: this.XMLHttpRequest
3014
+ };
3015
+
3016
+ // wrapper for global
3017
+ (function(global) {
3018
+ var xhr = sinon.xhr;
3019
+ xhr.GlobalXMLHttpRequest = global.XMLHttpRequest;
3020
+ xhr.GlobalActiveXObject = global.ActiveXObject;
3021
+ xhr.supportsActiveX = typeof xhr.GlobalActiveXObject != "undefined";
3022
+ xhr.supportsXHR = typeof xhr.GlobalXMLHttpRequest != "undefined";
3023
+ xhr.workingXHR = xhr.supportsXHR ? xhr.GlobalXMLHttpRequest : xhr.supportsActiveX ?
3024
+ function() {
3025
+ return new xhr.GlobalActiveXObject("MSXML2.XMLHTTP.3.0")
3026
+ } : false;
3027
+
3028
+ /*jsl:ignore*/
3029
+ var unsafeHeaders = {
3030
+ "Accept-Charset": true,
3031
+ "Accept-Encoding": true,
3032
+ "Connection": true,
3033
+ "Content-Length": true,
3034
+ "Cookie": true,
3035
+ "Cookie2": true,
3036
+ "Content-Transfer-Encoding": true,
3037
+ "Date": true,
3038
+ "Expect": true,
3039
+ "Host": true,
3040
+ "Keep-Alive": true,
3041
+ "Referer": true,
3042
+ "TE": true,
3043
+ "Trailer": true,
3044
+ "Transfer-Encoding": true,
3045
+ "Upgrade": true,
3046
+ "User-Agent": true,
3047
+ "Via": true
3048
+ };
3049
+ /*jsl:end*/
3050
+
3051
+ function FakeXMLHttpRequest() {
3052
+ this.readyState = FakeXMLHttpRequest.UNSENT;
3053
+ this.requestHeaders = {};
3054
+ this.requestBody = null;
3055
+ this.status = 0;
3056
+ this.statusText = "";
3057
+
3058
+ if (typeof FakeXMLHttpRequest.onCreate == "function") {
3059
+ FakeXMLHttpRequest.onCreate(this);
3060
+ }
3061
+ }
3062
+
3063
+ function verifyState(xhr) {
3064
+ if (xhr.readyState !== FakeXMLHttpRequest.OPENED) {
3065
+ throw new Error("INVALID_STATE_ERR");
3066
+ }
3067
+
3068
+ if (xhr.sendFlag) {
3069
+ throw new Error("INVALID_STATE_ERR");
3070
+ }
3071
+ }
3072
+
3073
+ // filtering to enable a white-list version of Sinon FakeXhr,
3074
+ // where whitelisted requests are passed through to real XHR
3075
+ function each(collection, callback) {
3076
+ if (!collection) return;
3077
+ for (var i = 0, l = collection.length; i < l; i += 1) {
3078
+ callback(collection[i]);
3079
+ }
3080
+ }
3081
+
3082
+ function some(collection, callback) {
3083
+ for (var index = 0; index < collection.length; index++) {
3084
+ if (callback(collection[index]) === true) return true;
3085
+ };
3086
+ return false;
3087
+ }
3088
+ // largest arity in XHR is 5 - XHR#open
3089
+ var apply = function(obj, method, args) {
3090
+ switch (args.length) {
3091
+ case 0:
3092
+ return obj[method]();
3093
+ case 1:
3094
+ return obj[method](args[0]);
3095
+ case 2:
3096
+ return obj[method](args[0], args[1]);
3097
+ case 3:
3098
+ return obj[method](args[0], args[1], args[2]);
3099
+ case 4:
3100
+ return obj[method](args[0], args[1], args[2], args[3]);
3101
+ case 5:
3102
+ return obj[method](args[0], args[1], args[2], args[3], args[4]);
3103
+ };
3104
+ };
3105
+
3106
+ FakeXMLHttpRequest.filters = [];
3107
+ FakeXMLHttpRequest.addFilter = function(fn) {
3108
+ this.filters.push(fn)
3109
+ };
3110
+ var IE6Re = /MSIE 6/;
3111
+ FakeXMLHttpRequest.defake = function(fakeXhr, xhrArgs) {
3112
+ var xhr = new sinon.xhr.workingXHR();
3113
+ each(["open", "setRequestHeader", "send", "abort", "getResponseHeader", "getAllResponseHeaders", "addEventListener", "overrideMimeType", "removeEventListener"], function(method) {
3114
+ fakeXhr[method] = function() {
3115
+ return apply(xhr, method, arguments);
3116
+ };
3117
+ });
3118
+
3119
+ var copyAttrs = function(args) {
3120
+ each(args, function(attr) {
3121
+ try {
3122
+ fakeXhr[attr] = xhr[attr]
3123
+ } catch (e) {
3124
+ if (!IE6Re.test(navigator.userAgent)) throw e;
3125
+ }
3126
+ });
3127
+ };
3128
+
3129
+ var stateChange = function() {
3130
+ fakeXhr.readyState = xhr.readyState;
3131
+ if (xhr.readyState >= FakeXMLHttpRequest.HEADERS_RECEIVED) {
3132
+ copyAttrs(["status", "statusText"]);
3133
+ }
3134
+ if (xhr.readyState >= FakeXMLHttpRequest.LOADING) {
3135
+ copyAttrs(["responseText"]);
3136
+ }
3137
+ if (xhr.readyState === FakeXMLHttpRequest.DONE) {
3138
+ copyAttrs(["responseXML"]);
3139
+ }
3140
+ if (fakeXhr.onreadystatechange) fakeXhr.onreadystatechange.call(fakeXhr);
3141
+ };
3142
+ if (xhr.addEventListener) {
3143
+ for (var event in fakeXhr.eventListeners) {
3144
+ if (fakeXhr.eventListeners.hasOwnProperty(event)) {
3145
+ each(fakeXhr.eventListeners[event], function(handler) {
3146
+ xhr.addEventListener(event, handler);
3147
+ });
3148
+ }
3149
+ }
3150
+ xhr.addEventListener("readystatechange", stateChange);
3151
+ } else {
3152
+ xhr.onreadystatechange = stateChange;
3153
+ }
3154
+ apply(xhr, "open", xhrArgs);
3155
+ };
3156
+ FakeXMLHttpRequest.useFilters = false;
3157
+
3158
+ function verifyRequestSent(xhr) {
3159
+ if (xhr.readyState == FakeXMLHttpRequest.DONE) {
3160
+ throw new Error("Request done");
3161
+ }
3162
+ }
3163
+
3164
+ function verifyHeadersReceived(xhr) {
3165
+ if (xhr.async && xhr.readyState != FakeXMLHttpRequest.HEADERS_RECEIVED) {
3166
+ throw new Error("No headers received");
3167
+ }
3168
+ }
3169
+
3170
+ function verifyResponseBodyType(body) {
3171
+ if (typeof body != "string") {
3172
+ var error = new Error("Attempted to respond to fake XMLHttpRequest with " + body + ", which is not a string.");
3173
+ error.name = "InvalidBodyException";
3174
+ throw error;
3175
+ }
3176
+ }
3177
+
3178
+ sinon.extend(FakeXMLHttpRequest.prototype, sinon.EventTarget, {
3179
+ async: true,
3180
+
3181
+ open: function open(method, url, async, username, password) {
3182
+ this.method = method;
3183
+ this.url = url;
3184
+ this.async = typeof async == "boolean" ? async : true;
3185
+ this.username = username;
3186
+ this.password = password;
3187
+ this.responseText = null;
3188
+ this.responseXML = null;
3189
+ this.requestHeaders = {};
3190
+ this.sendFlag = false;
3191
+ if (sinon.FakeXMLHttpRequest.useFilters === true) {
3192
+ var xhrArgs = arguments;
3193
+ var defake = some(FakeXMLHttpRequest.filters, function(filter) {
3194
+ return filter.apply(this, xhrArgs)
3195
+ });
3196
+ if (defake) {
3197
+ return sinon.FakeXMLHttpRequest.defake(this, arguments);
3198
+ }
3199
+ }
3200
+ this.readyStateChange(FakeXMLHttpRequest.OPENED);
3201
+ },
3202
+
3203
+ readyStateChange: function readyStateChange(state) {
3204
+ this.readyState = state;
3205
+
3206
+ if (typeof this.onreadystatechange == "function") {
3207
+ try {
3208
+ this.onreadystatechange();
3209
+ } catch (e) {
3210
+ sinon.logError("Fake XHR onreadystatechange handler", e);
3211
+ }
3212
+ }
3213
+
3214
+ this.dispatchEvent(new sinon.Event("readystatechange"));
3215
+ },
3216
+
3217
+ setRequestHeader: function setRequestHeader(header, value) {
3218
+ verifyState(this);
3219
+
3220
+ if (unsafeHeaders[header] || /^(Sec-|Proxy-)/.test(header)) {
3221
+ throw new Error("Refused to set unsafe header \"" + header + "\"");
3222
+ }
3223
+
3224
+ if (this.requestHeaders[header]) {
3225
+ this.requestHeaders[header] += "," + value;
3226
+ } else {
3227
+ this.requestHeaders[header] = value;
3228
+ }
3229
+ },
3230
+
3231
+ // Helps testing
3232
+ setResponseHeaders: function setResponseHeaders(headers) {
3233
+ this.responseHeaders = {};
3234
+
3235
+ for (var header in headers) {
3236
+ if (headers.hasOwnProperty(header)) {
3237
+ this.responseHeaders[header] = headers[header];
3238
+ }
3239
+ }
3240
+
3241
+ if (this.async) {
3242
+ this.readyStateChange(FakeXMLHttpRequest.HEADERS_RECEIVED);
3243
+ } else {
3244
+ this.readyState = FakeXMLHttpRequest.HEADERS_RECEIVED;
3245
+ }
3246
+ },
3247
+
3248
+ // Currently treats ALL data as a DOMString (i.e. no Document)
3249
+ send: function send(data) {
3250
+ verifyState(this);
3251
+
3252
+ if (!/^(get|head)$/i.test(this.method)) {
3253
+ if (this.requestHeaders["Content-Type"]) {
3254
+ var value = this.requestHeaders["Content-Type"].split(";");
3255
+ this.requestHeaders["Content-Type"] = value[0] + ";charset=utf-8";
3256
+ } else {
3257
+ this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
3258
+ }
3259
+
3260
+ this.requestBody = data;
3261
+ }
3262
+
3263
+ this.errorFlag = false;
3264
+ this.sendFlag = this.async;
3265
+ this.readyStateChange(FakeXMLHttpRequest.OPENED);
3266
+
3267
+ if (typeof this.onSend == "function") {
3268
+ this.onSend(this);
3269
+ }
3270
+ },
3271
+
3272
+ abort: function abort() {
3273
+ this.aborted = true;
3274
+ this.responseText = null;
3275
+ this.errorFlag = true;
3276
+ this.requestHeaders = {};
3277
+
3278
+ if (this.readyState > sinon.FakeXMLHttpRequest.UNSENT && this.sendFlag) {
3279
+ this.readyStateChange(sinon.FakeXMLHttpRequest.DONE);
3280
+ this.sendFlag = false;
3281
+ }
3282
+
3283
+ this.readyState = sinon.FakeXMLHttpRequest.UNSENT;
3284
+ },
3285
+
3286
+ getResponseHeader: function getResponseHeader(header) {
3287
+ if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
3288
+ return null;
3289
+ }
3290
+
3291
+ if (/^Set-Cookie2?$/i.test(header)) {
3292
+ return null;
3293
+ }
3294
+
3295
+ header = header.toLowerCase();
3296
+
3297
+ for (var h in this.responseHeaders) {
3298
+ if (h.toLowerCase() == header) {
3299
+ return this.responseHeaders[h];
3300
+ }
3301
+ }
3302
+
3303
+ return null;
3304
+ },
3305
+
3306
+ getAllResponseHeaders: function getAllResponseHeaders() {
3307
+ if (this.readyState < FakeXMLHttpRequest.HEADERS_RECEIVED) {
3308
+ return "";
3309
+ }
3310
+
3311
+ var headers = "";
3312
+
3313
+ for (var header in this.responseHeaders) {
3314
+ if (this.responseHeaders.hasOwnProperty(header) && !/^Set-Cookie2?$/i.test(header)) {
3315
+ headers += header + ": " + this.responseHeaders[header] + "\r\n";
3316
+ }
3317
+ }
3318
+
3319
+ return headers;
3320
+ },
3321
+
3322
+ setResponseBody: function setResponseBody(body) {
3323
+ verifyRequestSent(this);
3324
+ verifyHeadersReceived(this);
3325
+ verifyResponseBodyType(body);
3326
+
3327
+ var chunkSize = this.chunkSize || 10;
3328
+ var index = 0;
3329
+ this.responseText = "";
3330
+
3331
+ do {
3332
+ if (this.async) {
3333
+ this.readyStateChange(FakeXMLHttpRequest.LOADING);
3334
+ }
3335
+
3336
+ this.responseText += body.substring(index, index + chunkSize);
3337
+ index += chunkSize;
3338
+ } while (index < body.length);
3339
+
3340
+ var type = this.getResponseHeader("Content-Type");
3341
+
3342
+ if (this.responseText && (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) {
3343
+ try {
3344
+ this.responseXML = FakeXMLHttpRequest.parseXML(this.responseText);
3345
+ } catch (e) {
3346
+ // Unable to parse XML - no biggie
3347
+ }
3348
+ }
3349
+
3350
+ if (this.async) {
3351
+ this.readyStateChange(FakeXMLHttpRequest.DONE);
3352
+ } else {
3353
+ this.readyState = FakeXMLHttpRequest.DONE;
3354
+ }
3355
+ },
3356
+
3357
+ respond: function respond(status, headers, body) {
3358
+ this.setResponseHeaders(headers || {});
3359
+ this.status = typeof status == "number" ? status : 200;
3360
+ this.statusText = FakeXMLHttpRequest.statusCodes[this.status];
3361
+ this.setResponseBody(body || "");
3362
+ }
3363
+ });
3364
+
3365
+ sinon.extend(FakeXMLHttpRequest, {
3366
+ UNSENT: 0,
3367
+ OPENED: 1,
3368
+ HEADERS_RECEIVED: 2,
3369
+ LOADING: 3,
3370
+ DONE: 4
3371
+ });
3372
+
3373
+ // Borrowed from JSpec
3374
+ FakeXMLHttpRequest.parseXML = function parseXML(text) {
3375
+ var xmlDoc;
3376
+
3377
+ if (typeof DOMParser != "undefined") {
3378
+ var parser = new DOMParser();
3379
+ xmlDoc = parser.parseFromString(text, "text/xml");
3380
+ } else {
3381
+ xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
3382
+ xmlDoc.async = "false";
3383
+ xmlDoc.loadXML(text);
3384
+ }
3385
+
3386
+ return xmlDoc;
3387
+ };
3388
+
3389
+ FakeXMLHttpRequest.statusCodes = {
3390
+ 100: "Continue",
3391
+ 101: "Switching Protocols",
3392
+ 200: "OK",
3393
+ 201: "Created",
3394
+ 202: "Accepted",
3395
+ 203: "Non-Authoritative Information",
3396
+ 204: "No Content",
3397
+ 205: "Reset Content",
3398
+ 206: "Partial Content",
3399
+ 300: "Multiple Choice",
3400
+ 301: "Moved Permanently",
3401
+ 302: "Found",
3402
+ 303: "See Other",
3403
+ 304: "Not Modified",
3404
+ 305: "Use Proxy",
3405
+ 307: "Temporary Redirect",
3406
+ 400: "Bad Request",
3407
+ 401: "Unauthorized",
3408
+ 402: "Payment Required",
3409
+ 403: "Forbidden",
3410
+ 404: "Not Found",
3411
+ 405: "Method Not Allowed",
3412
+ 406: "Not Acceptable",
3413
+ 407: "Proxy Authentication Required",
3414
+ 408: "Request Timeout",
3415
+ 409: "Conflict",
3416
+ 410: "Gone",
3417
+ 411: "Length Required",
3418
+ 412: "Precondition Failed",
3419
+ 413: "Request Entity Too Large",
3420
+ 414: "Request-URI Too Long",
3421
+ 415: "Unsupported Media Type",
3422
+ 416: "Requested Range Not Satisfiable",
3423
+ 417: "Expectation Failed",
3424
+ 422: "Unprocessable Entity",
3425
+ 500: "Internal Server Error",
3426
+ 501: "Not Implemented",
3427
+ 502: "Bad Gateway",
3428
+ 503: "Service Unavailable",
3429
+ 504: "Gateway Timeout",
3430
+ 505: "HTTP Version Not Supported"
3431
+ };
3432
+
3433
+ sinon.useFakeXMLHttpRequest = function() {
3434
+ sinon.FakeXMLHttpRequest.restore = function restore(keepOnCreate) {
3435
+ if (xhr.supportsXHR) {
3436
+ global.XMLHttpRequest = xhr.GlobalXMLHttpRequest;
3437
+ }
3438
+
3439
+ if (xhr.supportsActiveX) {
3440
+ global.ActiveXObject = xhr.GlobalActiveXObject;
3441
+ }
3442
+
3443
+ delete sinon.FakeXMLHttpRequest.restore;
3444
+
3445
+ if (keepOnCreate !== true) {
3446
+ delete sinon.FakeXMLHttpRequest.onCreate;
3447
+ }
3448
+ };
3449
+ if (xhr.supportsXHR) {
3450
+ global.XMLHttpRequest = sinon.FakeXMLHttpRequest;
3451
+ }
3452
+
3453
+ if (xhr.supportsActiveX) {
3454
+ global.ActiveXObject = function ActiveXObject(objId) {
3455
+ if (objId == "Microsoft.XMLHTTP" || /^Msxml2\.XMLHTTP/i.test(objId)) {
3456
+
3457
+ return new sinon.FakeXMLHttpRequest();
3458
+ }
3459
+
3460
+ return new xhr.GlobalActiveXObject(objId);
3461
+ };
3462
+ }
3463
+
3464
+ return sinon.FakeXMLHttpRequest;
3465
+ };
3466
+
3467
+ sinon.FakeXMLHttpRequest = FakeXMLHttpRequest;
3468
+ })(this);
3469
+
3470
+ if (typeof module == "object" && typeof require == "function") {
3471
+ module.exports = sinon;
3472
+ }
3473
+
3474
+ /**
3475
+ * @depend fake_xml_http_request.js
3476
+ */
3477
+ /*jslint eqeqeq: false, onevar: false, regexp: false, plusplus: false*/
3478
+ /*global module, require, window*/
3479
+ /**
3480
+ * The Sinon "server" mimics a web server that receives requests from
3481
+ * sinon.FakeXMLHttpRequest and provides an API to respond to those requests,
3482
+ * both synchronously and asynchronously. To respond synchronuously, canned
3483
+ * answers have to be provided upfront.
3484
+ *
3485
+ * @author Christian Johansen (christian@cjohansen.no)
3486
+ * @license BSD
3487
+ *
3488
+ * Copyright (c) 2010-2013 Christian Johansen
3489
+ */
3490
+
3491
+ if (typeof sinon == "undefined") {
3492
+ var sinon = {};
3493
+ }
3494
+
3495
+ sinon.fakeServer = (function() {
3496
+ var push = [].push;
3497
+
3498
+ function F() {}
3499
+
3500
+ function create(proto) {
3501
+ F.prototype = proto;
3502
+ return new F();
3503
+ }
3504
+
3505
+ function responseArray(handler) {
3506
+ var response = handler;
3507
+
3508
+ if (Object.prototype.toString.call(handler) != "[object Array]") {
3509
+ response = [200,
3510
+ {},
3511
+ handler];
3512
+ }
3513
+
3514
+ if (typeof response[2] != "string") {
3515
+ throw new TypeError("Fake server response body should be string, but was " + typeof response[2]);
3516
+ }
3517
+
3518
+ return response;
3519
+ }
3520
+
3521
+ var wloc = typeof window !== "undefined" ? window.location : {};
3522
+ var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host);
3523
+
3524
+ function matchOne(response, reqMethod, reqUrl) {
3525
+ var rmeth = response.method;
3526
+ var matchMethod = !rmeth || rmeth.toLowerCase() == reqMethod.toLowerCase();
3527
+ var url = response.url;
3528
+ var matchUrl = !url || url == reqUrl || (typeof url.test == "function" && url.test(reqUrl));
3529
+
3530
+ return matchMethod && matchUrl;
3531
+ }
3532
+
3533
+ function match(response, request) {
3534
+ var requestMethod = this.getHTTPMethod(request);
3535
+ var requestUrl = request.url;
3536
+
3537
+ if (!/^https?:\/\//.test(requestUrl) || rCurrLoc.test(requestUrl)) {
3538
+ requestUrl = requestUrl.replace(rCurrLoc, "");
3539
+ }
3540
+
3541
+ if (matchOne(response, this.getHTTPMethod(request), requestUrl)) {
3542
+ if (typeof response.response == "function") {
3543
+ var ru = response.url;
3544
+ var args = [request].concat(!ru ? [] : requestUrl.match(ru).slice(1));
3545
+ return response.response.apply(response, args);
3546
+ }
3547
+
3548
+ return true;
3549
+ }
3550
+
3551
+ return false;
3552
+ }
3553
+
3554
+ function log(response, request) {
3555
+ var str;
3556
+
3557
+ str = "Request:\n" + sinon.format(request) + "\n\n";
3558
+ str += "Response:\n" + sinon.format(response) + "\n\n";
3559
+
3560
+ sinon.log(str);
3561
+ }
3562
+
3563
+ return {
3564
+ create: function() {
3565
+ var server = create(this);
3566
+ this.xhr = sinon.useFakeXMLHttpRequest();
3567
+ server.requests = [];
3568
+
3569
+ this.xhr.onCreate = function(xhrObj) {
3570
+ server.addRequest(xhrObj);
3571
+ };
3572
+
3573
+ return server;
3574
+ },
3575
+
3576
+ addRequest: function addRequest(xhrObj) {
3577
+ var server = this;
3578
+ push.call(this.requests, xhrObj);
3579
+
3580
+ xhrObj.onSend = function() {
3581
+ server.handleRequest(this);
3582
+ };
3583
+
3584
+ if (this.autoRespond && !this.responding) {
3585
+ setTimeout(function() {
3586
+ server.responding = false;
3587
+ server.respond();
3588
+ }, this.autoRespondAfter || 10);
3589
+
3590
+ this.responding = true;
3591
+ }
3592
+ },
3593
+
3594
+ getHTTPMethod: function getHTTPMethod(request) {
3595
+ if (this.fakeHTTPMethods && /post/i.test(request.method)) {
3596
+ var matches = (request.requestBody || "").match(/_method=([^\b;]+)/);
3597
+ return !!matches ? matches[1] : request.method;
3598
+ }
3599
+
3600
+ return request.method;
3601
+ },
3602
+
3603
+ handleRequest: function handleRequest(xhr) {
3604
+ if (xhr.async) {
3605
+ if (!this.queue) {
3606
+ this.queue = [];
3607
+ }
3608
+
3609
+ push.call(this.queue, xhr);
3610
+ } else {
3611
+ this.processRequest(xhr);
3612
+ }
3613
+ },
3614
+
3615
+ respondWith: function respondWith(method, url, body) {
3616
+ if (arguments.length == 1 && typeof method != "function") {
3617
+ this.response = responseArray(method);
3618
+ return;
3619
+ }
3620
+
3621
+ if (!this.responses) {
3622
+ this.responses = [];
3623
+ }
3624
+
3625
+ if (arguments.length == 1) {
3626
+ body = method;
3627
+ url = method = null;
3628
+ }
3629
+
3630
+ if (arguments.length == 2) {
3631
+ body = url;
3632
+ url = method;
3633
+ method = null;
3634
+ }
3635
+
3636
+ push.call(this.responses, {
3637
+ method: method,
3638
+ url: url,
3639
+ response: typeof body == "function" ? body : responseArray(body)
3640
+ });
3641
+ },
3642
+
3643
+ respond: function respond() {
3644
+ if (arguments.length > 0) this.respondWith.apply(this, arguments);
3645
+ var queue = this.queue || [];
3646
+ var request;
3647
+
3648
+ while (request = queue.shift()) {
3649
+ this.processRequest(request);
3650
+ }
3651
+ },
3652
+
3653
+ processRequest: function processRequest(request) {
3654
+ try {
3655
+ if (request.aborted) {
3656
+ return;
3657
+ }
3658
+
3659
+ var response = this.response || [404,
3660
+ {}, ""];
3661
+
3662
+ if (this.responses) {
3663
+ for (var i = 0, l = this.responses.length; i < l; i++) {
3664
+ if (match.call(this, this.responses[i], request)) {
3665
+ response = this.responses[i].response;
3666
+ break;
3667
+ }
3668
+ }
3669
+ }
3670
+
3671
+ if (request.readyState != 4) {
3672
+ log(response, request);
3673
+
3674
+ request.respond(response[0], response[1], response[2]);
3675
+ }
3676
+ } catch (e) {
3677
+ sinon.logError("Fake server request processing", e);
3678
+ }
3679
+ },
3680
+
3681
+ restore: function restore() {
3682
+ return this.xhr.restore && this.xhr.restore.apply(this.xhr, arguments);
3683
+ }
3684
+ };
3685
+ }());
3686
+
3687
+ if (typeof module == "object" && typeof require == "function") {
3688
+ module.exports = sinon;
3689
+ }
3690
+
3691
+ /**
3692
+ * @depend fake_server.js
3693
+ * @depend fake_timers.js
3694
+ */
3695
+ /*jslint browser: true, eqeqeq: false, onevar: false*/
3696
+ /*global sinon*/
3697
+ /**
3698
+ * Add-on for sinon.fakeServer that automatically handles a fake timer along with
3699
+ * the FakeXMLHttpRequest. The direct inspiration for this add-on is jQuery
3700
+ * 1.3.x, which does not use xhr object's onreadystatehandler at all - instead,
3701
+ * it polls the object for completion with setInterval. Dispite the direct
3702
+ * motivation, there is nothing jQuery-specific in this file, so it can be used
3703
+ * in any environment where the ajax implementation depends on setInterval or
3704
+ * setTimeout.
3705
+ *
3706
+ * @author Christian Johansen (christian@cjohansen.no)
3707
+ * @license BSD
3708
+ *
3709
+ * Copyright (c) 2010-2013 Christian Johansen
3710
+ */
3711
+
3712
+ (function() {
3713
+ function Server() {}
3714
+ Server.prototype = sinon.fakeServer;
3715
+
3716
+ sinon.fakeServerWithClock = new Server();
3717
+
3718
+ sinon.fakeServerWithClock.addRequest = function addRequest(xhr) {
3719
+ if (xhr.async) {
3720
+ if (typeof setTimeout.clock == "object") {
3721
+ this.clock = setTimeout.clock;
3722
+ } else {
3723
+ this.clock = sinon.useFakeTimers();
3724
+ this.resetClock = true;
3725
+ }
3726
+
3727
+ if (!this.longestTimeout) {
3728
+ var clockSetTimeout = this.clock.setTimeout;
3729
+ var clockSetInterval = this.clock.setInterval;
3730
+ var server = this;
3731
+
3732
+ this.clock.setTimeout = function(fn, timeout) {
3733
+ server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
3734
+
3735
+ return clockSetTimeout.apply(this, arguments);
3736
+ };
3737
+
3738
+ this.clock.setInterval = function(fn, timeout) {
3739
+ server.longestTimeout = Math.max(timeout, server.longestTimeout || 0);
3740
+
3741
+ return clockSetInterval.apply(this, arguments);
3742
+ };
3743
+ }
3744
+ }
3745
+
3746
+ return sinon.fakeServer.addRequest.call(this, xhr);
3747
+ };
3748
+
3749
+ sinon.fakeServerWithClock.respond = function respond() {
3750
+ var returnVal = sinon.fakeServer.respond.apply(this, arguments);
3751
+
3752
+ if (this.clock) {
3753
+ this.clock.tick(this.longestTimeout || 0);
3754
+ this.longestTimeout = 0;
3755
+
3756
+ if (this.resetClock) {
3757
+ this.clock.restore();
3758
+ this.resetClock = false;
3759
+ }
3760
+ }
3761
+
3762
+ return returnVal;
3763
+ };
3764
+
3765
+ sinon.fakeServerWithClock.restore = function restore() {
3766
+ if (this.clock) {
3767
+ this.clock.restore();
3768
+ }
3769
+
3770
+ return sinon.fakeServer.restore.apply(this, arguments);
3771
+ };
3772
+ }());
3773
+
3774
+ /**
3775
+ * @depend ../sinon.js
3776
+ * @depend collection.js
3777
+ * @depend util/fake_timers.js
3778
+ * @depend util/fake_server_with_clock.js
3779
+ */
3780
+ /*jslint eqeqeq: false, onevar: false, plusplus: false*/
3781
+ /*global require, module*/
3782
+ /**
3783
+ * Manages fake collections as well as fake utilities such as Sinon's
3784
+ * timers and fake XHR implementation in one convenient object.
3785
+ *
3786
+ * @author Christian Johansen (christian@cjohansen.no)
3787
+ * @license BSD
3788
+ *
3789
+ * Copyright (c) 2010-2013 Christian Johansen
3790
+ */
3791
+
3792
+ if (typeof module == "object" && typeof require == "function") {
3793
+ var sinon = require("../sinon");
3794
+ sinon.extend(sinon, require("./util/fake_timers"));
3795
+ }
3796
+
3797
+ (function() {
3798
+ var push = [].push;
3799
+
3800
+ function exposeValue(sandbox, config, key, value) {
3801
+ if (!value) {
3802
+ return;
3803
+ }
3804
+
3805
+ if (config.injectInto) {
3806
+ config.injectInto[key] = value;
3807
+ } else {
3808
+ push.call(sandbox.args, value);
3809
+ }
3810
+ }
3811
+
3812
+ function prepareSandboxFromConfig(config) {
3813
+ var sandbox = sinon.create(sinon.sandbox);
3814
+
3815
+ if (config.useFakeServer) {
3816
+ if (typeof config.useFakeServer == "object") {
3817
+ sandbox.serverPrototype = config.useFakeServer;
3818
+ }
3819
+
3820
+ sandbox.useFakeServer();
3821
+ }
3822
+
3823
+ if (config.useFakeTimers) {
3824
+ if (typeof config.useFakeTimers == "object") {
3825
+ sandbox.useFakeTimers.apply(sandbox, config.useFakeTimers);
3826
+ } else {
3827
+ sandbox.useFakeTimers();
3828
+ }
3829
+ }
3830
+
3831
+ return sandbox;
3832
+ }
3833
+
3834
+ sinon.sandbox = sinon.extend(sinon.create(sinon.collection), {
3835
+ useFakeTimers: function useFakeTimers() {
3836
+ this.clock = sinon.useFakeTimers.apply(sinon, arguments);
3837
+
3838
+ return this.add(this.clock);
3839
+ },
3840
+
3841
+ serverPrototype: sinon.fakeServer,
3842
+
3843
+ useFakeServer: function useFakeServer() {
3844
+ var proto = this.serverPrototype || sinon.fakeServer;
3845
+
3846
+ if (!proto || !proto.create) {
3847
+ return null;
3848
+ }
3849
+
3850
+ this.server = proto.create();
3851
+ return this.add(this.server);
3852
+ },
3853
+
3854
+ inject: function(obj) {
3855
+ sinon.collection.inject.call(this, obj);
3856
+
3857
+ if (this.clock) {
3858
+ obj.clock = this.clock;
3859
+ }
3860
+
3861
+ if (this.server) {
3862
+ obj.server = this.server;
3863
+ obj.requests = this.server.requests;
3864
+ }
3865
+
3866
+ return obj;
3867
+ },
3868
+
3869
+ create: function(config) {
3870
+ if (!config) {
3871
+ return sinon.create(sinon.sandbox);
3872
+ }
3873
+
3874
+ var sandbox = prepareSandboxFromConfig(config);
3875
+ sandbox.args = sandbox.args || [];
3876
+ var prop, value, exposed = sandbox.inject({});
3877
+
3878
+ if (config.properties) {
3879
+ for (var i = 0, l = config.properties.length; i < l; i++) {
3880
+ prop = config.properties[i];
3881
+ value = exposed[prop] || prop == "sandbox" && sandbox;
3882
+ exposeValue(sandbox, config, prop, value);
3883
+ }
3884
+ } else {
3885
+ exposeValue(sandbox, config, "sandbox", value);
3886
+ }
3887
+
3888
+ return sandbox;
3889
+ }
3890
+ });
3891
+
3892
+ sinon.sandbox.useFakeXMLHttpRequest = sinon.sandbox.useFakeServer;
3893
+
3894
+ if (typeof module == "object" && typeof require == "function") {
3895
+ module.exports = sinon.sandbox;
3896
+ }
3897
+ }());
3898
+
3899
+ /**
3900
+ * @depend ../sinon.js
3901
+ * @depend stub.js
3902
+ * @depend mock.js
3903
+ * @depend sandbox.js
3904
+ */
3905
+ /*jslint eqeqeq: false, onevar: false, forin: true, plusplus: false*/
3906
+ /*global module, require, sinon*/
3907
+ /**
3908
+ * Test function, sandboxes fakes
3909
+ *
3910
+ * @author Christian Johansen (christian@cjohansen.no)
3911
+ * @license BSD
3912
+ *
3913
+ * Copyright (c) 2010-2013 Christian Johansen
3914
+ */
3915
+
3916
+ (function(sinon) {
3917
+ var commonJSModule = typeof module == "object" && typeof require == "function";
3918
+
3919
+ if (!sinon && commonJSModule) {
3920
+ sinon = require("../sinon");
3921
+ }
3922
+
3923
+ if (!sinon) {
3924
+ return;
3925
+ }
3926
+
3927
+ function test(callback) {
3928
+ var type = typeof callback;
3929
+
3930
+ if (type != "function") {
3931
+ throw new TypeError("sinon.test needs to wrap a test function, got " + type);
3932
+ }
3933
+
3934
+ return function() {
3935
+ var config = sinon.getConfig(sinon.config);
3936
+ config.injectInto = config.injectIntoThis && this || config.injectInto;
3937
+ var sandbox = sinon.sandbox.create(config);
3938
+ var exception, result;
3939
+ var args = Array.prototype.slice.call(arguments).concat(sandbox.args);
3940
+
3941
+ try {
3942
+ result = callback.apply(this, args);
3943
+ } catch (e) {
3944
+ exception = e;
3945
+ }
3946
+
3947
+ if (typeof exception !== "undefined") {
3948
+ sandbox.restore();
3949
+ throw exception;
3950
+ } else {
3951
+ sandbox.verifyAndRestore();
3952
+ }
3953
+
3954
+ return result;
3955
+ };
3956
+ }
3957
+
3958
+ test.config = {
3959
+ injectIntoThis: true,
3960
+ injectInto: null,
3961
+ properties: ["spy", "stub", "mock", "clock", "server", "requests"],
3962
+ useFakeTimers: true,
3963
+ useFakeServer: true
3964
+ };
3965
+
3966
+ if (commonJSModule) {
3967
+ module.exports = test;
3968
+ } else {
3969
+ sinon.test = test;
3970
+ }
3971
+ }(typeof sinon == "object" && sinon || null));
3972
+
3973
+ /**
3974
+ * @depend ../sinon.js
3975
+ * @depend test.js
3976
+ */
3977
+ /*jslint eqeqeq: false, onevar: false, eqeqeq: false*/
3978
+ /*global module, require, sinon*/
3979
+ /**
3980
+ * Test case, sandboxes all test functions
3981
+ *
3982
+ * @author Christian Johansen (christian@cjohansen.no)
3983
+ * @license BSD
3984
+ *
3985
+ * Copyright (c) 2010-2013 Christian Johansen
3986
+ */
3987
+
3988
+ (function(sinon) {
3989
+ var commonJSModule = typeof module == "object" && typeof require == "function";
3990
+
3991
+ if (!sinon && commonJSModule) {
3992
+ sinon = require("../sinon");
3993
+ }
3994
+
3995
+ if (!sinon || !Object.prototype.hasOwnProperty) {
3996
+ return;
3997
+ }
3998
+
3999
+ function createTest(property, setUp, tearDown) {
4000
+ return function() {
4001
+ if (setUp) {
4002
+ setUp.apply(this, arguments);
4003
+ }
4004
+
4005
+ var exception, result;
4006
+
4007
+ try {
4008
+ result = property.apply(this, arguments);
4009
+ } catch (e) {
4010
+ exception = e;
4011
+ }
4012
+
4013
+ if (tearDown) {
4014
+ tearDown.apply(this, arguments);
4015
+ }
4016
+
4017
+ if (exception) {
4018
+ throw exception;
4019
+ }
4020
+
4021
+ return result;
4022
+ };
4023
+ }
4024
+
4025
+ function testCase(tests, prefix) {
4026
+ /*jsl:ignore*/
4027
+ if (!tests || typeof tests != "object") {
4028
+ throw new TypeError("sinon.testCase needs an object with test functions");
4029
+ }
4030
+ /*jsl:end*/
4031
+
4032
+ prefix = prefix || "test";
4033
+ var rPrefix = new RegExp("^" + prefix);
4034
+ var methods = {},
4035
+ testName, property, method;
4036
+ var setUp = tests.setUp;
4037
+ var tearDown = tests.tearDown;
4038
+
4039
+ for (testName in tests) {
4040
+ if (tests.hasOwnProperty(testName)) {
4041
+ property = tests[testName];
4042
+
4043
+ if (/^(setUp|tearDown)$/.test(testName)) {
4044
+ continue;
4045
+ }
4046
+
4047
+ if (typeof property == "function" && rPrefix.test(testName)) {
4048
+ method = property;
4049
+
4050
+ if (setUp || tearDown) {
4051
+ method = createTest(property, setUp, tearDown);
4052
+ }
4053
+
4054
+ methods[testName] = sinon.test(method);
4055
+ } else {
4056
+ methods[testName] = tests[testName];
4057
+ }
4058
+ }
4059
+ }
4060
+
4061
+ return methods;
4062
+ }
4063
+
4064
+ if (commonJSModule) {
4065
+ module.exports = testCase;
4066
+ } else {
4067
+ sinon.testCase = testCase;
4068
+ }
4069
+ }(typeof sinon == "object" && sinon || null));
4070
+
4071
+ /**
4072
+ * @depend ../sinon.js
4073
+ * @depend stub.js
4074
+ */
4075
+ /*jslint eqeqeq: false, onevar: false, nomen: false, plusplus: false*/
4076
+ /*global module, require, sinon*/
4077
+ /**
4078
+ * Assertions matching the test spy retrieval interface.
4079
+ *
4080
+ * @author Christian Johansen (christian@cjohansen.no)
4081
+ * @license BSD
4082
+ *
4083
+ * Copyright (c) 2010-2013 Christian Johansen
4084
+ */
4085
+
4086
+ (function(sinon, global) {
4087
+ var commonJSModule = typeof module == "object" && typeof require == "function";
4088
+ var slice = Array.prototype.slice;
4089
+ var assert;
4090
+
4091
+ if (!sinon && commonJSModule) {
4092
+ sinon = require("../sinon");
4093
+ }
4094
+
4095
+ if (!sinon) {
4096
+ return;
4097
+ }
4098
+
4099
+ function verifyIsStub() {
4100
+ var method;
4101
+
4102
+ for (var i = 0, l = arguments.length; i < l; ++i) {
4103
+ method = arguments[i];
4104
+
4105
+ if (!method) {
4106
+ assert.fail("fake is not a spy");
4107
+ }
4108
+
4109
+ if (typeof method != "function") {
4110
+ assert.fail(method + " is not a function");
4111
+ }
4112
+
4113
+ if (typeof method.getCall != "function") {
4114
+ assert.fail(method + " is not stubbed");
4115
+ }
4116
+ }
4117
+ }
4118
+
4119
+ function failAssertion(object, msg) {
4120
+ object = object || global;
4121
+ var failMethod = object.fail || assert.fail;
4122
+ failMethod.call(object, msg);
4123
+ }
4124
+
4125
+ function mirrorPropAsAssertion(name, method, message) {
4126
+ if (arguments.length == 2) {
4127
+ message = method;
4128
+ method = name;
4129
+ }
4130
+
4131
+ assert[name] = function(fake) {
4132
+ verifyIsStub(fake);
4133
+
4134
+ var args = slice.call(arguments, 1);
4135
+ var failed = false;
4136
+
4137
+ if (typeof method == "function") {
4138
+ failed = !method(fake);
4139
+ } else {
4140
+ failed = typeof fake[method] == "function" ? !fake[method].apply(fake, args) : !fake[method];
4141
+ }
4142
+
4143
+ if (failed) {
4144
+ failAssertion(this, fake.printf.apply(fake, [message].concat(args)));
4145
+ } else {
4146
+ assert.pass(name);
4147
+ }
4148
+ };
4149
+ }
4150
+
4151
+ function exposedName(prefix, prop) {
4152
+ return !prefix || /^fail/.test(prop) ? prop : prefix + prop.slice(0, 1).toUpperCase() + prop.slice(1);
4153
+ };
4154
+
4155
+ assert = {
4156
+ failException: "AssertError",
4157
+
4158
+ fail: function fail(message) {
4159
+ var error = new Error(message);
4160
+ error.name = this.failException || assert.failException;
4161
+
4162
+ throw error;
4163
+ },
4164
+
4165
+ pass: function pass(assertion) {},
4166
+
4167
+ callOrder: function assertCallOrder() {
4168
+ verifyIsStub.apply(null, arguments);
4169
+ var expected = "",
4170
+ actual = "";
4171
+
4172
+ if (!sinon.calledInOrder(arguments)) {
4173
+ try {
4174
+ expected = [].join.call(arguments, ", ");
4175
+ actual = sinon.orderByFirstCall(slice.call(arguments)).join(", ");
4176
+ } catch (e) {
4177
+ // If this fails, we'll just fall back to the blank string
4178
+ }
4179
+
4180
+ failAssertion(this, "expected " + expected + " to be " + "called in order but were called as " + actual);
4181
+ } else {
4182
+ assert.pass("callOrder");
4183
+ }
4184
+ },
4185
+
4186
+ callCount: function assertCallCount(method, count) {
4187
+ verifyIsStub(method);
4188
+
4189
+ if (method.callCount != count) {
4190
+ var msg = "expected %n to be called " + sinon.timesInWords(count) + " but was called %c%C";
4191
+ failAssertion(this, method.printf(msg));
4192
+ } else {
4193
+ assert.pass("callCount");
4194
+ }
4195
+ },
4196
+
4197
+ expose: function expose(target, options) {
4198
+ if (!target) {
4199
+ throw new TypeError("target is null or undefined");
4200
+ }
4201
+
4202
+ var o = options || {};
4203
+ var prefix = typeof o.prefix == "undefined" && "assert" || o.prefix;
4204
+ var includeFail = typeof o.includeFail == "undefined" || !! o.includeFail;
4205
+
4206
+ for (var method in this) {
4207
+ if (method != "export" && (includeFail || !/^(fail)/.test(method))) {
4208
+ target[exposedName(prefix, method)] = this[method];
4209
+ }
4210
+ }
4211
+
4212
+ return target;
4213
+ }
4214
+ };
4215
+
4216
+ mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called");
4217
+ mirrorPropAsAssertion("notCalled", function(spy) {
4218
+ return !spy.called;
4219
+ }, "expected %n to not have been called but was called %c%C");
4220
+ mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C");
4221
+ mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C");
4222
+ mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C");
4223
+ mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t");
4224
+ mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t");
4225
+ mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new");
4226
+ mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new");
4227
+ mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %*%C");
4228
+ mirrorPropAsAssertion("calledWithMatch", "expected %n to be called with match %*%C");
4229
+ mirrorPropAsAssertion("alwaysCalledWith", "expected %n to always be called with arguments %*%C");
4230
+ mirrorPropAsAssertion("alwaysCalledWithMatch", "expected %n to always be called with match %*%C");
4231
+ mirrorPropAsAssertion("calledWithExactly", "expected %n to be called with exact arguments %*%C");
4232
+ mirrorPropAsAssertion("alwaysCalledWithExactly", "expected %n to always be called with exact arguments %*%C");
4233
+ mirrorPropAsAssertion("neverCalledWith", "expected %n to never be called with arguments %*%C");
4234
+ mirrorPropAsAssertion("neverCalledWithMatch", "expected %n to never be called with match %*%C");
4235
+ mirrorPropAsAssertion("threw", "%n did not throw exception%C");
4236
+ mirrorPropAsAssertion("alwaysThrew", "%n did not always throw exception%C");
4237
+
4238
+ if (commonJSModule) {
4239
+ module.exports = assert;
4240
+ } else {
4241
+ sinon.assert = assert;
4242
+ }
4243
+ }(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : global));
4244
+
4245
+ return sinon;
4246
+ }.call(typeof window != 'undefined' && window || {}));