not really known
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.

5332 lines
132 KiB

  1. ;(function(){
  2. /**
  3. * Require the module at `name`.
  4. *
  5. * @param {String} name
  6. * @return {Object} exports
  7. * @api public
  8. */
  9. function require(name) {
  10. var module = require.modules[name];
  11. if (!module) throw new Error('failed to require "' + name + '"');
  12. if (!('exports' in module) && typeof module.definition === 'function') {
  13. module.client = module.component = true;
  14. module.definition.call(this, module.exports = {}, module);
  15. delete module.definition;
  16. }
  17. return module.exports;
  18. }
  19. /**
  20. * Meta info, accessible in the global scope unless you use AMD option.
  21. */
  22. require.loader = 'component';
  23. /**
  24. * Internal helper object, contains a sorting function for semantiv versioning
  25. */
  26. require.helper = {};
  27. require.helper.semVerSort = function(a, b) {
  28. var aArray = a.version.split('.');
  29. var bArray = b.version.split('.');
  30. for (var i=0; i<aArray.length; ++i) {
  31. var aInt = parseInt(aArray[i], 10);
  32. var bInt = parseInt(bArray[i], 10);
  33. if (aInt === bInt) {
  34. var aLex = aArray[i].substr((""+aInt).length);
  35. var bLex = bArray[i].substr((""+bInt).length);
  36. if (aLex === '' && bLex !== '') return 1;
  37. if (aLex !== '' && bLex === '') return -1;
  38. if (aLex !== '' && bLex !== '') return aLex > bLex ? 1 : -1;
  39. continue;
  40. } else if (aInt > bInt) {
  41. return 1;
  42. } else {
  43. return -1;
  44. }
  45. }
  46. return 0;
  47. }
  48. /**
  49. * Find and require a module which name starts with the provided name.
  50. * If multiple modules exists, the highest semver is used.
  51. * This function can only be used for remote dependencies.
  52. * @param {String} name - module name: `user~repo`
  53. * @param {Boolean} returnPath - returns the canonical require path if true,
  54. * otherwise it returns the epxorted module
  55. */
  56. require.latest = function (name, returnPath) {
  57. function showError(name) {
  58. throw new Error('failed to find latest module of "' + name + '"');
  59. }
  60. // only remotes with semvers, ignore local files conataining a '/'
  61. var versionRegexp = /(.*)~(.*)@v?(\d+\.\d+\.\d+[^\/]*)$/;
  62. var remoteRegexp = /(.*)~(.*)/;
  63. if (!remoteRegexp.test(name)) showError(name);
  64. var moduleNames = Object.keys(require.modules);
  65. var semVerCandidates = [];
  66. var otherCandidates = []; // for instance: name of the git branch
  67. for (var i=0; i<moduleNames.length; i++) {
  68. var moduleName = moduleNames[i];
  69. if (new RegExp(name + '@').test(moduleName)) {
  70. var version = moduleName.substr(name.length+1);
  71. var semVerMatch = versionRegexp.exec(moduleName);
  72. if (semVerMatch != null) {
  73. semVerCandidates.push({version: version, name: moduleName});
  74. } else {
  75. otherCandidates.push({version: version, name: moduleName});
  76. }
  77. }
  78. }
  79. if (semVerCandidates.concat(otherCandidates).length === 0) {
  80. showError(name);
  81. }
  82. if (semVerCandidates.length > 0) {
  83. var module = semVerCandidates.sort(require.helper.semVerSort).pop().name;
  84. if (returnPath === true) {
  85. return module;
  86. }
  87. return require(module);
  88. }
  89. // if the build contains more than one branch of the same module
  90. // you should not use this funciton
  91. var module = otherCandidates.sort(function(a, b) {return a.name > b.name})[0].name;
  92. if (returnPath === true) {
  93. return module;
  94. }
  95. return require(module);
  96. }
  97. /**
  98. * Registered modules.
  99. */
  100. require.modules = {};
  101. /**
  102. * Register module at `name` with callback `definition`.
  103. *
  104. * @param {String} name
  105. * @param {Function} definition
  106. * @api private
  107. */
  108. require.register = function (name, definition) {
  109. require.modules[name] = {
  110. definition: definition
  111. };
  112. };
  113. /**
  114. * Define a module's exports immediately with `exports`.
  115. *
  116. * @param {String} name
  117. * @param {Generic} exports
  118. * @api private
  119. */
  120. require.define = function (name, exports) {
  121. require.modules[name] = {
  122. exports: exports
  123. };
  124. };
  125. require.register("chaijs~assertion-error@1.0.0", function (exports, module) {
  126. /*!
  127. * assertion-error
  128. * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
  129. * MIT Licensed
  130. */
  131. /*!
  132. * Return a function that will copy properties from
  133. * one object to another excluding any originally
  134. * listed. Returned function will create a new `{}`.
  135. *
  136. * @param {String} excluded properties ...
  137. * @return {Function}
  138. */
  139. function exclude () {
  140. var excludes = [].slice.call(arguments);
  141. function excludeProps (res, obj) {
  142. Object.keys(obj).forEach(function (key) {
  143. if (!~excludes.indexOf(key)) res[key] = obj[key];
  144. });
  145. }
  146. return function extendExclude () {
  147. var args = [].slice.call(arguments)
  148. , i = 0
  149. , res = {};
  150. for (; i < args.length; i++) {
  151. excludeProps(res, args[i]);
  152. }
  153. return res;
  154. };
  155. };
  156. /*!
  157. * Primary Exports
  158. */
  159. module.exports = AssertionError;
  160. /**
  161. * ### AssertionError
  162. *
  163. * An extension of the JavaScript `Error` constructor for
  164. * assertion and validation scenarios.
  165. *
  166. * @param {String} message
  167. * @param {Object} properties to include (optional)
  168. * @param {callee} start stack function (optional)
  169. */
  170. function AssertionError (message, _props, ssf) {
  171. var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
  172. , props = extend(_props || {});
  173. // default values
  174. this.message = message || 'Unspecified AssertionError';
  175. this.showDiff = false;
  176. // copy from properties
  177. for (var key in props) {
  178. this[key] = props[key];
  179. }
  180. // capture stack trace
  181. ssf = ssf || arguments.callee;
  182. if (ssf && Error.captureStackTrace) {
  183. Error.captureStackTrace(this, ssf);
  184. }
  185. }
  186. /*!
  187. * Inherit from Error.prototype
  188. */
  189. AssertionError.prototype = Object.create(Error.prototype);
  190. /*!
  191. * Statically set name
  192. */
  193. AssertionError.prototype.name = 'AssertionError';
  194. /*!
  195. * Ensure correct constructor
  196. */
  197. AssertionError.prototype.constructor = AssertionError;
  198. /**
  199. * Allow errors to be converted to JSON for static transfer.
  200. *
  201. * @param {Boolean} include stack (default: `true`)
  202. * @return {Object} object that can be `JSON.stringify`
  203. */
  204. AssertionError.prototype.toJSON = function (stack) {
  205. var extend = exclude('constructor', 'toJSON', 'stack')
  206. , props = extend({ name: this.name }, this);
  207. // include stack if exists and not turned off
  208. if (false !== stack && this.stack) {
  209. props.stack = this.stack;
  210. }
  211. return props;
  212. };
  213. });
  214. require.register("chaijs~type-detect@0.1.1", function (exports, module) {
  215. /*!
  216. * type-detect
  217. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  218. * MIT Licensed
  219. */
  220. /*!
  221. * Primary Exports
  222. */
  223. var exports = module.exports = getType;
  224. /*!
  225. * Detectable javascript natives
  226. */
  227. var natives = {
  228. '[object Array]': 'array'
  229. , '[object RegExp]': 'regexp'
  230. , '[object Function]': 'function'
  231. , '[object Arguments]': 'arguments'
  232. , '[object Date]': 'date'
  233. };
  234. /**
  235. * ### typeOf (obj)
  236. *
  237. * Use several different techniques to determine
  238. * the type of object being tested.
  239. *
  240. *
  241. * @param {Mixed} object
  242. * @return {String} object type
  243. * @api public
  244. */
  245. function getType (obj) {
  246. var str = Object.prototype.toString.call(obj);
  247. if (natives[str]) return natives[str];
  248. if (obj === null) return 'null';
  249. if (obj === undefined) return 'undefined';
  250. if (obj === Object(obj)) return 'object';
  251. return typeof obj;
  252. }
  253. exports.Library = Library;
  254. /**
  255. * ### Library
  256. *
  257. * Create a repository for custom type detection.
  258. *
  259. * ```js
  260. * var lib = new type.Library;
  261. * ```
  262. *
  263. */
  264. function Library () {
  265. this.tests = {};
  266. }
  267. /**
  268. * #### .of (obj)
  269. *
  270. * Expose replacement `typeof` detection to the library.
  271. *
  272. * ```js
  273. * if ('string' === lib.of('hello world')) {
  274. * // ...
  275. * }
  276. * ```
  277. *
  278. * @param {Mixed} object to test
  279. * @return {String} type
  280. */
  281. Library.prototype.of = getType;
  282. /**
  283. * #### .define (type, test)
  284. *
  285. * Add a test to for the `.test()` assertion.
  286. *
  287. * Can be defined as a regular expression:
  288. *
  289. * ```js
  290. * lib.define('int', /^[0-9]+$/);
  291. * ```
  292. *
  293. * ... or as a function:
  294. *
  295. * ```js
  296. * lib.define('bln', function (obj) {
  297. * if ('boolean' === lib.of(obj)) return true;
  298. * var blns = [ 'yes', 'no', 'true', 'false', 1, 0 ];
  299. * if ('string' === lib.of(obj)) obj = obj.toLowerCase();
  300. * return !! ~blns.indexOf(obj);
  301. * });
  302. * ```
  303. *
  304. * @param {String} type
  305. * @param {RegExp|Function} test
  306. * @api public
  307. */
  308. Library.prototype.define = function (type, test) {
  309. if (arguments.length === 1) return this.tests[type];
  310. this.tests[type] = test;
  311. return this;
  312. };
  313. /**
  314. * #### .test (obj, test)
  315. *
  316. * Assert that an object is of type. Will first
  317. * check natives, and if that does not pass it will
  318. * use the user defined custom tests.
  319. *
  320. * ```js
  321. * assert(lib.test('1', 'int'));
  322. * assert(lib.test('yes', 'bln'));
  323. * ```
  324. *
  325. * @param {Mixed} object
  326. * @param {String} type
  327. * @return {Boolean} result
  328. * @api public
  329. */
  330. Library.prototype.test = function (obj, type) {
  331. if (type === getType(obj)) return true;
  332. var test = this.tests[type];
  333. if (test && 'regexp' === getType(test)) {
  334. return test.test(obj);
  335. } else if (test && 'function' === getType(test)) {
  336. return test(obj);
  337. } else {
  338. throw new ReferenceError('Type test "' + type + '" not defined or invalid.');
  339. }
  340. };
  341. });
  342. require.register("chaijs~deep-eql@0.1.3", function (exports, module) {
  343. /*!
  344. * deep-eql
  345. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  346. * MIT Licensed
  347. */
  348. /*!
  349. * Module dependencies
  350. */
  351. var type = require('chaijs~type-detect@0.1.1');
  352. /*!
  353. * Buffer.isBuffer browser shim
  354. */
  355. var Buffer;
  356. try { Buffer = require('buffer').Buffer; }
  357. catch(ex) {
  358. Buffer = {};
  359. Buffer.isBuffer = function() { return false; }
  360. }
  361. /*!
  362. * Primary Export
  363. */
  364. module.exports = deepEqual;
  365. /**
  366. * Assert super-strict (egal) equality between
  367. * two objects of any type.
  368. *
  369. * @param {Mixed} a
  370. * @param {Mixed} b
  371. * @param {Array} memoised (optional)
  372. * @return {Boolean} equal match
  373. */
  374. function deepEqual(a, b, m) {
  375. if (sameValue(a, b)) {
  376. return true;
  377. } else if ('date' === type(a)) {
  378. return dateEqual(a, b);
  379. } else if ('regexp' === type(a)) {
  380. return regexpEqual(a, b);
  381. } else if (Buffer.isBuffer(a)) {
  382. return bufferEqual(a, b);
  383. } else if ('arguments' === type(a)) {
  384. return argumentsEqual(a, b, m);
  385. } else if (!typeEqual(a, b)) {
  386. return false;
  387. } else if (('object' !== type(a) && 'object' !== type(b))
  388. && ('array' !== type(a) && 'array' !== type(b))) {
  389. return sameValue(a, b);
  390. } else {
  391. return objectEqual(a, b, m);
  392. }
  393. }
  394. /*!
  395. * Strict (egal) equality test. Ensures that NaN always
  396. * equals NaN and `-0` does not equal `+0`.
  397. *
  398. * @param {Mixed} a
  399. * @param {Mixed} b
  400. * @return {Boolean} equal match
  401. */
  402. function sameValue(a, b) {
  403. if (a === b) return a !== 0 || 1 / a === 1 / b;
  404. return a !== a && b !== b;
  405. }
  406. /*!
  407. * Compare the types of two given objects and
  408. * return if they are equal. Note that an Array
  409. * has a type of `array` (not `object`) and arguments
  410. * have a type of `arguments` (not `array`/`object`).
  411. *
  412. * @param {Mixed} a
  413. * @param {Mixed} b
  414. * @return {Boolean} result
  415. */
  416. function typeEqual(a, b) {
  417. return type(a) === type(b);
  418. }
  419. /*!
  420. * Compare two Date objects by asserting that
  421. * the time values are equal using `saveValue`.
  422. *
  423. * @param {Date} a
  424. * @param {Date} b
  425. * @return {Boolean} result
  426. */
  427. function dateEqual(a, b) {
  428. if ('date' !== type(b)) return false;
  429. return sameValue(a.getTime(), b.getTime());
  430. }
  431. /*!
  432. * Compare two regular expressions by converting them
  433. * to string and checking for `sameValue`.
  434. *
  435. * @param {RegExp} a
  436. * @param {RegExp} b
  437. * @return {Boolean} result
  438. */
  439. function regexpEqual(a, b) {
  440. if ('regexp' !== type(b)) return false;
  441. return sameValue(a.toString(), b.toString());
  442. }
  443. /*!
  444. * Assert deep equality of two `arguments` objects.
  445. * Unfortunately, these must be sliced to arrays
  446. * prior to test to ensure no bad behavior.
  447. *
  448. * @param {Arguments} a
  449. * @param {Arguments} b
  450. * @param {Array} memoize (optional)
  451. * @return {Boolean} result
  452. */
  453. function argumentsEqual(a, b, m) {
  454. if ('arguments' !== type(b)) return false;
  455. a = [].slice.call(a);
  456. b = [].slice.call(b);
  457. return deepEqual(a, b, m);
  458. }
  459. /*!
  460. * Get enumerable properties of a given object.
  461. *
  462. * @param {Object} a
  463. * @return {Array} property names
  464. */
  465. function enumerable(a) {
  466. var res = [];
  467. for (var key in a) res.push(key);
  468. return res;
  469. }
  470. /*!
  471. * Simple equality for flat iterable objects
  472. * such as Arrays or Node.js buffers.
  473. *
  474. * @param {Iterable} a
  475. * @param {Iterable} b
  476. * @return {Boolean} result
  477. */
  478. function iterableEqual(a, b) {
  479. if (a.length !== b.length) return false;
  480. var i = 0;
  481. var match = true;
  482. for (; i < a.length; i++) {
  483. if (a[i] !== b[i]) {
  484. match = false;
  485. break;
  486. }
  487. }
  488. return match;
  489. }
  490. /*!
  491. * Extension to `iterableEqual` specifically
  492. * for Node.js Buffers.
  493. *
  494. * @param {Buffer} a
  495. * @param {Mixed} b
  496. * @return {Boolean} result
  497. */
  498. function bufferEqual(a, b) {
  499. if (!Buffer.isBuffer(b)) return false;
  500. return iterableEqual(a, b);
  501. }
  502. /*!
  503. * Block for `objectEqual` ensuring non-existing
  504. * values don't get in.
  505. *
  506. * @param {Mixed} object
  507. * @return {Boolean} result
  508. */
  509. function isValue(a) {
  510. return a !== null && a !== undefined;
  511. }
  512. /*!
  513. * Recursively check the equality of two objects.
  514. * Once basic sameness has been established it will
  515. * defer to `deepEqual` for each enumerable key
  516. * in the object.
  517. *
  518. * @param {Mixed} a
  519. * @param {Mixed} b
  520. * @return {Boolean} result
  521. */
  522. function objectEqual(a, b, m) {
  523. if (!isValue(a) || !isValue(b)) {
  524. return false;
  525. }
  526. if (a.prototype !== b.prototype) {
  527. return false;
  528. }
  529. var i;
  530. if (m) {
  531. for (i = 0; i < m.length; i++) {
  532. if ((m[i][0] === a && m[i][1] === b)
  533. || (m[i][0] === b && m[i][1] === a)) {
  534. return true;
  535. }
  536. }
  537. } else {
  538. m = [];
  539. }
  540. try {
  541. var ka = enumerable(a);
  542. var kb = enumerable(b);
  543. } catch (ex) {
  544. return false;
  545. }
  546. ka.sort();
  547. kb.sort();
  548. if (!iterableEqual(ka, kb)) {
  549. return false;
  550. }
  551. m.push([ a, b ]);
  552. var key;
  553. for (i = ka.length - 1; i >= 0; i--) {
  554. key = ka[i];
  555. if (!deepEqual(a[key], b[key], m)) {
  556. return false;
  557. }
  558. }
  559. return true;
  560. }
  561. });
  562. require.register("chai", function (exports, module) {
  563. module.exports = require('chai/lib/chai.js');
  564. });
  565. require.register("chai/lib/chai.js", function (exports, module) {
  566. /*!
  567. * chai
  568. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  569. * MIT Licensed
  570. */
  571. var used = []
  572. , exports = module.exports = {};
  573. /*!
  574. * Chai version
  575. */
  576. exports.version = '2.1.0';
  577. /*!
  578. * Assertion Error
  579. */
  580. exports.AssertionError = require('chaijs~assertion-error@1.0.0');
  581. /*!
  582. * Utils for plugins (not exported)
  583. */
  584. var util = require('chai/lib/chai/utils/index.js');
  585. /**
  586. * # .use(function)
  587. *
  588. * Provides a way to extend the internals of Chai
  589. *
  590. * @param {Function}
  591. * @returns {this} for chaining
  592. * @api public
  593. */
  594. exports.use = function (fn) {
  595. if (!~used.indexOf(fn)) {
  596. fn(this, util);
  597. used.push(fn);
  598. }
  599. return this;
  600. };
  601. /*!
  602. * Utility Functions
  603. */
  604. exports.util = util;
  605. /*!
  606. * Configuration
  607. */
  608. var config = require('chai/lib/chai/config.js');
  609. exports.config = config;
  610. /*!
  611. * Primary `Assertion` prototype
  612. */
  613. var assertion = require('chai/lib/chai/assertion.js');
  614. exports.use(assertion);
  615. /*!
  616. * Core Assertions
  617. */
  618. var core = require('chai/lib/chai/core/assertions.js');
  619. exports.use(core);
  620. /*!
  621. * Expect interface
  622. */
  623. var expect = require('chai/lib/chai/interface/expect.js');
  624. exports.use(expect);
  625. /*!
  626. * Should interface
  627. */
  628. var should = require('chai/lib/chai/interface/should.js');
  629. exports.use(should);
  630. /*!
  631. * Assert interface
  632. */
  633. var assert = require('chai/lib/chai/interface/assert.js');
  634. exports.use(assert);
  635. });
  636. require.register("chai/lib/chai/assertion.js", function (exports, module) {
  637. /*!
  638. * chai
  639. * http://chaijs.com
  640. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  641. * MIT Licensed
  642. */
  643. var config = require('chai/lib/chai/config.js');
  644. module.exports = function (_chai, util) {
  645. /*!
  646. * Module dependencies.
  647. */
  648. var AssertionError = _chai.AssertionError
  649. , flag = util.flag;
  650. /*!
  651. * Module export.
  652. */
  653. _chai.Assertion = Assertion;
  654. /*!
  655. * Assertion Constructor
  656. *
  657. * Creates object for chaining.
  658. *
  659. * @api private
  660. */
  661. function Assertion (obj, msg, stack) {
  662. flag(this, 'ssfi', stack || arguments.callee);
  663. flag(this, 'object', obj);
  664. flag(this, 'message', msg);
  665. }
  666. Object.defineProperty(Assertion, 'includeStack', {
  667. get: function() {
  668. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  669. return config.includeStack;
  670. },
  671. set: function(value) {
  672. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  673. config.includeStack = value;
  674. }
  675. });
  676. Object.defineProperty(Assertion, 'showDiff', {
  677. get: function() {
  678. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  679. return config.showDiff;
  680. },
  681. set: function(value) {
  682. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  683. config.showDiff = value;
  684. }
  685. });
  686. Assertion.addProperty = function (name, fn) {
  687. util.addProperty(this.prototype, name, fn);
  688. };
  689. Assertion.addMethod = function (name, fn) {
  690. util.addMethod(this.prototype, name, fn);
  691. };
  692. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  693. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  694. };
  695. Assertion.overwriteProperty = function (name, fn) {
  696. util.overwriteProperty(this.prototype, name, fn);
  697. };
  698. Assertion.overwriteMethod = function (name, fn) {
  699. util.overwriteMethod(this.prototype, name, fn);
  700. };
  701. Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
  702. util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
  703. };
  704. /*!
  705. * ### .assert(expression, message, negateMessage, expected, actual)
  706. *
  707. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  708. *
  709. * @name assert
  710. * @param {Philosophical} expression to be tested
  711. * @param {String or Function} message or function that returns message to display if fails
  712. * @param {String or Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
  713. * @param {Mixed} expected value (remember to check for negation)
  714. * @param {Mixed} actual (optional) will default to `this.obj`
  715. * @api private
  716. */
  717. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  718. var ok = util.test(this, arguments);
  719. if (true !== showDiff) showDiff = false;
  720. if (true !== config.showDiff) showDiff = false;
  721. if (!ok) {
  722. var msg = util.getMessage(this, arguments)
  723. , actual = util.getActual(this, arguments);
  724. throw new AssertionError(msg, {
  725. actual: actual
  726. , expected: expected
  727. , showDiff: showDiff
  728. }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
  729. }
  730. };
  731. /*!
  732. * ### ._obj
  733. *
  734. * Quick reference to stored `actual` value for plugin developers.
  735. *
  736. * @api private
  737. */
  738. Object.defineProperty(Assertion.prototype, '_obj',
  739. { get: function () {
  740. return flag(this, 'object');
  741. }
  742. , set: function (val) {
  743. flag(this, 'object', val);
  744. }
  745. });
  746. };
  747. });
  748. require.register("chai/lib/chai/config.js", function (exports, module) {
  749. module.exports = {
  750. /**
  751. * ### config.includeStack
  752. *
  753. * User configurable property, influences whether stack trace
  754. * is included in Assertion error message. Default of false
  755. * suppresses stack trace in the error message.
  756. *
  757. * chai.config.includeStack = true; // enable stack on error
  758. *
  759. * @param {Boolean}
  760. * @api public
  761. */
  762. includeStack: false,
  763. /**
  764. * ### config.showDiff
  765. *
  766. * User configurable property, influences whether or not
  767. * the `showDiff` flag should be included in the thrown
  768. * AssertionErrors. `false` will always be `false`; `true`
  769. * will be true when the assertion has requested a diff
  770. * be shown.
  771. *
  772. * @param {Boolean}
  773. * @api public
  774. */
  775. showDiff: true,
  776. /**
  777. * ### config.truncateThreshold
  778. *
  779. * User configurable property, sets length threshold for actual and
  780. * expected values in assertion errors. If this threshold is exceeded,
  781. * the value is truncated.
  782. *
  783. * Set it to zero if you want to disable truncating altogether.
  784. *
  785. * chai.config.truncateThreshold = 0; // disable truncating
  786. *
  787. * @param {Number}
  788. * @api public
  789. */
  790. truncateThreshold: 40
  791. };
  792. });
  793. require.register("chai/lib/chai/core/assertions.js", function (exports, module) {
  794. /*!
  795. * chai
  796. * http://chaijs.com
  797. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  798. * MIT Licensed
  799. */
  800. module.exports = function (chai, _) {
  801. var Assertion = chai.Assertion
  802. , toString = Object.prototype.toString
  803. , flag = _.flag;
  804. /**
  805. * ### Language Chains
  806. *
  807. * The following are provided as chainable getters to
  808. * improve the readability of your assertions. They
  809. * do not provide testing capabilities unless they
  810. * have been overwritten by a plugin.
  811. *
  812. * **Chains**
  813. *
  814. * - to
  815. * - be
  816. * - been
  817. * - is
  818. * - that
  819. * - which
  820. * - and
  821. * - has
  822. * - have
  823. * - with
  824. * - at
  825. * - of
  826. * - same
  827. *
  828. * @name language chains
  829. * @api public
  830. */
  831. [ 'to', 'be', 'been'
  832. , 'is', 'and', 'has', 'have'
  833. , 'with', 'that', 'which', 'at'
  834. , 'of', 'same' ].forEach(function (chain) {
  835. Assertion.addProperty(chain, function () {
  836. return this;
  837. });
  838. });
  839. /**
  840. * ### .not
  841. *
  842. * Negates any of assertions following in the chain.
  843. *
  844. * expect(foo).to.not.equal('bar');
  845. * expect(goodFn).to.not.throw(Error);
  846. * expect({ foo: 'baz' }).to.have.property('foo')
  847. * .and.not.equal('bar');
  848. *
  849. * @name not
  850. * @api public
  851. */
  852. Assertion.addProperty('not', function () {
  853. flag(this, 'negate', true);
  854. });
  855. /**
  856. * ### .deep
  857. *
  858. * Sets the `deep` flag, later used by the `equal` and
  859. * `property` assertions.
  860. *
  861. * expect(foo).to.deep.equal({ bar: 'baz' });
  862. * expect({ foo: { bar: { baz: 'quux' } } })
  863. * .to.have.deep.property('foo.bar.baz', 'quux');
  864. *
  865. * @name deep
  866. * @api public
  867. */
  868. Assertion.addProperty('deep', function () {
  869. flag(this, 'deep', true);
  870. });
  871. /**
  872. * ### .any
  873. *
  874. * Sets the `any` flag, (opposite of the `all` flag)
  875. * later used in the `keys` assertion.
  876. *
  877. * expect(foo).to.have.any.keys('bar', 'baz');
  878. *
  879. * @name any
  880. * @api public
  881. */
  882. Assertion.addProperty('any', function () {
  883. flag(this, 'any', true);
  884. flag(this, 'all', false)
  885. });
  886. /**
  887. * ### .all
  888. *
  889. * Sets the `all` flag (opposite of the `any` flag)
  890. * later used by the `keys` assertion.
  891. *
  892. * expect(foo).to.have.all.keys('bar', 'baz');
  893. *
  894. * @name all
  895. * @api public
  896. */
  897. Assertion.addProperty('all', function () {
  898. flag(this, 'all', true);
  899. flag(this, 'any', false);
  900. });
  901. /**
  902. * ### .a(type)
  903. *
  904. * The `a` and `an` assertions are aliases that can be
  905. * used either as language chains or to assert a value's
  906. * type.
  907. *
  908. * // typeof
  909. * expect('test').to.be.a('string');
  910. * expect({ foo: 'bar' }).to.be.an('object');
  911. * expect(null).to.be.a('null');
  912. * expect(undefined).to.be.an('undefined');
  913. *
  914. * // language chain
  915. * expect(foo).to.be.an.instanceof(Foo);
  916. *
  917. * @name a
  918. * @alias an
  919. * @param {String} type
  920. * @param {String} message _optional_
  921. * @api public
  922. */
  923. function an (type, msg) {
  924. if (msg) flag(this, 'message', msg);
  925. type = type.toLowerCase();
  926. var obj = flag(this, 'object')
  927. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  928. this.assert(
  929. type === _.type(obj)
  930. , 'expected #{this} to be ' + article + type
  931. , 'expected #{this} not to be ' + article + type
  932. );
  933. }
  934. Assertion.addChainableMethod('an', an);
  935. Assertion.addChainableMethod('a', an);
  936. /**
  937. * ### .include(value)
  938. *
  939. * The `include` and `contain` assertions can be used as either property
  940. * based language chains or as methods to assert the inclusion of an object
  941. * in an array or a substring in a string. When used as language chains,
  942. * they toggle the `contains` flag for the `keys` assertion.
  943. *
  944. * expect([1,2,3]).to.include(2);
  945. * expect('foobar').to.contain('foo');
  946. * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
  947. *
  948. * @name include
  949. * @alias contain
  950. * @alias includes
  951. * @alias contains
  952. * @param {Object|String|Number} obj
  953. * @param {String} message _optional_
  954. * @api public
  955. */
  956. function includeChainingBehavior () {
  957. flag(this, 'contains', true);
  958. }
  959. function include (val, msg) {
  960. if (msg) flag(this, 'message', msg);
  961. var obj = flag(this, 'object');
  962. var expected = false;
  963. if (_.type(obj) === 'array' && _.type(val) === 'object') {
  964. for (var i in obj) {
  965. if (_.eql(obj[i], val)) {
  966. expected = true;
  967. break;
  968. }
  969. }
  970. } else if (_.type(val) === 'object') {
  971. if (!flag(this, 'negate')) {
  972. for (var k in val) new Assertion(obj).property(k, val[k]);
  973. return;
  974. }
  975. var subset = {};
  976. for (var k in val) subset[k] = obj[k];
  977. expected = _.eql(subset, val);
  978. } else {
  979. expected = obj && ~obj.indexOf(val);
  980. }
  981. this.assert(
  982. expected
  983. , 'expected #{this} to include ' + _.inspect(val)
  984. , 'expected #{this} to not include ' + _.inspect(val));
  985. }
  986. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  987. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  988. Assertion.addChainableMethod('contains', include, includeChainingBehavior);
  989. Assertion.addChainableMethod('includes', include, includeChainingBehavior);
  990. /**
  991. * ### .ok
  992. *
  993. * Asserts that the target is truthy.
  994. *
  995. * expect('everthing').to.be.ok;
  996. * expect(1).to.be.ok;
  997. * expect(false).to.not.be.ok;
  998. * expect(undefined).to.not.be.ok;
  999. * expect(null).to.not.be.ok;
  1000. *
  1001. * @name ok
  1002. * @api public
  1003. */
  1004. Assertion.addProperty('ok', function () {
  1005. this.assert(
  1006. flag(this, 'object')
  1007. , 'expected #{this} to be truthy'
  1008. , 'expected #{this} to be falsy');
  1009. });
  1010. /**
  1011. * ### .true
  1012. *
  1013. * Asserts that the target is `true`.
  1014. *
  1015. * expect(true).to.be.true;
  1016. * expect(1).to.not.be.true;
  1017. *
  1018. * @name true
  1019. * @api public
  1020. */
  1021. Assertion.addProperty('true', function () {
  1022. this.assert(
  1023. true === flag(this, 'object')
  1024. , 'expected #{this} to be true'
  1025. , 'expected #{this} to be false'
  1026. , this.negate ? false : true
  1027. );
  1028. });
  1029. /**
  1030. * ### .false
  1031. *
  1032. * Asserts that the target is `false`.
  1033. *
  1034. * expect(false).to.be.false;
  1035. * expect(0).to.not.be.false;
  1036. *
  1037. * @name false
  1038. * @api public
  1039. */
  1040. Assertion.addProperty('false', function () {
  1041. this.assert(
  1042. false === flag(this, 'object')
  1043. , 'expected #{this} to be false'
  1044. , 'expected #{this} to be true'
  1045. , this.negate ? true : false
  1046. );
  1047. });
  1048. /**
  1049. * ### .null
  1050. *
  1051. * Asserts that the target is `null`.
  1052. *
  1053. * expect(null).to.be.null;
  1054. * expect(undefined).not.to.be.null;
  1055. *
  1056. * @name null
  1057. * @api public
  1058. */
  1059. Assertion.addProperty('null', function () {
  1060. this.assert(
  1061. null === flag(this, 'object')
  1062. , 'expected #{this} to be null'
  1063. , 'expected #{this} not to be null'
  1064. );
  1065. });
  1066. /**
  1067. * ### .undefined
  1068. *
  1069. * Asserts that the target is `undefined`.
  1070. *
  1071. * expect(undefined).to.be.undefined;
  1072. * expect(null).to.not.be.undefined;
  1073. *
  1074. * @name undefined
  1075. * @api public
  1076. */
  1077. Assertion.addProperty('undefined', function () {
  1078. this.assert(
  1079. undefined === flag(this, 'object')
  1080. , 'expected #{this} to be undefined'
  1081. , 'expected #{this} not to be undefined'
  1082. );
  1083. });
  1084. /**
  1085. * ### .exist
  1086. *
  1087. * Asserts that the target is neither `null` nor `undefined`.
  1088. *
  1089. * var foo = 'hi'
  1090. * , bar = null
  1091. * , baz;
  1092. *
  1093. * expect(foo).to.exist;
  1094. * expect(bar).to.not.exist;
  1095. * expect(baz).to.not.exist;
  1096. *
  1097. * @name exist
  1098. * @api public
  1099. */
  1100. Assertion.addProperty('exist', function () {
  1101. this.assert(
  1102. null != flag(this, 'object')
  1103. , 'expected #{this} to exist'
  1104. , 'expected #{this} to not exist'
  1105. );
  1106. });
  1107. /**
  1108. * ### .empty
  1109. *
  1110. * Asserts that the target's length is `0`. For arrays, it checks
  1111. * the `length` property. For objects, it gets the count of
  1112. * enumerable keys.
  1113. *
  1114. * expect([]).to.be.empty;
  1115. * expect('').to.be.empty;
  1116. * expect({}).to.be.empty;
  1117. *
  1118. * @name empty
  1119. * @api public
  1120. */
  1121. Assertion.addProperty('empty', function () {
  1122. var obj = flag(this, 'object')
  1123. , expected = obj;
  1124. if (Array.isArray(obj) || 'string' === typeof object) {
  1125. expected = obj.length;
  1126. } else if (typeof obj === 'object') {
  1127. expected = Object.keys(obj).length;
  1128. }
  1129. this.assert(
  1130. !expected
  1131. , 'expected #{this} to be empty'
  1132. , 'expected #{this} not to be empty'
  1133. );
  1134. });
  1135. /**
  1136. * ### .arguments
  1137. *
  1138. * Asserts that the target is an arguments object.
  1139. *
  1140. * function test () {
  1141. * expect(arguments).to.be.arguments;
  1142. * }
  1143. *
  1144. * @name arguments
  1145. * @alias Arguments
  1146. * @api public
  1147. */
  1148. function checkArguments () {
  1149. var obj = flag(this, 'object')
  1150. , type = Object.prototype.toString.call(obj);
  1151. this.assert(
  1152. '[object Arguments]' === type
  1153. , 'expected #{this} to be arguments but got ' + type
  1154. , 'expected #{this} to not be arguments'
  1155. );
  1156. }
  1157. Assertion.addProperty('arguments', checkArguments);
  1158. Assertion.addProperty('Arguments', checkArguments);
  1159. /**
  1160. * ### .equal(value)
  1161. *
  1162. * Asserts that the target is strictly equal (`===`) to `value`.
  1163. * Alternately, if the `deep` flag is set, asserts that
  1164. * the target is deeply equal to `value`.
  1165. *
  1166. * expect('hello').to.equal('hello');
  1167. * expect(42).to.equal(42);
  1168. * expect(1).to.not.equal(true);
  1169. * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
  1170. * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
  1171. *
  1172. * @name equal
  1173. * @alias equals
  1174. * @alias eq
  1175. * @alias deep.equal
  1176. * @param {Mixed} value
  1177. * @param {String} message _optional_
  1178. * @api public
  1179. */
  1180. function assertEqual (val, msg) {
  1181. if (msg) flag(this, 'message', msg);
  1182. var obj = flag(this, 'object');
  1183. if (flag(this, 'deep')) {
  1184. return this.eql(val);
  1185. } else {
  1186. this.assert(
  1187. val === obj
  1188. , 'expected #{this} to equal #{exp}'
  1189. , 'expected #{this} to not equal #{exp}'
  1190. , val
  1191. , this._obj
  1192. , true
  1193. );
  1194. }
  1195. }
  1196. Assertion.addMethod('equal', assertEqual);
  1197. Assertion.addMethod('equals', assertEqual);
  1198. Assertion.addMethod('eq', assertEqual);
  1199. /**
  1200. * ### .eql(value)
  1201. *
  1202. * Asserts that the target is deeply equal to `value`.
  1203. *
  1204. * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
  1205. * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
  1206. *
  1207. * @name eql
  1208. * @alias eqls
  1209. * @param {Mixed} value
  1210. * @param {String} message _optional_
  1211. * @api public
  1212. */
  1213. function assertEql(obj, msg) {
  1214. if (msg) flag(this, 'message', msg);
  1215. this.assert(
  1216. _.eql(obj, flag(this, 'object'))
  1217. , 'expected #{this} to deeply equal #{exp}'
  1218. , 'expected #{this} to not deeply equal #{exp}'
  1219. , obj
  1220. , this._obj
  1221. , true
  1222. );
  1223. }
  1224. Assertion.addMethod('eql', assertEql);
  1225. Assertion.addMethod('eqls', assertEql);
  1226. /**
  1227. * ### .above(value)
  1228. *
  1229. * Asserts that the target is greater than `value`.
  1230. *
  1231. * expect(10).to.be.above(5);
  1232. *
  1233. * Can also be used in conjunction with `length` to
  1234. * assert a minimum length. The benefit being a
  1235. * more informative error message than if the length
  1236. * was supplied directly.
  1237. *
  1238. * expect('foo').to.have.length.above(2);
  1239. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  1240. *
  1241. * @name above
  1242. * @alias gt
  1243. * @alias greaterThan
  1244. * @param {Number} value
  1245. * @param {String} message _optional_
  1246. * @api public
  1247. */
  1248. function assertAbove (n, msg) {
  1249. if (msg) flag(this, 'message', msg);
  1250. var obj = flag(this, 'object');
  1251. if (flag(this, 'doLength')) {
  1252. new Assertion(obj, msg).to.have.property('length');
  1253. var len = obj.length;
  1254. this.assert(
  1255. len > n
  1256. , 'expected #{this} to have a length above #{exp} but got #{act}'
  1257. , 'expected #{this} to not have a length above #{exp}'
  1258. , n
  1259. , len
  1260. );
  1261. } else {
  1262. this.assert(
  1263. obj > n
  1264. , 'expected #{this} to be above ' + n
  1265. , 'expected #{this} to be at most ' + n
  1266. );
  1267. }
  1268. }
  1269. Assertion.addMethod('above', assertAbove);
  1270. Assertion.addMethod('gt', assertAbove);
  1271. Assertion.addMethod('greaterThan', assertAbove);
  1272. /**
  1273. * ### .least(value)
  1274. *
  1275. * Asserts that the target is greater than or equal to `value`.
  1276. *
  1277. * expect(10).to.be.at.least(10);
  1278. *
  1279. * Can also be used in conjunction with `length` to
  1280. * assert a minimum length. The benefit being a
  1281. * more informative error message than if the length
  1282. * was supplied directly.
  1283. *
  1284. * expect('foo').to.have.length.of.at.least(2);
  1285. * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
  1286. *
  1287. * @name least
  1288. * @alias gte
  1289. * @param {Number} value
  1290. * @param {String} message _optional_
  1291. * @api public
  1292. */
  1293. function assertLeast (n, msg) {
  1294. if (msg) flag(this, 'message', msg);
  1295. var obj = flag(this, 'object');
  1296. if (flag(this, 'doLength')) {
  1297. new Assertion(obj, msg).to.have.property('length');
  1298. var len = obj.length;
  1299. this.assert(
  1300. len >= n
  1301. , 'expected #{this} to have a length at least #{exp} but got #{act}'
  1302. , 'expected #{this} to have a length below #{exp}'
  1303. , n
  1304. , len
  1305. );
  1306. } else {
  1307. this.assert(
  1308. obj >= n
  1309. , 'expected #{this} to be at least ' + n
  1310. , 'expected #{this} to be below ' + n
  1311. );
  1312. }
  1313. }
  1314. Assertion.addMethod('least', assertLeast);
  1315. Assertion.addMethod('gte', assertLeast);
  1316. /**
  1317. * ### .below(value)
  1318. *
  1319. * Asserts that the target is less than `value`.
  1320. *
  1321. * expect(5).to.be.below(10);
  1322. *
  1323. * Can also be used in conjunction with `length` to
  1324. * assert a maximum length. The benefit being a
  1325. * more informative error message than if the length
  1326. * was supplied directly.
  1327. *
  1328. * expect('foo').to.have.length.below(4);
  1329. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  1330. *
  1331. * @name below
  1332. * @alias lt
  1333. * @alias lessThan
  1334. * @param {Number} value
  1335. * @param {String} message _optional_
  1336. * @api public
  1337. */
  1338. function assertBelow (n, msg) {
  1339. if (msg) flag(this, 'message', msg);
  1340. var obj = flag(this, 'object');
  1341. if (flag(this, 'doLength')) {
  1342. new Assertion(obj, msg).to.have.property('length');
  1343. var len = obj.length;
  1344. this.assert(
  1345. len < n
  1346. , 'expected #{this} to have a length below #{exp} but got #{act}'
  1347. , 'expected #{this} to not have a length below #{exp}'
  1348. , n
  1349. , len
  1350. );
  1351. } else {
  1352. this.assert(
  1353. obj < n
  1354. , 'expected #{this} to be below ' + n
  1355. , 'expected #{this} to be at least ' + n
  1356. );
  1357. }
  1358. }
  1359. Assertion.addMethod('below', assertBelow);
  1360. Assertion.addMethod('lt', assertBelow);
  1361. Assertion.addMethod('lessThan', assertBelow);
  1362. /**
  1363. * ### .most(value)
  1364. *
  1365. * Asserts that the target is less than or equal to `value`.
  1366. *
  1367. * expect(5).to.be.at.most(5);
  1368. *
  1369. * Can also be used in conjunction with `length` to
  1370. * assert a maximum length. The benefit being a
  1371. * more informative error message than if the length
  1372. * was supplied directly.
  1373. *
  1374. * expect('foo').to.have.length.of.at.most(4);
  1375. * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
  1376. *
  1377. * @name most
  1378. * @alias lte
  1379. * @param {Number} value
  1380. * @param {String} message _optional_
  1381. * @api public
  1382. */
  1383. function assertMost (n, msg) {
  1384. if (msg) flag(this, 'message', msg);
  1385. var obj = flag(this, 'object');
  1386. if (flag(this, 'doLength')) {
  1387. new Assertion(obj, msg).to.have.property('length');
  1388. var len = obj.length;
  1389. this.assert(
  1390. len <= n
  1391. , 'expected #{this} to have a length at most #{exp} but got #{act}'
  1392. , 'expected #{this} to have a length above #{exp}'
  1393. , n
  1394. , len
  1395. );
  1396. } else {
  1397. this.assert(
  1398. obj <= n
  1399. , 'expected #{this} to be at most ' + n
  1400. , 'expected #{this} to be above ' + n
  1401. );
  1402. }
  1403. }
  1404. Assertion.addMethod('most', assertMost);
  1405. Assertion.addMethod('lte', assertMost);
  1406. /**
  1407. * ### .within(start, finish)
  1408. *
  1409. * Asserts that the target is within a range.
  1410. *
  1411. * expect(7).to.be.within(5,10);
  1412. *
  1413. * Can also be used in conjunction with `length` to
  1414. * assert a length range. The benefit being a
  1415. * more informative error message than if the length
  1416. * was supplied directly.
  1417. *
  1418. * expect('foo').to.have.length.within(2,4);
  1419. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  1420. *
  1421. * @name within
  1422. * @param {Number} start lowerbound inclusive
  1423. * @param {Number} finish upperbound inclusive
  1424. * @param {String} message _optional_
  1425. * @api public
  1426. */
  1427. Assertion.addMethod('within', function (start, finish, msg) {
  1428. if (msg) flag(this, 'message', msg);
  1429. var obj = flag(this, 'object')
  1430. , range = start + '..' + finish;
  1431. if (flag(this, 'doLength')) {
  1432. new Assertion(obj, msg).to.have.property('length');
  1433. var len = obj.length;
  1434. this.assert(
  1435. len >= start && len <= finish
  1436. , 'expected #{this} to have a length within ' + range
  1437. , 'expected #{this} to not have a length within ' + range
  1438. );
  1439. } else {
  1440. this.assert(
  1441. obj >= start && obj <= finish
  1442. , 'expected #{this} to be within ' + range
  1443. , 'expected #{this} to not be within ' + range
  1444. );
  1445. }
  1446. });
  1447. /**
  1448. * ### .instanceof(constructor)
  1449. *
  1450. * Asserts that the target is an instance of `constructor`.
  1451. *
  1452. * var Tea = function (name) { this.name = name; }
  1453. * , Chai = new Tea('chai');
  1454. *
  1455. * expect(Chai).to.be.an.instanceof(Tea);
  1456. * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
  1457. *
  1458. * @name instanceof
  1459. * @param {Constructor} constructor
  1460. * @param {String} message _optional_
  1461. * @alias instanceOf
  1462. * @api public
  1463. */
  1464. function assertInstanceOf (constructor, msg) {
  1465. if (msg) flag(this, 'message', msg);
  1466. var name = _.getName(constructor);
  1467. this.assert(
  1468. flag(this, 'object') instanceof constructor
  1469. , 'expected #{this} to be an instance of ' + name
  1470. , 'expected #{this} to not be an instance of ' + name
  1471. );
  1472. };
  1473. Assertion.addMethod('instanceof', assertInstanceOf);
  1474. Assertion.addMethod('instanceOf', assertInstanceOf);
  1475. /**
  1476. * ### .property(name, [value])
  1477. *
  1478. * Asserts that the target has a property `name`, optionally asserting that
  1479. * the value of that property is strictly equal to `value`.
  1480. * If the `deep` flag is set, you can use dot- and bracket-notation for deep
  1481. * references into objects and arrays.
  1482. *
  1483. * // simple referencing
  1484. * var obj = { foo: 'bar' };
  1485. * expect(obj).to.have.property('foo');
  1486. * expect(obj).to.have.property('foo', 'bar');
  1487. *
  1488. * // deep referencing
  1489. * var deepObj = {
  1490. * green: { tea: 'matcha' }
  1491. * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
  1492. * };
  1493. * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
  1494. * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
  1495. * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
  1496. *
  1497. * You can also use an array as the starting point of a `deep.property`
  1498. * assertion, or traverse nested arrays.
  1499. *
  1500. * var arr = [
  1501. * [ 'chai', 'matcha', 'konacha' ]
  1502. * , [ { tea: 'chai' }
  1503. * , { tea: 'matcha' }
  1504. * , { tea: 'konacha' } ]
  1505. * ];
  1506. *
  1507. * expect(arr).to.have.deep.property('[0][1]', 'matcha');
  1508. * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
  1509. *
  1510. * Furthermore, `property` changes the subject of the assertion
  1511. * to be the value of that property from the original object. This
  1512. * permits for further chainable assertions on that property.
  1513. *
  1514. * expect(obj).to.have.property('foo')
  1515. * .that.is.a('string');
  1516. * expect(deepObj).to.have.property('green')
  1517. * .that.is.an('object')
  1518. * .that.deep.equals({ tea: 'matcha' });
  1519. * expect(deepObj).to.have.property('teas')
  1520. * .that.is.an('array')
  1521. * .with.deep.property('[2]')
  1522. * .that.deep.equals({ tea: 'konacha' });
  1523. *
  1524. * @name property
  1525. * @alias deep.property
  1526. * @param {String} name
  1527. * @param {Mixed} value (optional)
  1528. * @param {String} message _optional_
  1529. * @returns value of property for chaining
  1530. * @api public
  1531. */
  1532. Assertion.addMethod('property', function (name, val, msg) {
  1533. if (msg) flag(this, 'message', msg);
  1534. var isDeep = !!flag(this, 'deep')
  1535. , descriptor = isDeep ? 'deep property ' : 'property '
  1536. , negate = flag(this, 'negate')
  1537. , obj = flag(this, 'object')
  1538. , pathInfo = isDeep ? _.getPathInfo(name, obj) : null
  1539. , hasProperty = isDeep
  1540. ? pathInfo.exists
  1541. : _.hasProperty(name, obj)
  1542. , value = isDeep
  1543. ? pathInfo.value
  1544. : obj[name];
  1545. if (negate && undefined !== val) {
  1546. if (undefined === value) {
  1547. msg = (msg != null) ? msg + ': ' : '';
  1548. throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
  1549. }
  1550. } else {
  1551. this.assert(
  1552. hasProperty
  1553. , 'expected #{this} to have a ' + descriptor + _.inspect(name)
  1554. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  1555. }
  1556. if (undefined !== val) {
  1557. this.assert(
  1558. val === value
  1559. , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  1560. , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
  1561. , val
  1562. , value
  1563. );
  1564. }
  1565. flag(this, 'object', value);
  1566. });
  1567. /**
  1568. * ### .ownProperty(name)
  1569. *
  1570. * Asserts that the target has an own property `name`.
  1571. *
  1572. * expect('test').to.have.ownProperty('length');
  1573. *
  1574. * @name ownProperty
  1575. * @alias haveOwnProperty
  1576. * @param {String} name
  1577. * @param {String} message _optional_
  1578. * @api public
  1579. */
  1580. function assertOwnProperty (name, msg) {
  1581. if (msg) flag(this, 'message', msg);
  1582. var obj = flag(this, 'object');
  1583. this.assert(
  1584. obj.hasOwnProperty(name)
  1585. , 'expected #{this} to have own property ' + _.inspect(name)
  1586. , 'expected #{this} to not have own property ' + _.inspect(name)
  1587. );
  1588. }
  1589. Assertion.addMethod('ownProperty', assertOwnProperty);
  1590. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  1591. /**
  1592. * ### .length(value)
  1593. *
  1594. * Asserts that the target's `length` property has
  1595. * the expected value.
  1596. *
  1597. * expect([ 1, 2, 3]).to.have.length(3);
  1598. * expect('foobar').to.have.length(6);
  1599. *
  1600. * Can also be used as a chain precursor to a value
  1601. * comparison for the length property.
  1602. *
  1603. * expect('foo').to.have.length.above(2);
  1604. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  1605. * expect('foo').to.have.length.below(4);
  1606. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  1607. * expect('foo').to.have.length.within(2,4);
  1608. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  1609. *
  1610. * @name length
  1611. * @alias lengthOf
  1612. * @param {Number} length
  1613. * @param {String} message _optional_
  1614. * @api public
  1615. */
  1616. function assertLengthChain () {
  1617. flag(this, 'doLength', true);
  1618. }
  1619. function assertLength (n, msg) {
  1620. if (msg) flag(this, 'message', msg);
  1621. var obj = flag(this, 'object');
  1622. new Assertion(obj, msg).to.have.property('length');
  1623. var len = obj.length;
  1624. this.assert(
  1625. len == n
  1626. , 'expected #{this} to have a length of #{exp} but got #{act}'
  1627. , 'expected #{this} to not have a length of #{act}'
  1628. , n
  1629. , len
  1630. );
  1631. }
  1632. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  1633. Assertion.addMethod('lengthOf', assertLength);
  1634. /**
  1635. * ### .match(regexp)
  1636. *
  1637. * Asserts that the target matches a regular expression.
  1638. *
  1639. * expect('foobar').to.match(/^foo/);
  1640. *
  1641. * @name match
  1642. * @param {RegExp} RegularExpression
  1643. * @param {String} message _optional_
  1644. * @api public
  1645. */
  1646. Assertion.addMethod('match', function (re, msg) {
  1647. if (msg) flag(this, 'message', msg);
  1648. var obj = flag(this, 'object');
  1649. this.assert(
  1650. re.exec(obj)
  1651. , 'expected #{this} to match ' + re
  1652. , 'expected #{this} not to match ' + re
  1653. );
  1654. });
  1655. /**
  1656. * ### .string(string)
  1657. *
  1658. * Asserts that the string target contains another string.
  1659. *
  1660. * expect('foobar').to.have.string('bar');
  1661. *
  1662. * @name string
  1663. * @param {String} string
  1664. * @param {String} message _optional_
  1665. * @api public
  1666. */
  1667. Assertion.addMethod('string', function (str, msg) {
  1668. if (msg) flag(this, 'message', msg);
  1669. var obj = flag(this, 'object');
  1670. new Assertion(obj, msg).is.a('string');
  1671. this.assert(
  1672. ~obj.indexOf(str)
  1673. , 'expected #{this} to contain ' + _.inspect(str)
  1674. , 'expected #{this} to not contain ' + _.inspect(str)
  1675. );
  1676. });
  1677. /**
  1678. * ### .keys(key1, [key2], [...])
  1679. *
  1680. * Asserts that the target contains any or all of the passed-in keys.
  1681. * Use in combination with `any`, `all`, `contains`, or `have` will affect
  1682. * what will pass.
  1683. *
  1684. * When used in conjunction with `any`, at least one key that is passed
  1685. * in must exist in the target object. This is regardless whether or not
  1686. * the `have` or `contain` qualifiers are used. Note, either `any` or `all`
  1687. * should be used in the assertion. If neither are used, the assertion is
  1688. * defaulted to `all`.
  1689. *
  1690. * When both `all` and `contain` are used, the target object must have at
  1691. * least all of the passed-in keys but may have more keys not listed.
  1692. *
  1693. * When both `all` and `have` are used, the target object must both contain
  1694. * all of the passed-in keys AND the number of keys in the target object must
  1695. * match the number of keys passed in (in other words, a target object must
  1696. * have all and only all of the passed-in keys).
  1697. *
  1698. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
  1699. * expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
  1700. * expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
  1701. * expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
  1702. * expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
  1703. * expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
  1704. * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo', 7});
  1705. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
  1706. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys([{'bar': 6}}]);
  1707. *
  1708. *
  1709. * @name keys
  1710. * @alias key
  1711. * @param {String...|Array|Object} keys
  1712. * @api public
  1713. */
  1714. function assertKeys (keys) {
  1715. var obj = flag(this, 'object')
  1716. , str
  1717. , ok = true
  1718. , mixedArgsMsg = 'keys must be given single argument of Array|Object|String, or multiple String arguments';
  1719. switch (_.type(keys)) {
  1720. case "array":
  1721. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  1722. break;
  1723. case "object":
  1724. if (arguments.length > 1) throw (new Error(mixedArgsMsg));
  1725. keys = Object.keys(keys);
  1726. break;
  1727. default:
  1728. keys = Array.prototype.slice.call(arguments);
  1729. }
  1730. if (!keys.length) throw new Error('keys required');
  1731. var actual = Object.keys(obj)
  1732. , expected = keys
  1733. , len = keys.length
  1734. , any = flag(this, 'any')
  1735. , all = flag(this, 'all');
  1736. if (!any && !all) {
  1737. all = true;
  1738. }
  1739. // Has any
  1740. if (any) {
  1741. var intersection = expected.filter(function(key) {
  1742. return ~actual.indexOf(key);
  1743. });
  1744. ok = intersection.length > 0;
  1745. }
  1746. // Has all
  1747. if (all) {
  1748. ok = keys.every(function(key){
  1749. return ~actual.indexOf(key);
  1750. });
  1751. if (!flag(this, 'negate') && !flag(this, 'contains')) {
  1752. ok = ok && keys.length == actual.length;
  1753. }
  1754. }
  1755. // Key string
  1756. if (len > 1) {
  1757. keys = keys.map(function(key){
  1758. return _.inspect(key);
  1759. });
  1760. var last = keys.pop();
  1761. if (all) {
  1762. str = keys.join(', ') + ', and ' + last;
  1763. }
  1764. if (any) {
  1765. str = keys.join(', ') + ', or ' + last;
  1766. }
  1767. } else {
  1768. str = _.inspect(keys[0]);
  1769. }
  1770. // Form
  1771. str = (len > 1 ? 'keys ' : 'key ') + str;
  1772. // Have / include
  1773. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  1774. // Assertion
  1775. this.assert(
  1776. ok
  1777. , 'expected #{this} to ' + str
  1778. , 'expected #{this} to not ' + str
  1779. , expected.slice(0).sort()
  1780. , actual.sort()
  1781. , true
  1782. );
  1783. }
  1784. Assertion.addMethod('keys', assertKeys);
  1785. Assertion.addMethod('key', assertKeys);
  1786. /**
  1787. * ### .throw(constructor)
  1788. *
  1789. * Asserts that the function target will throw a specific error, or specific type of error
  1790. * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
  1791. * for the error's message.
  1792. *
  1793. * var err = new ReferenceError('This is a bad function.');
  1794. * var fn = function () { throw err; }
  1795. * expect(fn).to.throw(ReferenceError);
  1796. * expect(fn).to.throw(Error);
  1797. * expect(fn).to.throw(/bad function/);
  1798. * expect(fn).to.not.throw('good function');
  1799. * expect(fn).to.throw(ReferenceError, /bad function/);
  1800. * expect(fn).to.throw(err);
  1801. * expect(fn).to.not.throw(new RangeError('Out of range.'));
  1802. *
  1803. * Please note that when a throw expectation is negated, it will check each
  1804. * parameter independently, starting with error constructor type. The appropriate way
  1805. * to check for the existence of a type of error but for a message that does not match
  1806. * is to use `and`.
  1807. *
  1808. * expect(fn).to.throw(ReferenceError)
  1809. * .and.not.throw(/good function/);
  1810. *
  1811. * @name throw
  1812. * @alias throws
  1813. * @alias Throw
  1814. * @param {ErrorConstructor} constructor
  1815. * @param {String|RegExp} expected error message
  1816. * @param {String} message _optional_
  1817. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  1818. * @returns error for chaining (null if no error)
  1819. * @api public
  1820. */
  1821. function assertThrows (constructor, errMsg, msg) {
  1822. if (msg) flag(this, 'message', msg);
  1823. var obj = flag(this, 'object');
  1824. new Assertion(obj, msg).is.a('function');
  1825. var thrown = false
  1826. , desiredError = null
  1827. , name = null
  1828. , thrownError = null;
  1829. if (arguments.length === 0) {
  1830. errMsg = null;
  1831. constructor = null;
  1832. } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
  1833. errMsg = constructor;
  1834. constructor = null;
  1835. } else if (constructor && constructor instanceof Error) {
  1836. desiredError = constructor;
  1837. constructor = null;
  1838. errMsg = null;
  1839. } else if (typeof constructor === 'function') {
  1840. name = constructor.prototype.name || constructor.name;
  1841. if (name === 'Error' && constructor !== Error) {
  1842. name = (new constructor()).name;
  1843. }
  1844. } else {
  1845. constructor = null;
  1846. }
  1847. try {
  1848. obj();
  1849. } catch (err) {
  1850. // first, check desired error
  1851. if (desiredError) {
  1852. this.assert(
  1853. err === desiredError
  1854. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1855. , 'expected #{this} to not throw #{exp}'
  1856. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  1857. , (err instanceof Error ? err.toString() : err)
  1858. );
  1859. flag(this, 'object', err);
  1860. return this;
  1861. }
  1862. // next, check constructor
  1863. if (constructor) {
  1864. this.assert(
  1865. err instanceof constructor
  1866. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  1867. , 'expected #{this} to not throw #{exp} but #{act} was thrown'
  1868. , name
  1869. , (err instanceof Error ? err.toString() : err)
  1870. );
  1871. if (!errMsg) {
  1872. flag(this, 'object', err);
  1873. return this;
  1874. }
  1875. }
  1876. // next, check message
  1877. var message = 'object' === _.type(err) && "message" in err
  1878. ? err.message
  1879. : '' + err;
  1880. if ((message != null) && errMsg && errMsg instanceof RegExp) {
  1881. this.assert(
  1882. errMsg.exec(message)
  1883. , 'expected #{this} to throw error matching #{exp} but got #{act}'
  1884. , 'expected #{this} to throw error not matching #{exp}'
  1885. , errMsg
  1886. , message
  1887. );
  1888. flag(this, 'object', err);
  1889. return this;
  1890. } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
  1891. this.assert(
  1892. ~message.indexOf(errMsg)
  1893. , 'expected #{this} to throw error including #{exp} but got #{act}'
  1894. , 'expected #{this} to throw error not including #{act}'
  1895. , errMsg
  1896. , message
  1897. );
  1898. flag(this, 'object', err);
  1899. return this;
  1900. } else {
  1901. thrown = true;
  1902. thrownError = err;
  1903. }
  1904. }
  1905. var actuallyGot = ''
  1906. , expectedThrown = name !== null
  1907. ? name
  1908. : desiredError
  1909. ? '#{exp}' //_.inspect(desiredError)
  1910. : 'an error';
  1911. if (thrown) {
  1912. actuallyGot = ' but #{act} was thrown'
  1913. }
  1914. this.assert(
  1915. thrown === true
  1916. , 'expected #{this} to throw ' + expectedThrown + actuallyGot
  1917. , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
  1918. , (desiredError instanceof Error ? desiredError.toString() : desiredError)
  1919. , (thrownError instanceof Error ? thrownError.toString() : thrownError)
  1920. );
  1921. flag(this, 'object', thrownError);
  1922. };
  1923. Assertion.addMethod('throw', assertThrows);
  1924. Assertion.addMethod('throws', assertThrows);
  1925. Assertion.addMethod('Throw', assertThrows);
  1926. /**
  1927. * ### .respondTo(method)
  1928. *
  1929. * Asserts that the object or class target will respond to a method.
  1930. *
  1931. * Klass.prototype.bar = function(){};
  1932. * expect(Klass).to.respondTo('bar');
  1933. * expect(obj).to.respondTo('bar');
  1934. *
  1935. * To check if a constructor will respond to a static function,
  1936. * set the `itself` flag.
  1937. *
  1938. * Klass.baz = function(){};
  1939. * expect(Klass).itself.to.respondTo('baz');
  1940. *
  1941. * @name respondTo
  1942. * @param {String} method
  1943. * @param {String} message _optional_
  1944. * @api public
  1945. */
  1946. Assertion.addMethod('respondTo', function (method, msg) {
  1947. if (msg) flag(this, 'message', msg);
  1948. var obj = flag(this, 'object')
  1949. , itself = flag(this, 'itself')
  1950. , context = ('function' === _.type(obj) && !itself)
  1951. ? obj.prototype[method]
  1952. : obj[method];
  1953. this.assert(
  1954. 'function' === typeof context
  1955. , 'expected #{this} to respond to ' + _.inspect(method)
  1956. , 'expected #{this} to not respond to ' + _.inspect(method)
  1957. );
  1958. });
  1959. /**
  1960. * ### .itself
  1961. *
  1962. * Sets the `itself` flag, later used by the `respondTo` assertion.
  1963. *
  1964. * function Foo() {}
  1965. * Foo.bar = function() {}
  1966. * Foo.prototype.baz = function() {}
  1967. *
  1968. * expect(Foo).itself.to.respondTo('bar');
  1969. * expect(Foo).itself.not.to.respondTo('baz');
  1970. *
  1971. * @name itself
  1972. * @api public
  1973. */
  1974. Assertion.addProperty('itself', function () {
  1975. flag(this, 'itself', true);
  1976. });
  1977. /**
  1978. * ### .satisfy(method)
  1979. *
  1980. * Asserts that the target passes a given truth test.
  1981. *
  1982. * expect(1).to.satisfy(function(num) { return num > 0; });
  1983. *
  1984. * @name satisfy
  1985. * @param {Function} matcher
  1986. * @param {String} message _optional_
  1987. * @api public
  1988. */
  1989. Assertion.addMethod('satisfy', function (matcher, msg) {
  1990. if (msg) flag(this, 'message', msg);
  1991. var obj = flag(this, 'object');
  1992. var result = matcher(obj);
  1993. this.assert(
  1994. result
  1995. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  1996. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  1997. , this.negate ? false : true
  1998. , result
  1999. );
  2000. });
  2001. /**
  2002. * ### .closeTo(expected, delta)
  2003. *
  2004. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  2005. *
  2006. * expect(1.5).to.be.closeTo(1, 0.5);
  2007. *
  2008. * @name closeTo
  2009. * @param {Number} expected
  2010. * @param {Number} delta
  2011. * @param {String} message _optional_
  2012. * @api public
  2013. */
  2014. Assertion.addMethod('closeTo', function (expected, delta, msg) {
  2015. if (msg) flag(this, 'message', msg);
  2016. var obj = flag(this, 'object');
  2017. new Assertion(obj, msg).is.a('number');
  2018. if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
  2019. throw new Error('the arguments to closeTo must be numbers');
  2020. }
  2021. this.assert(
  2022. Math.abs(obj - expected) <= delta
  2023. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  2024. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  2025. );
  2026. });
  2027. function isSubsetOf(subset, superset, cmp) {
  2028. return subset.every(function(elem) {
  2029. if (!cmp) return superset.indexOf(elem) !== -1;
  2030. return superset.some(function(elem2) {
  2031. return cmp(elem, elem2);
  2032. });
  2033. })
  2034. }
  2035. /**
  2036. * ### .members(set)
  2037. *
  2038. * Asserts that the target is a superset of `set`,
  2039. * or that the target and `set` have the same strictly-equal (===) members.
  2040. * Alternately, if the `deep` flag is set, set members are compared for deep
  2041. * equality.
  2042. *
  2043. * expect([1, 2, 3]).to.include.members([3, 2]);
  2044. * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
  2045. *
  2046. * expect([4, 2]).to.have.members([2, 4]);
  2047. * expect([5, 2]).to.not.have.members([5, 2, 1]);
  2048. *
  2049. * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
  2050. *
  2051. * @name members
  2052. * @param {Array} set
  2053. * @param {String} message _optional_
  2054. * @api public
  2055. */
  2056. Assertion.addMethod('members', function (subset, msg) {
  2057. if (msg) flag(this, 'message', msg);
  2058. var obj = flag(this, 'object');
  2059. new Assertion(obj).to.be.an('array');
  2060. new Assertion(subset).to.be.an('array');
  2061. var cmp = flag(this, 'deep') ? _.eql : undefined;
  2062. if (flag(this, 'contains')) {
  2063. return this.assert(
  2064. isSubsetOf(subset, obj, cmp)
  2065. , 'expected #{this} to be a superset of #{act}'
  2066. , 'expected #{this} to not be a superset of #{act}'
  2067. , obj
  2068. , subset
  2069. );
  2070. }
  2071. this.assert(
  2072. isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
  2073. , 'expected #{this} to have the same members as #{act}'
  2074. , 'expected #{this} to not have the same members as #{act}'
  2075. , obj
  2076. , subset
  2077. );
  2078. });
  2079. /**
  2080. * ### .change(function)
  2081. *
  2082. * Asserts that a function changes an object property
  2083. *
  2084. * var obj = { val: 10 };
  2085. * var fn = function() { obj.val += 3 };
  2086. * var noChangeFn = function() { return 'foo' + 'bar'; }
  2087. * expect(fn).to.change(obj, 'val');
  2088. * expect(noChangFn).to.not.change(obj, 'val')
  2089. *
  2090. * @name change
  2091. * @alias changes
  2092. * @alias Change
  2093. * @param {String} object
  2094. * @param {String} property name
  2095. * @param {String} message _optional_
  2096. * @api public
  2097. */
  2098. function assertChanges (object, prop, msg) {
  2099. if (msg) flag(this, 'message', msg);
  2100. var fn = flag(this, 'object');
  2101. new Assertion(object, msg).to.have.property(prop);
  2102. new Assertion(fn).is.a('function');
  2103. var initial = object[prop];
  2104. fn();
  2105. this.assert(
  2106. initial !== object[prop]
  2107. , 'expected .' + prop + ' to change'
  2108. , 'expected .' + prop + ' to not change'
  2109. );
  2110. }
  2111. Assertion.addChainableMethod('change', assertChanges);
  2112. Assertion.addChainableMethod('changes', assertChanges);
  2113. /**
  2114. * ### .increase(function)
  2115. *
  2116. * Asserts that a function increases an object property
  2117. *
  2118. * var obj = { val: 10 };
  2119. * var fn = function() { obj.val = 15 };
  2120. * expect(fn).to.increase(obj, 'val');
  2121. *
  2122. * @name increase
  2123. * @alias increases
  2124. * @alias Increase
  2125. * @param {String} object
  2126. * @param {String} property name
  2127. * @param {String} message _optional_
  2128. * @api public
  2129. */
  2130. function assertIncreases (object, prop, msg) {
  2131. if (msg) flag(this, 'message', msg);
  2132. var fn = flag(this, 'object');
  2133. new Assertion(object, msg).to.have.property(prop);
  2134. new Assertion(fn).is.a('function');
  2135. var initial = object[prop];
  2136. fn();
  2137. this.assert(
  2138. object[prop] - initial > 0
  2139. , 'expected .' + prop + ' to increase'
  2140. , 'expected .' + prop + ' to not increase'
  2141. );
  2142. }
  2143. Assertion.addChainableMethod('increase', assertIncreases);
  2144. Assertion.addChainableMethod('increases', assertIncreases);
  2145. /**
  2146. * ### .decrease(function)
  2147. *
  2148. * Asserts that a function decreases an object property
  2149. *
  2150. * var obj = { val: 10 };
  2151. * var fn = function() { obj.val = 5 };
  2152. * expect(fn).to.decrease(obj, 'val');
  2153. *
  2154. * @name decrease
  2155. * @alias decreases
  2156. * @alias Decrease
  2157. * @param {String} object
  2158. * @param {String} property name
  2159. * @param {String} message _optional_
  2160. * @api public
  2161. */
  2162. function assertDecreases (object, prop, msg) {
  2163. if (msg) flag(this, 'message', msg);
  2164. var fn = flag(this, 'object');
  2165. new Assertion(object, msg).to.have.property(prop);
  2166. new Assertion(fn).is.a('function');
  2167. var initial = object[prop];
  2168. fn();
  2169. this.assert(
  2170. object[prop] - initial < 0
  2171. , 'expected .' + prop + ' to decrease'
  2172. , 'expected .' + prop + ' to not decrease'
  2173. );
  2174. }
  2175. Assertion.addChainableMethod('decrease', assertDecreases);
  2176. Assertion.addChainableMethod('decreases', assertDecreases);
  2177. };
  2178. });
  2179. require.register("chai/lib/chai/interface/assert.js", function (exports, module) {
  2180. /*!
  2181. * chai
  2182. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  2183. * MIT Licensed
  2184. */
  2185. module.exports = function (chai, util) {
  2186. /*!
  2187. * Chai dependencies.
  2188. */
  2189. var Assertion = chai.Assertion
  2190. , flag = util.flag;
  2191. /*!
  2192. * Module export.
  2193. */
  2194. /**
  2195. * ### assert(expression, message)
  2196. *
  2197. * Write your own test expressions.
  2198. *
  2199. * assert('foo' !== 'bar', 'foo is not bar');
  2200. * assert(Array.isArray([]), 'empty arrays are arrays');
  2201. *
  2202. * @param {Mixed} expression to test for truthiness
  2203. * @param {String} message to display on error
  2204. * @name assert
  2205. * @api public
  2206. */
  2207. var assert = chai.assert = function (express, errmsg) {
  2208. var test = new Assertion(null, null, chai.assert);
  2209. test.assert(
  2210. express
  2211. , errmsg
  2212. , '[ negation message unavailable ]'
  2213. );
  2214. };
  2215. /**
  2216. * ### .fail(actual, expected, [message], [operator])
  2217. *
  2218. * Throw a failure. Node.js `assert` module-compatible.
  2219. *
  2220. * @name fail
  2221. * @param {Mixed} actual
  2222. * @param {Mixed} expected
  2223. * @param {String} message
  2224. * @param {String} operator
  2225. * @api public
  2226. */
  2227. assert.fail = function (actual, expected, message, operator) {
  2228. message = message || 'assert.fail()';
  2229. throw new chai.AssertionError(message, {
  2230. actual: actual
  2231. , expected: expected
  2232. , operator: operator
  2233. }, assert.fail);
  2234. };
  2235. /**
  2236. * ### .ok(object, [message])
  2237. *
  2238. * Asserts that `object` is truthy.
  2239. *
  2240. * assert.ok('everything', 'everything is ok');
  2241. * assert.ok(false, 'this will fail');
  2242. *
  2243. * @name ok
  2244. * @param {Mixed} object to test
  2245. * @param {String} message
  2246. * @api public
  2247. */
  2248. assert.ok = function (val, msg) {
  2249. new Assertion(val, msg).is.ok;
  2250. };
  2251. /**
  2252. * ### .notOk(object, [message])
  2253. *
  2254. * Asserts that `object` is falsy.
  2255. *
  2256. * assert.notOk('everything', 'this will fail');
  2257. * assert.notOk(false, 'this will pass');
  2258. *
  2259. * @name notOk
  2260. * @param {Mixed} object to test
  2261. * @param {String} message
  2262. * @api public
  2263. */
  2264. assert.notOk = function (val, msg) {
  2265. new Assertion(val, msg).is.not.ok;
  2266. };
  2267. /**
  2268. * ### .equal(actual, expected, [message])
  2269. *
  2270. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  2271. *
  2272. * assert.equal(3, '3', '== coerces values to strings');
  2273. *
  2274. * @name equal
  2275. * @param {Mixed} actual
  2276. * @param {Mixed} expected
  2277. * @param {String} message
  2278. * @api public
  2279. */
  2280. assert.equal = function (act, exp, msg) {
  2281. var test = new Assertion(act, msg, assert.equal);
  2282. test.assert(
  2283. exp == flag(test, 'object')
  2284. , 'expected #{this} to equal #{exp}'
  2285. , 'expected #{this} to not equal #{act}'
  2286. , exp
  2287. , act
  2288. );
  2289. };
  2290. /**
  2291. * ### .notEqual(actual, expected, [message])
  2292. *
  2293. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  2294. *
  2295. * assert.notEqual(3, 4, 'these numbers are not equal');
  2296. *
  2297. * @name notEqual
  2298. * @param {Mixed} actual
  2299. * @param {Mixed} expected
  2300. * @param {String} message
  2301. * @api public
  2302. */
  2303. assert.notEqual = function (act, exp, msg) {
  2304. var test = new Assertion(act, msg, assert.notEqual);
  2305. test.assert(
  2306. exp != flag(test, 'object')
  2307. , 'expected #{this} to not equal #{exp}'
  2308. , 'expected #{this} to equal #{act}'
  2309. , exp
  2310. , act
  2311. );
  2312. };
  2313. /**
  2314. * ### .strictEqual(actual, expected, [message])
  2315. *
  2316. * Asserts strict equality (`===`) of `actual` and `expected`.
  2317. *
  2318. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  2319. *
  2320. * @name strictEqual
  2321. * @param {Mixed} actual
  2322. * @param {Mixed} expected
  2323. * @param {String} message
  2324. * @api public
  2325. */
  2326. assert.strictEqual = function (act, exp, msg) {
  2327. new Assertion(act, msg).to.equal(exp);
  2328. };
  2329. /**
  2330. * ### .notStrictEqual(actual, expected, [message])
  2331. *
  2332. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  2333. *
  2334. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  2335. *
  2336. * @name notStrictEqual
  2337. * @param {Mixed} actual
  2338. * @param {Mixed} expected
  2339. * @param {String} message
  2340. * @api public
  2341. */
  2342. assert.notStrictEqual = function (act, exp, msg) {
  2343. new Assertion(act, msg).to.not.equal(exp);
  2344. };
  2345. /**
  2346. * ### .deepEqual(actual, expected, [message])
  2347. *
  2348. * Asserts that `actual` is deeply equal to `expected`.
  2349. *
  2350. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  2351. *
  2352. * @name deepEqual
  2353. * @param {Mixed} actual
  2354. * @param {Mixed} expected
  2355. * @param {String} message
  2356. * @api public
  2357. */
  2358. assert.deepEqual = function (act, exp, msg) {
  2359. new Assertion(act, msg).to.eql(exp);
  2360. };
  2361. /**
  2362. * ### .notDeepEqual(actual, expected, [message])
  2363. *
  2364. * Assert that `actual` is not deeply equal to `expected`.
  2365. *
  2366. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  2367. *
  2368. * @name notDeepEqual
  2369. * @param {Mixed} actual
  2370. * @param {Mixed} expected
  2371. * @param {String} message
  2372. * @api public
  2373. */
  2374. assert.notDeepEqual = function (act, exp, msg) {
  2375. new Assertion(act, msg).to.not.eql(exp);
  2376. };
  2377. /**
  2378. * ### .isTrue(value, [message])
  2379. *
  2380. * Asserts that `value` is true.
  2381. *
  2382. * var teaServed = true;
  2383. * assert.isTrue(teaServed, 'the tea has been served');
  2384. *
  2385. * @name isTrue
  2386. * @param {Mixed} value
  2387. * @param {String} message
  2388. * @api public
  2389. */
  2390. assert.isAbove = function (val, abv, msg) {
  2391. new Assertion(val, msg).to.be.above(abv);
  2392. };
  2393. /**
  2394. * ### .isAbove(valueToCheck, valueToBeAbove, [message])
  2395. *
  2396. * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`
  2397. *
  2398. * assert.isAbove(5, 2, '5 is strictly greater than 2');
  2399. *
  2400. * @name isAbove
  2401. * @param {Mixed} valueToCheck
  2402. * @param {Mixed} valueToBeAbove
  2403. * @param {String} message
  2404. * @api public
  2405. */
  2406. assert.isBelow = function (val, blw, msg) {
  2407. new Assertion(val, msg).to.be.below(blw);
  2408. };
  2409. /**
  2410. * ### .isBelow(valueToCheck, valueToBeBelow, [message])
  2411. *
  2412. * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`
  2413. *
  2414. * assert.isBelow(3, 6, '3 is strictly less than 6');
  2415. *
  2416. * @name isBelow
  2417. * @param {Mixed} valueToCheck
  2418. * @param {Mixed} valueToBeBelow
  2419. * @param {String} message
  2420. * @api public
  2421. */
  2422. assert.isTrue = function (val, msg) {
  2423. new Assertion(val, msg).is['true'];
  2424. };
  2425. /**
  2426. * ### .isFalse(value, [message])
  2427. *
  2428. * Asserts that `value` is false.
  2429. *
  2430. * var teaServed = false;
  2431. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  2432. *
  2433. * @name isFalse
  2434. * @param {Mixed} value
  2435. * @param {String} message
  2436. * @api public
  2437. */
  2438. assert.isFalse = function (val, msg) {
  2439. new Assertion(val, msg).is['false'];
  2440. };
  2441. /**
  2442. * ### .isNull(value, [message])
  2443. *
  2444. * Asserts that `value` is null.
  2445. *
  2446. * assert.isNull(err, 'there was no error');
  2447. *
  2448. * @name isNull
  2449. * @param {Mixed} value
  2450. * @param {String} message
  2451. * @api public
  2452. */
  2453. assert.isNull = function (val, msg) {
  2454. new Assertion(val, msg).to.equal(null);
  2455. };
  2456. /**
  2457. * ### .isNotNull(value, [message])
  2458. *
  2459. * Asserts that `value` is not null.
  2460. *
  2461. * var tea = 'tasty chai';
  2462. * assert.isNotNull(tea, 'great, time for tea!');
  2463. *
  2464. * @name isNotNull
  2465. * @param {Mixed} value
  2466. * @param {String} message
  2467. * @api public
  2468. */
  2469. assert.isNotNull = function (val, msg) {
  2470. new Assertion(val, msg).to.not.equal(null);
  2471. };
  2472. /**
  2473. * ### .isUndefined(value, [message])
  2474. *
  2475. * Asserts that `value` is `undefined`.
  2476. *
  2477. * var tea;
  2478. * assert.isUndefined(tea, 'no tea defined');
  2479. *
  2480. * @name isUndefined
  2481. * @param {Mixed} value
  2482. * @param {String} message
  2483. * @api public
  2484. */
  2485. assert.isUndefined = function (val, msg) {
  2486. new Assertion(val, msg).to.equal(undefined);
  2487. };
  2488. /**
  2489. * ### .isDefined(value, [message])
  2490. *
  2491. * Asserts that `value` is not `undefined`.
  2492. *
  2493. * var tea = 'cup of chai';
  2494. * assert.isDefined(tea, 'tea has been defined');
  2495. *
  2496. * @name isDefined
  2497. * @param {Mixed} value
  2498. * @param {String} message
  2499. * @api public
  2500. */
  2501. assert.isDefined = function (val, msg) {
  2502. new Assertion(val, msg).to.not.equal(undefined);
  2503. };
  2504. /**
  2505. * ### .isFunction(value, [message])
  2506. *
  2507. * Asserts that `value` is a function.
  2508. *
  2509. * function serveTea() { return 'cup of tea'; };
  2510. * assert.isFunction(serveTea, 'great, we can have tea now');
  2511. *
  2512. * @name isFunction
  2513. * @param {Mixed} value
  2514. * @param {String} message
  2515. * @api public
  2516. */
  2517. assert.isFunction = function (val, msg) {
  2518. new Assertion(val, msg).to.be.a('function');
  2519. };
  2520. /**
  2521. * ### .isNotFunction(value, [message])
  2522. *
  2523. * Asserts that `value` is _not_ a function.
  2524. *
  2525. * var serveTea = [ 'heat', 'pour', 'sip' ];
  2526. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  2527. *
  2528. * @name isNotFunction
  2529. * @param {Mixed} value
  2530. * @param {String} message
  2531. * @api public
  2532. */
  2533. assert.isNotFunction = function (val, msg) {
  2534. new Assertion(val, msg).to.not.be.a('function');
  2535. };
  2536. /**
  2537. * ### .isObject(value, [message])
  2538. *
  2539. * Asserts that `value` is an object (as revealed by
  2540. * `Object.prototype.toString`).
  2541. *
  2542. * var selection = { name: 'Chai', serve: 'with spices' };
  2543. * assert.isObject(selection, 'tea selection is an object');
  2544. *
  2545. * @name isObject
  2546. * @param {Mixed} value
  2547. * @param {String} message
  2548. * @api public
  2549. */
  2550. assert.isObject = function (val, msg) {
  2551. new Assertion(val, msg).to.be.a('object');
  2552. };
  2553. /**
  2554. * ### .isNotObject(value, [message])
  2555. *
  2556. * Asserts that `value` is _not_ an object.
  2557. *
  2558. * var selection = 'chai'
  2559. * assert.isNotObject(selection, 'tea selection is not an object');
  2560. * assert.isNotObject(null, 'null is not an object');
  2561. *
  2562. * @name isNotObject
  2563. * @param {Mixed} value
  2564. * @param {String} message
  2565. * @api public
  2566. */
  2567. assert.isNotObject = function (val, msg) {
  2568. new Assertion(val, msg).to.not.be.a('object');
  2569. };
  2570. /**
  2571. * ### .isArray(value, [message])
  2572. *
  2573. * Asserts that `value` is an array.
  2574. *
  2575. * var menu = [ 'green', 'chai', 'oolong' ];
  2576. * assert.isArray(menu, 'what kind of tea do we want?');
  2577. *
  2578. * @name isArray
  2579. * @param {Mixed} value
  2580. * @param {String} message
  2581. * @api public
  2582. */
  2583. assert.isArray = function (val, msg) {
  2584. new Assertion(val, msg).to.be.an('array');
  2585. };
  2586. /**
  2587. * ### .isNotArray(value, [message])
  2588. *
  2589. * Asserts that `value` is _not_ an array.
  2590. *
  2591. * var menu = 'green|chai|oolong';
  2592. * assert.isNotArray(menu, 'what kind of tea do we want?');
  2593. *
  2594. * @name isNotArray
  2595. * @param {Mixed} value
  2596. * @param {String} message
  2597. * @api public
  2598. */
  2599. assert.isNotArray = function (val, msg) {
  2600. new Assertion(val, msg).to.not.be.an('array');
  2601. };
  2602. /**
  2603. * ### .isString(value, [message])
  2604. *
  2605. * Asserts that `value` is a string.
  2606. *
  2607. * var teaOrder = 'chai';
  2608. * assert.isString(teaOrder, 'order placed');
  2609. *
  2610. * @name isString
  2611. * @param {Mixed} value
  2612. * @param {String} message
  2613. * @api public
  2614. */
  2615. assert.isString = function (val, msg) {
  2616. new Assertion(val, msg).to.be.a('string');
  2617. };
  2618. /**
  2619. * ### .isNotString(value, [message])
  2620. *
  2621. * Asserts that `value` is _not_ a string.
  2622. *
  2623. * var teaOrder = 4;
  2624. * assert.isNotString(teaOrder, 'order placed');
  2625. *
  2626. * @name isNotString
  2627. * @param {Mixed} value
  2628. * @param {String} message
  2629. * @api public
  2630. */
  2631. assert.isNotString = function (val, msg) {
  2632. new Assertion(val, msg).to.not.be.a('string');
  2633. };
  2634. /**
  2635. * ### .isNumber(value, [message])
  2636. *
  2637. * Asserts that `value` is a number.
  2638. *
  2639. * var cups = 2;
  2640. * assert.isNumber(cups, 'how many cups');
  2641. *
  2642. * @name isNumber
  2643. * @param {Number} value
  2644. * @param {String} message
  2645. * @api public
  2646. */
  2647. assert.isNumber = function (val, msg) {
  2648. new Assertion(val, msg).to.be.a('number');
  2649. };
  2650. /**
  2651. * ### .isNotNumber(value, [message])
  2652. *
  2653. * Asserts that `value` is _not_ a number.
  2654. *
  2655. * var cups = '2 cups please';
  2656. * assert.isNotNumber(cups, 'how many cups');
  2657. *
  2658. * @name isNotNumber
  2659. * @param {Mixed} value
  2660. * @param {String} message
  2661. * @api public
  2662. */
  2663. assert.isNotNumber = function (val, msg) {
  2664. new Assertion(val, msg).to.not.be.a('number');
  2665. };
  2666. /**
  2667. * ### .isBoolean(value, [message])
  2668. *
  2669. * Asserts that `value` is a boolean.
  2670. *
  2671. * var teaReady = true
  2672. * , teaServed = false;
  2673. *
  2674. * assert.isBoolean(teaReady, 'is the tea ready');
  2675. * assert.isBoolean(teaServed, 'has tea been served');
  2676. *
  2677. * @name isBoolean
  2678. * @param {Mixed} value
  2679. * @param {String} message
  2680. * @api public
  2681. */
  2682. assert.isBoolean = function (val, msg) {
  2683. new Assertion(val, msg).to.be.a('boolean');
  2684. };
  2685. /**
  2686. * ### .isNotBoolean(value, [message])
  2687. *
  2688. * Asserts that `value` is _not_ a boolean.
  2689. *
  2690. * var teaReady = 'yep'
  2691. * , teaServed = 'nope';
  2692. *
  2693. * assert.isNotBoolean(teaReady, 'is the tea ready');
  2694. * assert.isNotBoolean(teaServed, 'has tea been served');
  2695. *
  2696. * @name isNotBoolean
  2697. * @param {Mixed} value
  2698. * @param {String} message
  2699. * @api public
  2700. */
  2701. assert.isNotBoolean = function (val, msg) {
  2702. new Assertion(val, msg).to.not.be.a('boolean');
  2703. };
  2704. /**
  2705. * ### .typeOf(value, name, [message])
  2706. *
  2707. * Asserts that `value`'s type is `name`, as determined by
  2708. * `Object.prototype.toString`.
  2709. *
  2710. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  2711. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  2712. * assert.typeOf('tea', 'string', 'we have a string');
  2713. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  2714. * assert.typeOf(null, 'null', 'we have a null');
  2715. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  2716. *
  2717. * @name typeOf
  2718. * @param {Mixed} value
  2719. * @param {String} name
  2720. * @param {String} message
  2721. * @api public
  2722. */
  2723. assert.typeOf = function (val, type, msg) {
  2724. new Assertion(val, msg).to.be.a(type);
  2725. };
  2726. /**
  2727. * ### .notTypeOf(value, name, [message])
  2728. *
  2729. * Asserts that `value`'s type is _not_ `name`, as determined by
  2730. * `Object.prototype.toString`.
  2731. *
  2732. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  2733. *
  2734. * @name notTypeOf
  2735. * @param {Mixed} value
  2736. * @param {String} typeof name
  2737. * @param {String} message
  2738. * @api public
  2739. */
  2740. assert.notTypeOf = function (val, type, msg) {
  2741. new Assertion(val, msg).to.not.be.a(type);
  2742. };
  2743. /**
  2744. * ### .instanceOf(object, constructor, [message])
  2745. *
  2746. * Asserts that `value` is an instance of `constructor`.
  2747. *
  2748. * var Tea = function (name) { this.name = name; }
  2749. * , chai = new Tea('chai');
  2750. *
  2751. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  2752. *
  2753. * @name instanceOf
  2754. * @param {Object} object
  2755. * @param {Constructor} constructor
  2756. * @param {String} message
  2757. * @api public
  2758. */
  2759. assert.instanceOf = function (val, type, msg) {
  2760. new Assertion(val, msg).to.be.instanceOf(type);
  2761. };
  2762. /**
  2763. * ### .notInstanceOf(object, constructor, [message])
  2764. *
  2765. * Asserts `value` is not an instance of `constructor`.
  2766. *
  2767. * var Tea = function (name) { this.name = name; }
  2768. * , chai = new String('chai');
  2769. *
  2770. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  2771. *
  2772. * @name notInstanceOf
  2773. * @param {Object} object
  2774. * @param {Constructor} constructor
  2775. * @param {String} message
  2776. * @api public
  2777. */
  2778. assert.notInstanceOf = function (val, type, msg) {
  2779. new Assertion(val, msg).to.not.be.instanceOf(type);
  2780. };
  2781. /**
  2782. * ### .include(haystack, needle, [message])
  2783. *
  2784. * Asserts that `haystack` includes `needle`. Works
  2785. * for strings and arrays.
  2786. *
  2787. * assert.include('foobar', 'bar', 'foobar contains string "bar"');
  2788. * assert.include([ 1, 2, 3 ], 3, 'array contains value');
  2789. *
  2790. * @name include
  2791. * @param {Array|String} haystack
  2792. * @param {Mixed} needle
  2793. * @param {String} message
  2794. * @api public
  2795. */
  2796. assert.include = function (exp, inc, msg) {
  2797. new Assertion(exp, msg, assert.include).include(inc);
  2798. };
  2799. /**
  2800. * ### .notInclude(haystack, needle, [message])
  2801. *
  2802. * Asserts that `haystack` does not include `needle`. Works
  2803. * for strings and arrays.
  2804. *i
  2805. * assert.notInclude('foobar', 'baz', 'string not include substring');
  2806. * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
  2807. *
  2808. * @name notInclude
  2809. * @param {Array|String} haystack
  2810. * @param {Mixed} needle
  2811. * @param {String} message
  2812. * @api public
  2813. */
  2814. assert.notInclude = function (exp, inc, msg) {
  2815. new Assertion(exp, msg, assert.notInclude).not.include(inc);
  2816. };
  2817. /**
  2818. * ### .match(value, regexp, [message])
  2819. *
  2820. * Asserts that `value` matches the regular expression `regexp`.
  2821. *
  2822. * assert.match('foobar', /^foo/, 'regexp matches');
  2823. *
  2824. * @name match
  2825. * @param {Mixed} value
  2826. * @param {RegExp} regexp
  2827. * @param {String} message
  2828. * @api public
  2829. */
  2830. assert.match = function (exp, re, msg) {
  2831. new Assertion(exp, msg).to.match(re);
  2832. };
  2833. /**
  2834. * ### .notMatch(value, regexp, [message])
  2835. *
  2836. * Asserts that `value` does not match the regular expression `regexp`.
  2837. *
  2838. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  2839. *
  2840. * @name notMatch
  2841. * @param {Mixed} value
  2842. * @param {RegExp} regexp
  2843. * @param {String} message
  2844. * @api public
  2845. */
  2846. assert.notMatch = function (exp, re, msg) {
  2847. new Assertion(exp, msg).to.not.match(re);
  2848. };
  2849. /**
  2850. * ### .property(object, property, [message])
  2851. *
  2852. * Asserts that `object` has a property named by `property`.
  2853. *
  2854. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  2855. *
  2856. * @name property
  2857. * @param {Object} object
  2858. * @param {String} property
  2859. * @param {String} message
  2860. * @api public
  2861. */
  2862. assert.property = function (obj, prop, msg) {
  2863. new Assertion(obj, msg).to.have.property(prop);
  2864. };
  2865. /**
  2866. * ### .notProperty(object, property, [message])
  2867. *
  2868. * Asserts that `object` does _not_ have a property named by `property`.
  2869. *
  2870. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  2871. *
  2872. * @name notProperty
  2873. * @param {Object} object
  2874. * @param {String} property
  2875. * @param {String} message
  2876. * @api public
  2877. */
  2878. assert.notProperty = function (obj, prop, msg) {
  2879. new Assertion(obj, msg).to.not.have.property(prop);
  2880. };
  2881. /**
  2882. * ### .deepProperty(object, property, [message])
  2883. *
  2884. * Asserts that `object` has a property named by `property`, which can be a
  2885. * string using dot- and bracket-notation for deep reference.
  2886. *
  2887. * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
  2888. *
  2889. * @name deepProperty
  2890. * @param {Object} object
  2891. * @param {String} property
  2892. * @param {String} message
  2893. * @api public
  2894. */
  2895. assert.deepProperty = function (obj, prop, msg) {
  2896. new Assertion(obj, msg).to.have.deep.property(prop);
  2897. };
  2898. /**
  2899. * ### .notDeepProperty(object, property, [message])
  2900. *
  2901. * Asserts that `object` does _not_ have a property named by `property`, which
  2902. * can be a string using dot- and bracket-notation for deep reference.
  2903. *
  2904. * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  2905. *
  2906. * @name notDeepProperty
  2907. * @param {Object} object
  2908. * @param {String} property
  2909. * @param {String} message
  2910. * @api public
  2911. */
  2912. assert.notDeepProperty = function (obj, prop, msg) {
  2913. new Assertion(obj, msg).to.not.have.deep.property(prop);
  2914. };
  2915. /**
  2916. * ### .propertyVal(object, property, value, [message])
  2917. *
  2918. * Asserts that `object` has a property named by `property` with value given
  2919. * by `value`.
  2920. *
  2921. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  2922. *
  2923. * @name propertyVal
  2924. * @param {Object} object
  2925. * @param {String} property
  2926. * @param {Mixed} value
  2927. * @param {String} message
  2928. * @api public
  2929. */
  2930. assert.propertyVal = function (obj, prop, val, msg) {
  2931. new Assertion(obj, msg).to.have.property(prop, val);
  2932. };
  2933. /**
  2934. * ### .propertyNotVal(object, property, value, [message])
  2935. *
  2936. * Asserts that `object` has a property named by `property`, but with a value
  2937. * different from that given by `value`.
  2938. *
  2939. * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
  2940. *
  2941. * @name propertyNotVal
  2942. * @param {Object} object
  2943. * @param {String} property
  2944. * @param {Mixed} value
  2945. * @param {String} message
  2946. * @api public
  2947. */
  2948. assert.propertyNotVal = function (obj, prop, val, msg) {
  2949. new Assertion(obj, msg).to.not.have.property(prop, val);
  2950. };
  2951. /**
  2952. * ### .deepPropertyVal(object, property, value, [message])
  2953. *
  2954. * Asserts that `object` has a property named by `property` with value given
  2955. * by `value`. `property` can use dot- and bracket-notation for deep
  2956. * reference.
  2957. *
  2958. * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  2959. *
  2960. * @name deepPropertyVal
  2961. * @param {Object} object
  2962. * @param {String} property
  2963. * @param {Mixed} value
  2964. * @param {String} message
  2965. * @api public
  2966. */
  2967. assert.deepPropertyVal = function (obj, prop, val, msg) {
  2968. new Assertion(obj, msg).to.have.deep.property(prop, val);
  2969. };
  2970. /**
  2971. * ### .deepPropertyNotVal(object, property, value, [message])
  2972. *
  2973. * Asserts that `object` has a property named by `property`, but with a value
  2974. * different from that given by `value`. `property` can use dot- and
  2975. * bracket-notation for deep reference.
  2976. *
  2977. * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  2978. *
  2979. * @name deepPropertyNotVal
  2980. * @param {Object} object
  2981. * @param {String} property
  2982. * @param {Mixed} value
  2983. * @param {String} message
  2984. * @api public
  2985. */
  2986. assert.deepPropertyNotVal = function (obj, prop, val, msg) {
  2987. new Assertion(obj, msg).to.not.have.deep.property(prop, val);
  2988. };
  2989. /**
  2990. * ### .lengthOf(object, length, [message])
  2991. *
  2992. * Asserts that `object` has a `length` property with the expected value.
  2993. *
  2994. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  2995. * assert.lengthOf('foobar', 5, 'string has length of 6');
  2996. *
  2997. * @name lengthOf
  2998. * @param {Mixed} object
  2999. * @param {Number} length
  3000. * @param {String} message
  3001. * @api public
  3002. */
  3003. assert.lengthOf = function (exp, len, msg) {
  3004. new Assertion(exp, msg).to.have.length(len);
  3005. };
  3006. /**
  3007. * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
  3008. *
  3009. * Asserts that `function` will throw an error that is an instance of
  3010. * `constructor`, or alternately that it will throw an error with message
  3011. * matching `regexp`.
  3012. *
  3013. * assert.throw(fn, 'function throws a reference error');
  3014. * assert.throw(fn, /function throws a reference error/);
  3015. * assert.throw(fn, ReferenceError);
  3016. * assert.throw(fn, ReferenceError, 'function throws a reference error');
  3017. * assert.throw(fn, ReferenceError, /function throws a reference error/);
  3018. *
  3019. * @name throws
  3020. * @alias throw
  3021. * @alias Throw
  3022. * @param {Function} function
  3023. * @param {ErrorConstructor} constructor
  3024. * @param {RegExp} regexp
  3025. * @param {String} message
  3026. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  3027. * @api public
  3028. */
  3029. assert.Throw = function (fn, errt, errs, msg) {
  3030. if ('string' === typeof errt || errt instanceof RegExp) {
  3031. errs = errt;
  3032. errt = null;
  3033. }
  3034. var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
  3035. return flag(assertErr, 'object');
  3036. };
  3037. /**
  3038. * ### .doesNotThrow(function, [constructor/regexp], [message])
  3039. *
  3040. * Asserts that `function` will _not_ throw an error that is an instance of
  3041. * `constructor`, or alternately that it will not throw an error with message
  3042. * matching `regexp`.
  3043. *
  3044. * assert.doesNotThrow(fn, Error, 'function does not throw');
  3045. *
  3046. * @name doesNotThrow
  3047. * @param {Function} function
  3048. * @param {ErrorConstructor} constructor
  3049. * @param {RegExp} regexp
  3050. * @param {String} message
  3051. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  3052. * @api public
  3053. */
  3054. assert.doesNotThrow = function (fn, type, msg) {
  3055. if ('string' === typeof type) {
  3056. msg = type;
  3057. type = null;
  3058. }
  3059. new Assertion(fn, msg).to.not.Throw(type);
  3060. };
  3061. /**
  3062. * ### .operator(val1, operator, val2, [message])
  3063. *
  3064. * Compares two values using `operator`.
  3065. *
  3066. * assert.operator(1, '<', 2, 'everything is ok');
  3067. * assert.operator(1, '>', 2, 'this will fail');
  3068. *
  3069. * @name operator
  3070. * @param {Mixed} val1
  3071. * @param {String} operator
  3072. * @param {Mixed} val2
  3073. * @param {String} message
  3074. * @api public
  3075. */
  3076. assert.operator = function (val, operator, val2, msg) {
  3077. if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
  3078. throw new Error('Invalid operator "' + operator + '"');
  3079. }
  3080. var test = new Assertion(eval(val + operator + val2), msg);
  3081. test.assert(
  3082. true === flag(test, 'object')
  3083. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  3084. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  3085. };
  3086. /**
  3087. * ### .closeTo(actual, expected, delta, [message])
  3088. *
  3089. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  3090. *
  3091. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  3092. *
  3093. * @name closeTo
  3094. * @param {Number} actual
  3095. * @param {Number} expected
  3096. * @param {Number} delta
  3097. * @param {String} message
  3098. * @api public
  3099. */
  3100. assert.closeTo = function (act, exp, delta, msg) {
  3101. new Assertion(act, msg).to.be.closeTo(exp, delta);
  3102. };
  3103. /**
  3104. * ### .sameMembers(set1, set2, [message])
  3105. *
  3106. * Asserts that `set1` and `set2` have the same members.
  3107. * Order is not taken into account.
  3108. *
  3109. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  3110. *
  3111. * @name sameMembers
  3112. * @param {Array} set1
  3113. * @param {Array} set2
  3114. * @param {String} message
  3115. * @api public
  3116. */
  3117. assert.sameMembers = function (set1, set2, msg) {
  3118. new Assertion(set1, msg).to.have.same.members(set2);
  3119. }
  3120. /**
  3121. * ### .sameDeepMembers(set1, set2, [message])
  3122. *
  3123. * Asserts that `set1` and `set2` have the same members - using a deep equality checking.
  3124. * Order is not taken into account.
  3125. *
  3126. * assert.sameDeepMembers([ {b: 3}, {a: 2}, {c: 5} ], [ {c: 5}, {b: 3}, {a: 2} ], 'same deep members');
  3127. *
  3128. * @name sameDeepMembers
  3129. * @param {Array} set1
  3130. * @param {Array} set2
  3131. * @param {String} message
  3132. * @api public
  3133. */
  3134. assert.sameDeepMembers = function (set1, set2, msg) {
  3135. new Assertion(set1, msg).to.have.same.deep.members(set2);
  3136. }
  3137. /**
  3138. * ### .includeMembers(superset, subset, [message])
  3139. *
  3140. * Asserts that `subset` is included in `superset`.
  3141. * Order is not taken into account.
  3142. *
  3143. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
  3144. *
  3145. * @name includeMembers
  3146. * @param {Array} superset
  3147. * @param {Array} subset
  3148. * @param {String} message
  3149. * @api public
  3150. */
  3151. assert.includeMembers = function (superset, subset, msg) {
  3152. new Assertion(superset, msg).to.include.members(subset);
  3153. }
  3154. /**
  3155. * ### .changes(function, object, property)
  3156. *
  3157. * Asserts that a function changes the value of a property
  3158. *
  3159. * var obj = { val: 10 };
  3160. * var fn = function() { obj.val = 22 };
  3161. * assert.changes(fn, obj, 'val');
  3162. *
  3163. * @name changes
  3164. * @param {Function} modifier function
  3165. * @param {Object} object
  3166. * @param {String} property name
  3167. * @param {String} message _optional_
  3168. * @api public
  3169. */
  3170. assert.changes = function (fn, obj, prop) {
  3171. new Assertion(fn).to.change(obj, prop);
  3172. }
  3173. /**
  3174. * ### .doesNotChange(function, object, property)
  3175. *
  3176. * Asserts that a function does not changes the value of a property
  3177. *
  3178. * var obj = { val: 10 };
  3179. * var fn = function() { console.log('foo'); };
  3180. * assert.doesNotChange(fn, obj, 'val');
  3181. *
  3182. * @name doesNotChange
  3183. * @param {Function} modifier function
  3184. * @param {Object} object
  3185. * @param {String} property name
  3186. * @param {String} message _optional_
  3187. * @api public
  3188. */
  3189. assert.doesNotChange = function (fn, obj, prop) {
  3190. new Assertion(fn).to.not.change(obj, prop);
  3191. }
  3192. /**
  3193. * ### .increases(function, object, property)
  3194. *
  3195. * Asserts that a function increases an object property
  3196. *
  3197. * var obj = { val: 10 };
  3198. * var fn = function() { obj.val = 13 };
  3199. * assert.increases(fn, obj, 'val');
  3200. *
  3201. * @name increases
  3202. * @param {Function} modifier function
  3203. * @param {Object} object
  3204. * @param {String} property name
  3205. * @param {String} message _optional_
  3206. * @api public
  3207. */
  3208. assert.increases = function (fn, obj, prop) {
  3209. new Assertion(fn).to.increase(obj, prop);
  3210. }
  3211. /**
  3212. * ### .doesNotIncrease(function, object, property)
  3213. *
  3214. * Asserts that a function does not increase object property
  3215. *
  3216. * var obj = { val: 10 };
  3217. * var fn = function() { obj.val = 8 };
  3218. * assert.doesNotIncrease(fn, obj, 'val');
  3219. *
  3220. * @name doesNotIncrease
  3221. * @param {Function} modifier function
  3222. * @param {Object} object
  3223. * @param {String} property name
  3224. * @param {String} message _optional_
  3225. * @api public
  3226. */
  3227. assert.doesNotIncrease = function (fn, obj, prop) {
  3228. new Assertion(fn).to.not.increase(obj, prop);
  3229. }
  3230. /**
  3231. * ### .decreases(function, object, property)
  3232. *
  3233. * Asserts that a function decreases an object property
  3234. *
  3235. * var obj = { val: 10 };
  3236. * var fn = function() { obj.val = 5 };
  3237. * assert.decreases(fn, obj, 'val');
  3238. *
  3239. * @name decreases
  3240. * @param {Function} modifier function
  3241. * @param {Object} object
  3242. * @param {String} property name
  3243. * @param {String} message _optional_
  3244. * @api public
  3245. */
  3246. assert.decreases = function (fn, obj, prop) {
  3247. new Assertion(fn).to.decrease(obj, prop);
  3248. }
  3249. /**
  3250. * ### .doesNotDecrease(function, object, property)
  3251. *
  3252. * Asserts that a function does not decreases an object property
  3253. *
  3254. * var obj = { val: 10 };
  3255. * var fn = function() { obj.val = 15 };
  3256. * assert.doesNotDecrease(fn, obj, 'val');
  3257. *
  3258. * @name doesNotDecrease
  3259. * @param {Function} modifier function
  3260. * @param {Object} object
  3261. * @param {String} property name
  3262. * @param {String} message _optional_
  3263. * @api public
  3264. */
  3265. assert.doesNotDecrease = function (fn, obj, prop) {
  3266. new Assertion(fn).to.not.decrease(obj, prop);
  3267. }
  3268. /*!
  3269. * Undocumented / untested
  3270. */
  3271. assert.ifError = function (val, msg) {
  3272. new Assertion(val, msg).to.not.be.ok;
  3273. };
  3274. /*!
  3275. * Aliases.
  3276. */
  3277. (function alias(name, as){
  3278. assert[as] = assert[name];
  3279. return alias;
  3280. })
  3281. ('Throw', 'throw')
  3282. ('Throw', 'throws');
  3283. };
  3284. });
  3285. require.register("chai/lib/chai/interface/expect.js", function (exports, module) {
  3286. /*!
  3287. * chai
  3288. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3289. * MIT Licensed
  3290. */
  3291. module.exports = function (chai, util) {
  3292. chai.expect = function (val, message) {
  3293. return new chai.Assertion(val, message);
  3294. };
  3295. /**
  3296. * ### .fail(actual, expected, [message], [operator])
  3297. *
  3298. * Throw a failure.
  3299. *
  3300. * @name fail
  3301. * @param {Mixed} actual
  3302. * @param {Mixed} expected
  3303. * @param {String} message
  3304. * @param {String} operator
  3305. * @api public
  3306. */
  3307. chai.expect.fail = function (actual, expected, message, operator) {
  3308. message = message || 'expect.fail()';
  3309. throw new chai.AssertionError(message, {
  3310. actual: actual
  3311. , expected: expected
  3312. , operator: operator
  3313. }, chai.expect.fail);
  3314. };
  3315. };
  3316. });
  3317. require.register("chai/lib/chai/interface/should.js", function (exports, module) {
  3318. /*!
  3319. * chai
  3320. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3321. * MIT Licensed
  3322. */
  3323. module.exports = function (chai, util) {
  3324. var Assertion = chai.Assertion;
  3325. function loadShould () {
  3326. // explicitly define this method as function as to have it's name to include as `ssfi`
  3327. function shouldGetter() {
  3328. if (this instanceof String || this instanceof Number) {
  3329. return new Assertion(this.constructor(this), null, shouldGetter);
  3330. } else if (this instanceof Boolean) {
  3331. return new Assertion(this == true, null, shouldGetter);
  3332. }
  3333. return new Assertion(this, null, shouldGetter);
  3334. }
  3335. function shouldSetter(value) {
  3336. // See https://github.com/chaijs/chai/issues/86: this makes
  3337. // `whatever.should = someValue` actually set `someValue`, which is
  3338. // especially useful for `global.should = require('chai').should()`.
  3339. //
  3340. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  3341. // since otherwise we would trigger this very setter!
  3342. Object.defineProperty(this, 'should', {
  3343. value: value,
  3344. enumerable: true,
  3345. configurable: true,
  3346. writable: true
  3347. });
  3348. }
  3349. // modify Object.prototype to have `should`
  3350. Object.defineProperty(Object.prototype, 'should', {
  3351. set: shouldSetter
  3352. , get: shouldGetter
  3353. , configurable: true
  3354. });
  3355. var should = {};
  3356. /**
  3357. * ### .fail(actual, expected, [message], [operator])
  3358. *
  3359. * Throw a failure.
  3360. *
  3361. * @name fail
  3362. * @param {Mixed} actual
  3363. * @param {Mixed} expected
  3364. * @param {String} message
  3365. * @param {String} operator
  3366. * @api public
  3367. */
  3368. should.fail = function (actual, expected, message, operator) {
  3369. message = message || 'should.fail()';
  3370. throw new chai.AssertionError(message, {
  3371. actual: actual
  3372. , expected: expected
  3373. , operator: operator
  3374. }, should.fail);
  3375. };
  3376. should.equal = function (val1, val2, msg) {
  3377. new Assertion(val1, msg).to.equal(val2);
  3378. };
  3379. should.Throw = function (fn, errt, errs, msg) {
  3380. new Assertion(fn, msg).to.Throw(errt, errs);
  3381. };
  3382. should.exist = function (val, msg) {
  3383. new Assertion(val, msg).to.exist;
  3384. }
  3385. // negation
  3386. should.not = {}
  3387. should.not.equal = function (val1, val2, msg) {
  3388. new Assertion(val1, msg).to.not.equal(val2);
  3389. };
  3390. should.not.Throw = function (fn, errt, errs, msg) {
  3391. new Assertion(fn, msg).to.not.Throw(errt, errs);
  3392. };
  3393. should.not.exist = function (val, msg) {
  3394. new Assertion(val, msg).to.not.exist;
  3395. }
  3396. should['throw'] = should['Throw'];
  3397. should.not['throw'] = should.not['Throw'];
  3398. return should;
  3399. };
  3400. chai.should = loadShould;
  3401. chai.Should = loadShould;
  3402. };
  3403. });
  3404. require.register("chai/lib/chai/utils/addChainableMethod.js", function (exports, module) {
  3405. /*!
  3406. * Chai - addChainingMethod utility
  3407. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3408. * MIT Licensed
  3409. */
  3410. /*!
  3411. * Module dependencies
  3412. */
  3413. var transferFlags = require('chai/lib/chai/utils/transferFlags.js');
  3414. var flag = require('chai/lib/chai/utils/flag.js');
  3415. var config = require('chai/lib/chai/config.js');
  3416. /*!
  3417. * Module variables
  3418. */
  3419. // Check whether `__proto__` is supported
  3420. var hasProtoSupport = '__proto__' in Object;
  3421. // Without `__proto__` support, this module will need to add properties to a function.
  3422. // However, some Function.prototype methods cannot be overwritten,
  3423. // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
  3424. var excludeNames = /^(?:length|name|arguments|caller)$/;
  3425. // Cache `Function` properties
  3426. var call = Function.prototype.call,
  3427. apply = Function.prototype.apply;
  3428. /**
  3429. * ### addChainableMethod (ctx, name, method, chainingBehavior)
  3430. *
  3431. * Adds a method to an object, such that the method can also be chained.
  3432. *
  3433. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  3434. * var obj = utils.flag(this, 'object');
  3435. * new chai.Assertion(obj).to.be.equal(str);
  3436. * });
  3437. *
  3438. * Can also be accessed directly from `chai.Assertion`.
  3439. *
  3440. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  3441. *
  3442. * The result can then be used as both a method assertion, executing both `method` and
  3443. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  3444. *
  3445. * expect(fooStr).to.be.foo('bar');
  3446. * expect(fooStr).to.be.foo.equal('foo');
  3447. *
  3448. * @param {Object} ctx object to which the method is added
  3449. * @param {String} name of method to add
  3450. * @param {Function} method function to be used for `name`, when called
  3451. * @param {Function} chainingBehavior function to be called every time the property is accessed
  3452. * @name addChainableMethod
  3453. * @api public
  3454. */
  3455. module.exports = function (ctx, name, method, chainingBehavior) {
  3456. if (typeof chainingBehavior !== 'function') {
  3457. chainingBehavior = function () { };
  3458. }
  3459. var chainableBehavior = {
  3460. method: method
  3461. , chainingBehavior: chainingBehavior
  3462. };
  3463. // save the methods so we can overwrite them later, if we need to.
  3464. if (!ctx.__methods) {
  3465. ctx.__methods = {};
  3466. }
  3467. ctx.__methods[name] = chainableBehavior;
  3468. Object.defineProperty(ctx, name,
  3469. { get: function () {
  3470. chainableBehavior.chainingBehavior.call(this);
  3471. var assert = function assert() {
  3472. var old_ssfi = flag(this, 'ssfi');
  3473. if (old_ssfi && config.includeStack === false)
  3474. flag(this, 'ssfi', assert);
  3475. var result = chainableBehavior.method.apply(this, arguments);
  3476. return result === undefined ? this : result;
  3477. };
  3478. // Use `__proto__` if available
  3479. if (hasProtoSupport) {
  3480. // Inherit all properties from the object by replacing the `Function` prototype
  3481. var prototype = assert.__proto__ = Object.create(this);
  3482. // Restore the `call` and `apply` methods from `Function`
  3483. prototype.call = call;
  3484. prototype.apply = apply;
  3485. }
  3486. // Otherwise, redefine all properties (slow!)
  3487. else {
  3488. var asserterNames = Object.getOwnPropertyNames(ctx);
  3489. asserterNames.forEach(function (asserterName) {
  3490. if (!excludeNames.test(asserterName)) {
  3491. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  3492. Object.defineProperty(assert, asserterName, pd);
  3493. }
  3494. });
  3495. }
  3496. transferFlags(this, assert);
  3497. return assert;
  3498. }
  3499. , configurable: true
  3500. });
  3501. };
  3502. });
  3503. require.register("chai/lib/chai/utils/addMethod.js", function (exports, module) {
  3504. /*!
  3505. * Chai - addMethod utility
  3506. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3507. * MIT Licensed
  3508. */
  3509. var config = require('chai/lib/chai/config.js');
  3510. /**
  3511. * ### .addMethod (ctx, name, method)
  3512. *
  3513. * Adds a method to the prototype of an object.
  3514. *
  3515. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  3516. * var obj = utils.flag(this, 'object');
  3517. * new chai.Assertion(obj).to.be.equal(str);
  3518. * });
  3519. *
  3520. * Can also be accessed directly from `chai.Assertion`.
  3521. *
  3522. * chai.Assertion.addMethod('foo', fn);
  3523. *
  3524. * Then can be used as any other assertion.
  3525. *
  3526. * expect(fooStr).to.be.foo('bar');
  3527. *
  3528. * @param {Object} ctx object to which the method is added
  3529. * @param {String} name of method to add
  3530. * @param {Function} method function to be used for name
  3531. * @name addMethod
  3532. * @api public
  3533. */
  3534. var flag = require('chai/lib/chai/utils/flag.js');
  3535. module.exports = function (ctx, name, method) {
  3536. ctx[name] = function () {
  3537. var old_ssfi = flag(this, 'ssfi');
  3538. if (old_ssfi && config.includeStack === false)
  3539. flag(this, 'ssfi', ctx[name]);
  3540. var result = method.apply(this, arguments);
  3541. return result === undefined ? this : result;
  3542. };
  3543. };
  3544. });
  3545. require.register("chai/lib/chai/utils/addProperty.js", function (exports, module) {
  3546. /*!
  3547. * Chai - addProperty utility
  3548. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3549. * MIT Licensed
  3550. */
  3551. /**
  3552. * ### addProperty (ctx, name, getter)
  3553. *
  3554. * Adds a property to the prototype of an object.
  3555. *
  3556. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  3557. * var obj = utils.flag(this, 'object');
  3558. * new chai.Assertion(obj).to.be.instanceof(Foo);
  3559. * });
  3560. *
  3561. * Can also be accessed directly from `chai.Assertion`.
  3562. *
  3563. * chai.Assertion.addProperty('foo', fn);
  3564. *
  3565. * Then can be used as any other assertion.
  3566. *
  3567. * expect(myFoo).to.be.foo;
  3568. *
  3569. * @param {Object} ctx object to which the property is added
  3570. * @param {String} name of property to add
  3571. * @param {Function} getter function to be used for name
  3572. * @name addProperty
  3573. * @api public
  3574. */
  3575. module.exports = function (ctx, name, getter) {
  3576. Object.defineProperty(ctx, name,
  3577. { get: function () {
  3578. var result = getter.call(this);
  3579. return result === undefined ? this : result;
  3580. }
  3581. , configurable: true
  3582. });
  3583. };
  3584. });
  3585. require.register("chai/lib/chai/utils/flag.js", function (exports, module) {
  3586. /*!
  3587. * Chai - flag utility
  3588. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3589. * MIT Licensed
  3590. */
  3591. /**
  3592. * ### flag(object, key, [value])
  3593. *
  3594. * Get or set a flag value on an object. If a
  3595. * value is provided it will be set, else it will
  3596. * return the currently set value or `undefined` if
  3597. * the value is not set.
  3598. *
  3599. * utils.flag(this, 'foo', 'bar'); // setter
  3600. * utils.flag(this, 'foo'); // getter, returns `bar`
  3601. *
  3602. * @param {Object} object constructed Assertion
  3603. * @param {String} key
  3604. * @param {Mixed} value (optional)
  3605. * @name flag
  3606. * @api private
  3607. */
  3608. module.exports = function (obj, key, value) {
  3609. var flags = obj.__flags || (obj.__flags = Object.create(null));
  3610. if (arguments.length === 3) {
  3611. flags[key] = value;
  3612. } else {
  3613. return flags[key];
  3614. }
  3615. };
  3616. });
  3617. require.register("chai/lib/chai/utils/getActual.js", function (exports, module) {
  3618. /*!
  3619. * Chai - getActual utility
  3620. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3621. * MIT Licensed
  3622. */
  3623. /**
  3624. * # getActual(object, [actual])
  3625. *
  3626. * Returns the `actual` value for an Assertion
  3627. *
  3628. * @param {Object} object (constructed Assertion)
  3629. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3630. */
  3631. module.exports = function (obj, args) {
  3632. return args.length > 4 ? args[4] : obj._obj;
  3633. };
  3634. });
  3635. require.register("chai/lib/chai/utils/getEnumerableProperties.js", function (exports, module) {
  3636. /*!
  3637. * Chai - getEnumerableProperties utility
  3638. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3639. * MIT Licensed
  3640. */
  3641. /**
  3642. * ### .getEnumerableProperties(object)
  3643. *
  3644. * This allows the retrieval of enumerable property names of an object,
  3645. * inherited or not.
  3646. *
  3647. * @param {Object} object
  3648. * @returns {Array}
  3649. * @name getEnumerableProperties
  3650. * @api public
  3651. */
  3652. module.exports = function getEnumerableProperties(object) {
  3653. var result = [];
  3654. for (var name in object) {
  3655. result.push(name);
  3656. }
  3657. return result;
  3658. };
  3659. });
  3660. require.register("chai/lib/chai/utils/getMessage.js", function (exports, module) {
  3661. /*!
  3662. * Chai - message composition utility
  3663. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3664. * MIT Licensed
  3665. */
  3666. /*!
  3667. * Module dependancies
  3668. */
  3669. var flag = require('chai/lib/chai/utils/flag.js')
  3670. , getActual = require('chai/lib/chai/utils/getActual.js')
  3671. , inspect = require('chai/lib/chai/utils/inspect.js')
  3672. , objDisplay = require('chai/lib/chai/utils/objDisplay.js');
  3673. /**
  3674. * ### .getMessage(object, message, negateMessage)
  3675. *
  3676. * Construct the error message based on flags
  3677. * and template tags. Template tags will return
  3678. * a stringified inspection of the object referenced.
  3679. *
  3680. * Message template tags:
  3681. * - `#{this}` current asserted object
  3682. * - `#{act}` actual value
  3683. * - `#{exp}` expected value
  3684. *
  3685. * @param {Object} object (constructed Assertion)
  3686. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3687. * @name getMessage
  3688. * @api public
  3689. */
  3690. module.exports = function (obj, args) {
  3691. var negate = flag(obj, 'negate')
  3692. , val = flag(obj, 'object')
  3693. , expected = args[3]
  3694. , actual = getActual(obj, args)
  3695. , msg = negate ? args[2] : args[1]
  3696. , flagMsg = flag(obj, 'message');
  3697. if(typeof msg === "function") msg = msg();
  3698. msg = msg || '';
  3699. msg = msg
  3700. .replace(/#{this}/g, objDisplay(val))
  3701. .replace(/#{act}/g, objDisplay(actual))
  3702. .replace(/#{exp}/g, objDisplay(expected));
  3703. return flagMsg ? flagMsg + ': ' + msg : msg;
  3704. };
  3705. });
  3706. require.register("chai/lib/chai/utils/getName.js", function (exports, module) {
  3707. /*!
  3708. * Chai - getName utility
  3709. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3710. * MIT Licensed
  3711. */
  3712. /**
  3713. * # getName(func)
  3714. *
  3715. * Gets the name of a function, in a cross-browser way.
  3716. *
  3717. * @param {Function} a function (usually a constructor)
  3718. */
  3719. module.exports = function (func) {
  3720. if (func.name) return func.name;
  3721. var match = /^\s?function ([^(]*)\(/.exec(func);
  3722. return match && match[1] ? match[1] : "";
  3723. };
  3724. });
  3725. require.register("chai/lib/chai/utils/getPathValue.js", function (exports, module) {
  3726. /*!
  3727. * Chai - getPathValue utility
  3728. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3729. * @see https://github.com/logicalparadox/filtr
  3730. * MIT Licensed
  3731. */
  3732. var getPathInfo = require('chai/lib/chai/utils/getPathInfo.js');
  3733. /**
  3734. * ### .getPathValue(path, object)
  3735. *
  3736. * This allows the retrieval of values in an
  3737. * object given a string path.
  3738. *
  3739. * var obj = {
  3740. * prop1: {
  3741. * arr: ['a', 'b', 'c']
  3742. * , str: 'Hello'
  3743. * }
  3744. * , prop2: {
  3745. * arr: [ { nested: 'Universe' } ]
  3746. * , str: 'Hello again!'
  3747. * }
  3748. * }
  3749. *
  3750. * The following would be the results.
  3751. *
  3752. * getPathValue('prop1.str', obj); // Hello
  3753. * getPathValue('prop1.att[2]', obj); // b
  3754. * getPathValue('prop2.arr[0].nested', obj); // Universe
  3755. *
  3756. * @param {String} path
  3757. * @param {Object} object
  3758. * @returns {Object} value or `undefined`
  3759. * @name getPathValue
  3760. * @api public
  3761. */
  3762. module.exports = function(path, obj) {
  3763. var info = getPathInfo(path, obj);
  3764. return info.value;
  3765. };
  3766. });
  3767. require.register("chai/lib/chai/utils/getPathInfo.js", function (exports, module) {
  3768. /*!
  3769. * Chai - getPathInfo utility
  3770. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3771. * MIT Licensed
  3772. */
  3773. var hasProperty = require('chai/lib/chai/utils/hasProperty.js');
  3774. /**
  3775. * ### .getPathInfo(path, object)
  3776. *
  3777. * This allows the retrieval of property info in an
  3778. * object given a string path.
  3779. *
  3780. * The path info consists of an object with the
  3781. * following properties:
  3782. *
  3783. * * parent - The parent object of the property referenced by `path`
  3784. * * name - The name of the final property, a number if it was an array indexer
  3785. * * value - The value of the property, if it exists, otherwise `undefined`
  3786. * * exists - Whether the property exists or not
  3787. *
  3788. * @param {String} path
  3789. * @param {Object} object
  3790. * @returns {Object} info
  3791. * @name getPathInfo
  3792. * @api public
  3793. */
  3794. module.exports = function getPathInfo(path, obj) {
  3795. var parsed = parsePath(path),
  3796. last = parsed[parsed.length - 1];
  3797. var info = {
  3798. parent: _getPathValue(parsed, obj, parsed.length - 1),
  3799. name: last.p || last.i,
  3800. value: _getPathValue(parsed, obj),
  3801. };
  3802. info.exists = hasProperty(info.name, info.parent);
  3803. return info;
  3804. };
  3805. /*!
  3806. * ## parsePath(path)
  3807. *
  3808. * Helper function used to parse string object
  3809. * paths. Use in conjunction with `_getPathValue`.
  3810. *
  3811. * var parsed = parsePath('myobject.property.subprop');
  3812. *
  3813. * ### Paths:
  3814. *
  3815. * * Can be as near infinitely deep and nested
  3816. * * Arrays are also valid using the formal `myobject.document[3].property`.
  3817. *
  3818. * @param {String} path
  3819. * @returns {Object} parsed
  3820. * @api private
  3821. */
  3822. function parsePath (path) {
  3823. var str = path.replace(/\[/g, '.[')
  3824. , parts = str.match(/(\\\.|[^.]+?)+/g);
  3825. return parts.map(function (value) {
  3826. var re = /\[(\d+)\]$/
  3827. , mArr = re.exec(value);
  3828. if (mArr) return { i: parseFloat(mArr[1]) };
  3829. else return { p: value };
  3830. });
  3831. }
  3832. /*!
  3833. * ## _getPathValue(parsed, obj)
  3834. *
  3835. * Helper companion function for `.parsePath` that returns
  3836. * the value located at the parsed address.
  3837. *
  3838. * var value = getPathValue(parsed, obj);
  3839. *
  3840. * @param {Object} parsed definition from `parsePath`.
  3841. * @param {Object} object to search against
  3842. * @param {Number} object to search against
  3843. * @returns {Object|Undefined} value
  3844. * @api private
  3845. */
  3846. function _getPathValue (parsed, obj, index) {
  3847. var tmp = obj
  3848. , res;
  3849. index = (index === undefined ? parsed.length : index);
  3850. for (var i = 0, l = index; i < l; i++) {
  3851. var part = parsed[i];
  3852. if (tmp) {
  3853. if ('undefined' !== typeof part.p)
  3854. tmp = tmp[part.p];
  3855. else if ('undefined' !== typeof part.i)
  3856. tmp = tmp[part.i];
  3857. if (i == (l - 1)) res = tmp;
  3858. } else {
  3859. res = undefined;
  3860. }
  3861. }
  3862. return res;
  3863. }
  3864. });
  3865. require.register("chai/lib/chai/utils/hasProperty.js", function (exports, module) {
  3866. /*!
  3867. * Chai - hasProperty utility
  3868. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3869. * MIT Licensed
  3870. */
  3871. var type = require('chai/lib/chai/utils/type.js');
  3872. /**
  3873. * ### .hasProperty(object, name)
  3874. *
  3875. * This allows checking whether an object has
  3876. * named property or numeric array index.
  3877. *
  3878. * Basically does the same thing as the `in`
  3879. * operator but works properly with natives
  3880. * and null/undefined values.
  3881. *
  3882. * var obj = {
  3883. * arr: ['a', 'b', 'c']
  3884. * , str: 'Hello'
  3885. * }
  3886. *
  3887. * The following would be the results.
  3888. *
  3889. * hasProperty('str', obj); // true
  3890. * hasProperty('constructor', obj); // true
  3891. * hasProperty('bar', obj); // false
  3892. *
  3893. * hasProperty('length', obj.str); // true
  3894. * hasProperty(1, obj.str); // true
  3895. * hasProperty(5, obj.str); // false
  3896. *
  3897. * hasProperty('length', obj.arr); // true
  3898. * hasProperty(2, obj.arr); // true
  3899. * hasProperty(3, obj.arr); // false
  3900. *
  3901. * @param {Objuect} object
  3902. * @param {String|Number} name
  3903. * @returns {Boolean} whether it exists
  3904. * @name getPathInfo
  3905. * @api public
  3906. */
  3907. var literals = {
  3908. 'number': Number
  3909. , 'string': String
  3910. };
  3911. module.exports = function hasProperty(name, obj) {
  3912. var ot = type(obj);
  3913. // Bad Object, obviously no props at all
  3914. if(ot === 'null' || ot === 'undefined')
  3915. return false;
  3916. // The `in` operator does not work with certain literals
  3917. // box these before the check
  3918. if(literals[ot] && typeof obj !== 'object')
  3919. obj = new literals[ot](obj);
  3920. return name in obj;
  3921. };
  3922. });
  3923. require.register("chai/lib/chai/utils/getProperties.js", function (exports, module) {
  3924. /*!
  3925. * Chai - getProperties utility
  3926. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  3927. * MIT Licensed
  3928. */
  3929. /**
  3930. * ### .getProperties(object)
  3931. *
  3932. * This allows the retrieval of property names of an object, enumerable or not,
  3933. * inherited or not.
  3934. *
  3935. * @param {Object} object
  3936. * @returns {Array}
  3937. * @name getProperties
  3938. * @api public
  3939. */
  3940. module.exports = function getProperties(object) {
  3941. var result = Object.getOwnPropertyNames(subject);
  3942. function addProperty(property) {
  3943. if (result.indexOf(property) === -1) {
  3944. result.push(property);
  3945. }
  3946. }
  3947. var proto = Object.getPrototypeOf(subject);
  3948. while (proto !== null) {
  3949. Object.getOwnPropertyNames(proto).forEach(addProperty);
  3950. proto = Object.getPrototypeOf(proto);
  3951. }
  3952. return result;
  3953. };
  3954. });
  3955. require.register("chai/lib/chai/utils/index.js", function (exports, module) {
  3956. /*!
  3957. * chai
  3958. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  3959. * MIT Licensed
  3960. */
  3961. /*!
  3962. * Main exports
  3963. */
  3964. var exports = module.exports = {};
  3965. /*!
  3966. * test utility
  3967. */
  3968. exports.test = require('chai/lib/chai/utils/test.js');
  3969. /*!
  3970. * type utility
  3971. */
  3972. exports.type = require('chai/lib/chai/utils/type.js');
  3973. /*!
  3974. * message utility
  3975. */
  3976. exports.getMessage = require('chai/lib/chai/utils/getMessage.js');
  3977. /*!
  3978. * actual utility
  3979. */
  3980. exports.getActual = require('chai/lib/chai/utils/getActual.js');
  3981. /*!
  3982. * Inspect util
  3983. */
  3984. exports.inspect = require('chai/lib/chai/utils/inspect.js');
  3985. /*!
  3986. * Object Display util
  3987. */
  3988. exports.objDisplay = require('chai/lib/chai/utils/objDisplay.js');
  3989. /*!
  3990. * Flag utility
  3991. */
  3992. exports.flag = require('chai/lib/chai/utils/flag.js');
  3993. /*!
  3994. * Flag transferring utility
  3995. */
  3996. exports.transferFlags = require('chai/lib/chai/utils/transferFlags.js');
  3997. /*!
  3998. * Deep equal utility
  3999. */
  4000. exports.eql = require('chaijs~deep-eql@0.1.3');
  4001. /*!
  4002. * Deep path value
  4003. */
  4004. exports.getPathValue = require('chai/lib/chai/utils/getPathValue.js');
  4005. /*!
  4006. * Deep path info
  4007. */
  4008. exports.getPathInfo = require('chai/lib/chai/utils/getPathInfo.js');
  4009. /*!
  4010. * Check if a property exists
  4011. */
  4012. exports.hasProperty = require('chai/lib/chai/utils/hasProperty.js');
  4013. /*!
  4014. * Function name
  4015. */
  4016. exports.getName = require('chai/lib/chai/utils/getName.js');
  4017. /*!
  4018. * add Property
  4019. */
  4020. exports.addProperty = require('chai/lib/chai/utils/addProperty.js');
  4021. /*!
  4022. * add Method
  4023. */
  4024. exports.addMethod = require('chai/lib/chai/utils/addMethod.js');
  4025. /*!
  4026. * overwrite Property
  4027. */
  4028. exports.overwriteProperty = require('chai/lib/chai/utils/overwriteProperty.js');
  4029. /*!
  4030. * overwrite Method
  4031. */
  4032. exports.overwriteMethod = require('chai/lib/chai/utils/overwriteMethod.js');
  4033. /*!
  4034. * Add a chainable method
  4035. */
  4036. exports.addChainableMethod = require('chai/lib/chai/utils/addChainableMethod.js');
  4037. /*!
  4038. * Overwrite chainable method
  4039. */
  4040. exports.overwriteChainableMethod = require('chai/lib/chai/utils/overwriteChainableMethod.js');
  4041. });
  4042. require.register("chai/lib/chai/utils/inspect.js", function (exports, module) {
  4043. // This is (almost) directly from Node.js utils
  4044. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  4045. var getName = require('chai/lib/chai/utils/getName.js');
  4046. var getProperties = require('chai/lib/chai/utils/getProperties.js');
  4047. var getEnumerableProperties = require('chai/lib/chai/utils/getEnumerableProperties.js');
  4048. module.exports = inspect;
  4049. /**
  4050. * Echos the value of a value. Trys to print the value out
  4051. * in the best way possible given the different types.
  4052. *
  4053. * @param {Object} obj The object to print out.
  4054. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  4055. * properties of objects.
  4056. * @param {Number} depth Depth in which to descend in object. Default is 2.
  4057. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  4058. * output. Default is false (no coloring).
  4059. */
  4060. function inspect(obj, showHidden, depth, colors) {
  4061. var ctx = {
  4062. showHidden: showHidden,
  4063. seen: [],
  4064. stylize: function (str) { return str; }
  4065. };
  4066. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  4067. }
  4068. // Returns true if object is a DOM element.
  4069. var isDOMElement = function (object) {
  4070. if (typeof HTMLElement === 'object') {
  4071. return object instanceof HTMLElement;
  4072. } else {
  4073. return object &&
  4074. typeof object === 'object' &&
  4075. object.nodeType === 1 &&
  4076. typeof object.nodeName === 'string';
  4077. }
  4078. };
  4079. function formatValue(ctx, value, recurseTimes) {
  4080. // Provide a hook for user-specified inspect functions.
  4081. // Check that value is an object with an inspect function on it
  4082. if (value && typeof value.inspect === 'function' &&
  4083. // Filter out the util module, it's inspect function is special
  4084. value.inspect !== exports.inspect &&
  4085. // Also filter out any prototype objects using the circular check.
  4086. !(value.constructor && value.constructor.prototype === value)) {
  4087. var ret = value.inspect(recurseTimes);
  4088. if (typeof ret !== 'string') {
  4089. ret = formatValue(ctx, ret, recurseTimes);
  4090. }
  4091. return ret;
  4092. }
  4093. // Primitive types cannot have properties
  4094. var primitive = formatPrimitive(ctx, value);
  4095. if (primitive) {
  4096. return primitive;
  4097. }
  4098. // If this is a DOM element, try to get the outer HTML.
  4099. if (isDOMElement(value)) {
  4100. if ('outerHTML' in value) {
  4101. return value.outerHTML;
  4102. // This value does not have an outerHTML attribute,
  4103. // it could still be an XML element
  4104. } else {
  4105. // Attempt to serialize it
  4106. try {
  4107. if (document.xmlVersion) {
  4108. var xmlSerializer = new XMLSerializer();
  4109. return xmlSerializer.serializeToString(value);
  4110. } else {
  4111. // Firefox 11- do not support outerHTML
  4112. // It does, however, support innerHTML
  4113. // Use the following to render the element
  4114. var ns = "http://www.w3.org/1999/xhtml";
  4115. var container = document.createElementNS(ns, '_');
  4116. container.appendChild(value.cloneNode(false));
  4117. html = container.innerHTML
  4118. .replace('><', '>' + value.innerHTML + '<');
  4119. container.innerHTML = '';
  4120. return html;
  4121. }
  4122. } catch (err) {
  4123. // This could be a non-native DOM implementation,
  4124. // continue with the normal flow:
  4125. // printing the element as if it is an object.
  4126. }
  4127. }
  4128. }
  4129. // Look up the keys of the object.
  4130. var visibleKeys = getEnumerableProperties(value);
  4131. var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
  4132. // Some type of object without properties can be shortcutted.
  4133. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  4134. // a `stack` plus `description` property; ignore those for consistency.
  4135. if (keys.length === 0 || (isError(value) && (
  4136. (keys.length === 1 && keys[0] === 'stack') ||
  4137. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  4138. ))) {
  4139. if (typeof value === 'function') {
  4140. var name = getName(value);
  4141. var nameSuffix = name ? ': ' + name : '';
  4142. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  4143. }
  4144. if (isRegExp(value)) {
  4145. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4146. }
  4147. if (isDate(value)) {
  4148. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  4149. }
  4150. if (isError(value)) {
  4151. return formatError(value);
  4152. }
  4153. }
  4154. var base = '', array = false, braces = ['{', '}'];
  4155. // Make Array say that they are Array
  4156. if (isArray(value)) {
  4157. array = true;
  4158. braces = ['[', ']'];
  4159. }
  4160. // Make functions say that they are functions
  4161. if (typeof value === 'function') {
  4162. var name = getName(value);
  4163. var nameSuffix = name ? ': ' + name : '';
  4164. base = ' [Function' + nameSuffix + ']';
  4165. }
  4166. // Make RegExps say that they are RegExps
  4167. if (isRegExp(value)) {
  4168. base = ' ' + RegExp.prototype.toString.call(value);
  4169. }
  4170. // Make dates with properties first say the date
  4171. if (isDate(value)) {
  4172. base = ' ' + Date.prototype.toUTCString.call(value);
  4173. }
  4174. // Make error with message first say the error
  4175. if (isError(value)) {
  4176. return formatError(value);
  4177. }
  4178. if (keys.length === 0 && (!array || value.length == 0)) {
  4179. return braces[0] + base + braces[1];
  4180. }
  4181. if (recurseTimes < 0) {
  4182. if (isRegExp(value)) {
  4183. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  4184. } else {
  4185. return ctx.stylize('[Object]', 'special');
  4186. }
  4187. }
  4188. ctx.seen.push(value);
  4189. var output;
  4190. if (array) {
  4191. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  4192. } else {
  4193. output = keys.map(function(key) {
  4194. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  4195. });
  4196. }
  4197. ctx.seen.pop();
  4198. return reduceToSingleString(output, base, braces);
  4199. }
  4200. function formatPrimitive(ctx, value) {
  4201. switch (typeof value) {
  4202. case 'undefined':
  4203. return ctx.stylize('undefined', 'undefined');
  4204. case 'string':
  4205. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  4206. .replace(/'/g, "\\'")
  4207. .replace(/\\"/g, '"') + '\'';
  4208. return ctx.stylize(simple, 'string');
  4209. case 'number':
  4210. if (value === 0 && (1/value) === -Infinity) {
  4211. return ctx.stylize('-0', 'number');
  4212. }
  4213. return ctx.stylize('' + value, 'number');
  4214. case 'boolean':
  4215. return ctx.stylize('' + value, 'boolean');
  4216. }
  4217. // For some reason typeof null is "object", so special case here.
  4218. if (value === null) {
  4219. return ctx.stylize('null', 'null');
  4220. }
  4221. }
  4222. function formatError(value) {
  4223. return '[' + Error.prototype.toString.call(value) + ']';
  4224. }
  4225. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  4226. var output = [];
  4227. for (var i = 0, l = value.length; i < l; ++i) {
  4228. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  4229. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4230. String(i), true));
  4231. } else {
  4232. output.push('');
  4233. }
  4234. }
  4235. keys.forEach(function(key) {
  4236. if (!key.match(/^\d+$/)) {
  4237. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  4238. key, true));
  4239. }
  4240. });
  4241. return output;
  4242. }
  4243. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  4244. var name, str;
  4245. if (value.__lookupGetter__) {
  4246. if (value.__lookupGetter__(key)) {
  4247. if (value.__lookupSetter__(key)) {
  4248. str = ctx.stylize('[Getter/Setter]', 'special');
  4249. } else {
  4250. str = ctx.stylize('[Getter]', 'special');
  4251. }
  4252. } else {
  4253. if (value.__lookupSetter__(key)) {
  4254. str = ctx.stylize('[Setter]', 'special');
  4255. }
  4256. }
  4257. }
  4258. if (visibleKeys.indexOf(key) < 0) {
  4259. name = '[' + key + ']';
  4260. }
  4261. if (!str) {
  4262. if (ctx.seen.indexOf(value[key]) < 0) {
  4263. if (recurseTimes === null) {
  4264. str = formatValue(ctx, value[key], null);
  4265. } else {
  4266. str = formatValue(ctx, value[key], recurseTimes - 1);
  4267. }
  4268. if (str.indexOf('\n') > -1) {
  4269. if (array) {
  4270. str = str.split('\n').map(function(line) {
  4271. return ' ' + line;
  4272. }).join('\n').substr(2);
  4273. } else {
  4274. str = '\n' + str.split('\n').map(function(line) {
  4275. return ' ' + line;
  4276. }).join('\n');
  4277. }
  4278. }
  4279. } else {
  4280. str = ctx.stylize('[Circular]', 'special');
  4281. }
  4282. }
  4283. if (typeof name === 'undefined') {
  4284. if (array && key.match(/^\d+$/)) {
  4285. return str;
  4286. }
  4287. name = JSON.stringify('' + key);
  4288. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  4289. name = name.substr(1, name.length - 2);
  4290. name = ctx.stylize(name, 'name');
  4291. } else {
  4292. name = name.replace(/'/g, "\\'")
  4293. .replace(/\\"/g, '"')
  4294. .replace(/(^"|"$)/g, "'");
  4295. name = ctx.stylize(name, 'string');
  4296. }
  4297. }
  4298. return name + ': ' + str;
  4299. }
  4300. function reduceToSingleString(output, base, braces) {
  4301. var numLinesEst = 0;
  4302. var length = output.reduce(function(prev, cur) {
  4303. numLinesEst++;
  4304. if (cur.indexOf('\n') >= 0) numLinesEst++;
  4305. return prev + cur.length + 1;
  4306. }, 0);
  4307. if (length > 60) {
  4308. return braces[0] +
  4309. (base === '' ? '' : base + '\n ') +
  4310. ' ' +
  4311. output.join(',\n ') +
  4312. ' ' +
  4313. braces[1];
  4314. }
  4315. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  4316. }
  4317. function isArray(ar) {
  4318. return Array.isArray(ar) ||
  4319. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  4320. }
  4321. function isRegExp(re) {
  4322. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  4323. }
  4324. function isDate(d) {
  4325. return typeof d === 'object' && objectToString(d) === '[object Date]';
  4326. }
  4327. function isError(e) {
  4328. return typeof e === 'object' && objectToString(e) === '[object Error]';
  4329. }
  4330. function objectToString(o) {
  4331. return Object.prototype.toString.call(o);
  4332. }
  4333. });
  4334. require.register("chai/lib/chai/utils/objDisplay.js", function (exports, module) {
  4335. /*!
  4336. * Chai - flag utility
  4337. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4338. * MIT Licensed
  4339. */
  4340. /*!
  4341. * Module dependancies
  4342. */
  4343. var inspect = require('chai/lib/chai/utils/inspect.js');
  4344. var config = require('chai/lib/chai/config.js');
  4345. /**
  4346. * ### .objDisplay (object)
  4347. *
  4348. * Determines if an object or an array matches
  4349. * criteria to be inspected in-line for error
  4350. * messages or should be truncated.
  4351. *
  4352. * @param {Mixed} javascript object to inspect
  4353. * @name objDisplay
  4354. * @api public
  4355. */
  4356. module.exports = function (obj) {
  4357. var str = inspect(obj)
  4358. , type = Object.prototype.toString.call(obj);
  4359. if (config.truncateThreshold && str.length >= config.truncateThreshold) {
  4360. if (type === '[object Function]') {
  4361. return !obj.name || obj.name === ''
  4362. ? '[Function]'
  4363. : '[Function: ' + obj.name + ']';
  4364. } else if (type === '[object Array]') {
  4365. return '[ Array(' + obj.length + ') ]';
  4366. } else if (type === '[object Object]') {
  4367. var keys = Object.keys(obj)
  4368. , kstr = keys.length > 2
  4369. ? keys.splice(0, 2).join(', ') + ', ...'
  4370. : keys.join(', ');
  4371. return '{ Object (' + kstr + ') }';
  4372. } else {
  4373. return str;
  4374. }
  4375. } else {
  4376. return str;
  4377. }
  4378. };
  4379. });
  4380. require.register("chai/lib/chai/utils/overwriteMethod.js", function (exports, module) {
  4381. /*!
  4382. * Chai - overwriteMethod utility
  4383. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4384. * MIT Licensed
  4385. */
  4386. /**
  4387. * ### overwriteMethod (ctx, name, fn)
  4388. *
  4389. * Overwites an already existing method and provides
  4390. * access to previous function. Must return function
  4391. * to be used for name.
  4392. *
  4393. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  4394. * return function (str) {
  4395. * var obj = utils.flag(this, 'object');
  4396. * if (obj instanceof Foo) {
  4397. * new chai.Assertion(obj.value).to.equal(str);
  4398. * } else {
  4399. * _super.apply(this, arguments);
  4400. * }
  4401. * }
  4402. * });
  4403. *
  4404. * Can also be accessed directly from `chai.Assertion`.
  4405. *
  4406. * chai.Assertion.overwriteMethod('foo', fn);
  4407. *
  4408. * Then can be used as any other assertion.
  4409. *
  4410. * expect(myFoo).to.equal('bar');
  4411. *
  4412. * @param {Object} ctx object whose method is to be overwritten
  4413. * @param {String} name of method to overwrite
  4414. * @param {Function} method function that returns a function to be used for name
  4415. * @name overwriteMethod
  4416. * @api public
  4417. */
  4418. module.exports = function (ctx, name, method) {
  4419. var _method = ctx[name]
  4420. , _super = function () { return this; };
  4421. if (_method && 'function' === typeof _method)
  4422. _super = _method;
  4423. ctx[name] = function () {
  4424. var result = method(_super).apply(this, arguments);
  4425. return result === undefined ? this : result;
  4426. }
  4427. };
  4428. });
  4429. require.register("chai/lib/chai/utils/overwriteProperty.js", function (exports, module) {
  4430. /*!
  4431. * Chai - overwriteProperty utility
  4432. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4433. * MIT Licensed
  4434. */
  4435. /**
  4436. * ### overwriteProperty (ctx, name, fn)
  4437. *
  4438. * Overwites an already existing property getter and provides
  4439. * access to previous value. Must return function to use as getter.
  4440. *
  4441. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  4442. * return function () {
  4443. * var obj = utils.flag(this, 'object');
  4444. * if (obj instanceof Foo) {
  4445. * new chai.Assertion(obj.name).to.equal('bar');
  4446. * } else {
  4447. * _super.call(this);
  4448. * }
  4449. * }
  4450. * });
  4451. *
  4452. *
  4453. * Can also be accessed directly from `chai.Assertion`.
  4454. *
  4455. * chai.Assertion.overwriteProperty('foo', fn);
  4456. *
  4457. * Then can be used as any other assertion.
  4458. *
  4459. * expect(myFoo).to.be.ok;
  4460. *
  4461. * @param {Object} ctx object whose property is to be overwritten
  4462. * @param {String} name of property to overwrite
  4463. * @param {Function} getter function that returns a getter function to be used for name
  4464. * @name overwriteProperty
  4465. * @api public
  4466. */
  4467. module.exports = function (ctx, name, getter) {
  4468. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  4469. , _super = function () {};
  4470. if (_get && 'function' === typeof _get.get)
  4471. _super = _get.get
  4472. Object.defineProperty(ctx, name,
  4473. { get: function () {
  4474. var result = getter(_super).call(this);
  4475. return result === undefined ? this : result;
  4476. }
  4477. , configurable: true
  4478. });
  4479. };
  4480. });
  4481. require.register("chai/lib/chai/utils/overwriteChainableMethod.js", function (exports, module) {
  4482. /*!
  4483. * Chai - overwriteChainableMethod utility
  4484. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4485. * MIT Licensed
  4486. */
  4487. /**
  4488. * ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
  4489. *
  4490. * Overwites an already existing chainable method
  4491. * and provides access to the previous function or
  4492. * property. Must return functions to be used for
  4493. * name.
  4494. *
  4495. * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
  4496. * function (_super) {
  4497. * }
  4498. * , function (_super) {
  4499. * }
  4500. * );
  4501. *
  4502. * Can also be accessed directly from `chai.Assertion`.
  4503. *
  4504. * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
  4505. *
  4506. * Then can be used as any other assertion.
  4507. *
  4508. * expect(myFoo).to.have.length(3);
  4509. * expect(myFoo).to.have.length.above(3);
  4510. *
  4511. * @param {Object} ctx object whose method / property is to be overwritten
  4512. * @param {String} name of method / property to overwrite
  4513. * @param {Function} method function that returns a function to be used for name
  4514. * @param {Function} chainingBehavior function that returns a function to be used for property
  4515. * @name overwriteChainableMethod
  4516. * @api public
  4517. */
  4518. module.exports = function (ctx, name, method, chainingBehavior) {
  4519. var chainableBehavior = ctx.__methods[name];
  4520. var _chainingBehavior = chainableBehavior.chainingBehavior;
  4521. chainableBehavior.chainingBehavior = function () {
  4522. var result = chainingBehavior(_chainingBehavior).call(this);
  4523. return result === undefined ? this : result;
  4524. };
  4525. var _method = chainableBehavior.method;
  4526. chainableBehavior.method = function () {
  4527. var result = method(_method).apply(this, arguments);
  4528. return result === undefined ? this : result;
  4529. };
  4530. };
  4531. });
  4532. require.register("chai/lib/chai/utils/test.js", function (exports, module) {
  4533. /*!
  4534. * Chai - test utility
  4535. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4536. * MIT Licensed
  4537. */
  4538. /*!
  4539. * Module dependancies
  4540. */
  4541. var flag = require('chai/lib/chai/utils/flag.js');
  4542. /**
  4543. * # test(object, expression)
  4544. *
  4545. * Test and object for expression.
  4546. *
  4547. * @param {Object} object (constructed Assertion)
  4548. * @param {Arguments} chai.Assertion.prototype.assert arguments
  4549. */
  4550. module.exports = function (obj, args) {
  4551. var negate = flag(obj, 'negate')
  4552. , expr = args[0];
  4553. return negate ? !expr : expr;
  4554. };
  4555. });
  4556. require.register("chai/lib/chai/utils/transferFlags.js", function (exports, module) {
  4557. /*!
  4558. * Chai - transferFlags utility
  4559. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4560. * MIT Licensed
  4561. */
  4562. /**
  4563. * ### transferFlags(assertion, object, includeAll = true)
  4564. *
  4565. * Transfer all the flags for `assertion` to `object`. If
  4566. * `includeAll` is set to `false`, then the base Chai
  4567. * assertion flags (namely `object`, `ssfi`, and `message`)
  4568. * will not be transferred.
  4569. *
  4570. *
  4571. * var newAssertion = new Assertion();
  4572. * utils.transferFlags(assertion, newAssertion);
  4573. *
  4574. * var anotherAsseriton = new Assertion(myObj);
  4575. * utils.transferFlags(assertion, anotherAssertion, false);
  4576. *
  4577. * @param {Assertion} assertion the assertion to transfer the flags from
  4578. * @param {Object} object the object to transfer the flags to; usually a new assertion
  4579. * @param {Boolean} includeAll
  4580. * @name transferFlags
  4581. * @api private
  4582. */
  4583. module.exports = function (assertion, object, includeAll) {
  4584. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  4585. if (!object.__flags) {
  4586. object.__flags = Object.create(null);
  4587. }
  4588. includeAll = arguments.length === 3 ? includeAll : true;
  4589. for (var flag in flags) {
  4590. if (includeAll ||
  4591. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  4592. object.__flags[flag] = flags[flag];
  4593. }
  4594. }
  4595. };
  4596. });
  4597. require.register("chai/lib/chai/utils/type.js", function (exports, module) {
  4598. /*!
  4599. * Chai - type utility
  4600. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  4601. * MIT Licensed
  4602. */
  4603. /*!
  4604. * Detectable javascript natives
  4605. */
  4606. var natives = {
  4607. '[object Arguments]': 'arguments'
  4608. , '[object Array]': 'array'
  4609. , '[object Date]': 'date'
  4610. , '[object Function]': 'function'
  4611. , '[object Number]': 'number'
  4612. , '[object RegExp]': 'regexp'
  4613. , '[object String]': 'string'
  4614. };
  4615. /**
  4616. * ### type(object)
  4617. *
  4618. * Better implementation of `typeof` detection that can
  4619. * be used cross-browser. Handles the inconsistencies of
  4620. * Array, `null`, and `undefined` detection.
  4621. *
  4622. * utils.type({}) // 'object'
  4623. * utils.type(null) // `null'
  4624. * utils.type(undefined) // `undefined`
  4625. * utils.type([]) // `array`
  4626. *
  4627. * @param {Mixed} object to detect type of
  4628. * @name type
  4629. * @api private
  4630. */
  4631. module.exports = function (obj) {
  4632. var str = Object.prototype.toString.call(obj);
  4633. if (natives[str]) return natives[str];
  4634. if (obj === null) return 'null';
  4635. if (obj === undefined) return 'undefined';
  4636. if (obj === Object(obj)) return 'object';
  4637. return typeof obj;
  4638. };
  4639. });
  4640. if (typeof exports == "object") {
  4641. module.exports = require("chai");
  4642. } else if (typeof define == "function" && define.amd) {
  4643. define("chai", [], function(){ return require("chai"); });
  4644. } else {
  4645. (this || window)["chai"] = require("chai");
  4646. }
  4647. })()