You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4818 lines
146 KiB

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