ember-data-factory-guy 0.1.1 → 0.1.2

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