chai-backbone-rails 0.0.1 → 0.0.2

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