4 * Require the given path.
7 * @return {Object} exports
11 function require(path, parent, orig) {
12 var resolved = require.resolve(path);
15 if (null == resolved) {
17 parent = parent || 'root';
18 var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
25 var module = require.modules[resolved];
27 // perform real require()
28 // by invoking the module's
29 // registered function
30 if (!module.exports) {
32 module.client = module.component = true;
33 module.call(this, module.exports, require.relative(resolved), module);
36 return module.exports;
60 * @param {String} path
61 * @return {String} path or null
65 require.resolve = function(path) {
66 if (path.charAt(0) === '/') path = path.slice(1);
76 for (var i = 0; i < paths.length; i++) {
78 if (require.modules.hasOwnProperty(path)) return path;
79 if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
84 * Normalize `path` relative to the current path.
86 * @param {String} curr
87 * @param {String} path
92 require.normalize = function(curr, path) {
95 if ('.' != path.charAt(0)) return path;
97 curr = curr.split('/');
98 path = path.split('/');
100 for (var i = 0; i < path.length; ++i) {
101 if ('..' == path[i]) {
103 } else if ('.' != path[i] && '' != path[i]) {
108 return curr.concat(segs).join('/');
112 * Register module at `path` with callback `definition`.
114 * @param {String} path
115 * @param {Function} definition
119 require.register = function(path, definition) {
120 require.modules[path] = definition;
124 * Alias a module definition.
126 * @param {String} from
131 require.alias = function(from, to) {
132 if (!require.modules.hasOwnProperty(from)) {
133 throw new Error('Failed to alias "' + from + '", it does not exist');
135 require.aliases[to] = from;
139 * Return a require function relative to the `parent` path.
141 * @param {String} parent
146 require.relative = function(parent) {
147 var p = require.normalize(parent, '..');
150 * lastIndexOf helper.
153 function lastIndexOf(arr, obj) {
156 if (arr[i] === obj) return i;
162 * The relative require() itself.
165 function localRequire(path) {
166 var resolved = localRequire.resolve(path);
167 return require(resolved, parent, path);
171 * Resolve relative to the parent.
174 localRequire.resolve = function(path) {
175 var c = path.charAt(0);
176 if ('/' == c) return path.slice(1);
177 if ('.' == c) return require.normalize(p, path);
179 // resolve deps by returning
180 // the dep in the nearest "deps"
182 var segs = parent.split('/');
183 var i = lastIndexOf(segs, 'deps') + 1;
185 path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
190 * Check if module is defined at `path`.
193 localRequire.exists = function(path) {
194 return require.modules.hasOwnProperty(localRequire.resolve(path));
199 require.register("chaijs-assertion-error/index.js", function(exports, require, module){
202 * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
207 * Return a function that will copy properties from
208 * one object to another excluding any originally
209 * listed. Returned function will create a new `{}`.
211 * @param {String} excluded properties ...
215 function exclude () {
216 var excludes = [].slice.call(arguments);
218 function excludeProps (res, obj) {
219 Object.keys(obj).forEach(function (key) {
220 if (!~excludes.indexOf(key)) res[key] = obj[key];
224 return function extendExclude () {
225 var args = [].slice.call(arguments)
229 for (; i < args.length; i++) {
230 excludeProps(res, args[i]);
241 module.exports = AssertionError;
246 * An extension of the JavaScript `Error` constructor for
247 * assertion and validation scenarios.
249 * @param {String} message
250 * @param {Object} properties to include (optional)
251 * @param {callee} start stack function (optional)
254 function AssertionError (message, _props, ssf) {
255 var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
256 , props = extend(_props || {});
259 this.message = message || 'Unspecified AssertionError';
260 this.showDiff = false;
262 // copy from properties
263 for (var key in props) {
264 this[key] = props[key];
267 // capture stack trace
268 ssf = ssf || arguments.callee;
269 if (ssf && Error.captureStackTrace) {
270 Error.captureStackTrace(this, ssf);
275 * Inherit from Error.prototype
278 AssertionError.prototype = Object.create(Error.prototype);
281 * Statically set name
284 AssertionError.prototype.name = 'AssertionError';
287 * Ensure correct constructor
290 AssertionError.prototype.constructor = AssertionError;
293 * Allow errors to be converted to JSON for static transfer.
295 * @param {Boolean} include stack (default: `true`)
296 * @return {Object} object that can be `JSON.stringify`
299 AssertionError.prototype.toJSON = function (stack) {
300 var extend = exclude('constructor', 'toJSON', 'stack')
301 , props = extend({ name: this.name }, this);
303 // include stack if exists and not turned off
304 if (false !== stack && this.stack) {
305 props.stack = this.stack;
312 require.register("chai/index.js", function(exports, require, module){
313 module.exports = require('./lib/chai');
316 require.register("chai/lib/chai.js", function(exports, require, module){
319 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
324 , exports = module.exports = {};
330 exports.version = '1.7.0';
336 exports.AssertionError = require('assertion-error');
339 * Utils for plugins (not exported)
342 var util = require('./chai/utils');
347 * Provides a way to extend the internals of Chai
350 * @returns {this} for chaining
354 exports.use = function (fn) {
355 if (!~used.indexOf(fn)) {
364 * Primary `Assertion` prototype
367 var assertion = require('./chai/assertion');
368 exports.use(assertion);
374 var core = require('./chai/core/assertions');
381 var expect = require('./chai/interface/expect');
388 var should = require('./chai/interface/should');
395 var assert = require('./chai/interface/assert');
399 require.register("chai/lib/chai/assertion.js", function(exports, require, module){
403 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
407 module.exports = function (_chai, util) {
409 * Module dependencies.
412 var AssertionError = _chai.AssertionError
419 _chai.Assertion = Assertion;
422 * Assertion Constructor
424 * Creates object for chaining.
429 function Assertion (obj, msg, stack) {
430 flag(this, 'ssfi', stack || arguments.callee);
431 flag(this, 'object', obj);
432 flag(this, 'message', msg);
436 * ### Assertion.includeStack
438 * User configurable property, influences whether stack trace
439 * is included in Assertion error message. Default of false
440 * suppresses stack trace in the error message
442 * Assertion.includeStack = true; // enable stack on error
447 Assertion.includeStack = false;
450 * ### Assertion.showDiff
452 * User configurable property, influences whether or not
453 * the `showDiff` flag should be included in the thrown
454 * AssertionErrors. `false` will always be `false`; `true`
455 * will be true when the assertion has requested a diff
461 Assertion.showDiff = true;
463 Assertion.addProperty = function (name, fn) {
464 util.addProperty(this.prototype, name, fn);
467 Assertion.addMethod = function (name, fn) {
468 util.addMethod(this.prototype, name, fn);
471 Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
472 util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
475 Assertion.overwriteProperty = function (name, fn) {
476 util.overwriteProperty(this.prototype, name, fn);
479 Assertion.overwriteMethod = function (name, fn) {
480 util.overwriteMethod(this.prototype, name, fn);
484 * ### .assert(expression, message, negateMessage, expected, actual)
486 * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
489 * @param {Philosophical} expression to be tested
490 * @param {String} message to display if fails
491 * @param {String} negatedMessage to display if negated expression fails
492 * @param {Mixed} expected value (remember to check for negation)
493 * @param {Mixed} actual (optional) will default to `this.obj`
497 Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
498 var ok = util.test(this, arguments);
499 if (true !== showDiff) showDiff = false;
500 if (true !== Assertion.showDiff) showDiff = false;
503 var msg = util.getMessage(this, arguments)
504 , actual = util.getActual(this, arguments);
505 throw new AssertionError(msg, {
509 }, (Assertion.includeStack) ? this.assert : flag(this, 'ssfi'));
516 * Quick reference to stored `actual` value for plugin developers.
521 Object.defineProperty(Assertion.prototype, '_obj',
523 return flag(this, 'object');
525 , set: function (val) {
526 flag(this, 'object', val);
532 require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
536 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
540 module.exports = function (chai, _) {
541 var Assertion = chai.Assertion
542 , toString = Object.prototype.toString
546 * ### Language Chains
548 * The following are provide as chainable getters to
549 * improve the readability of your assertions. They
550 * do not provide an testing capability unless they
551 * have been overwritten by a plugin.
567 * @name language chains
572 , 'is', 'and', 'have'
573 , 'with', 'that', 'at'
574 , 'of', 'same' ].forEach(function (chain) {
575 Assertion.addProperty(chain, function () {
583 * Negates any of assertions following in the chain.
585 * expect(foo).to.not.equal('bar');
586 * expect(goodFn).to.not.throw(Error);
587 * expect({ foo: 'baz' }).to.have.property('foo')
588 * .and.not.equal('bar');
594 Assertion.addProperty('not', function () {
595 flag(this, 'negate', true);
601 * Sets the `deep` flag, later used by the `equal` and
602 * `property` assertions.
604 * expect(foo).to.deep.equal({ bar: 'baz' });
605 * expect({ foo: { bar: { baz: 'quux' } } })
606 * .to.have.deep.property('foo.bar.baz', 'quux');
612 Assertion.addProperty('deep', function () {
613 flag(this, 'deep', true);
619 * The `a` and `an` assertions are aliases that can be
620 * used either as language chains or to assert a value's
624 * expect('test').to.be.a('string');
625 * expect({ foo: 'bar' }).to.be.an('object');
626 * expect(null).to.be.a('null');
627 * expect(undefined).to.be.an('undefined');
630 * expect(foo).to.be.an.instanceof(Foo);
634 * @param {String} type
635 * @param {String} message _optional_
639 function an (type, msg) {
640 if (msg) flag(this, 'message', msg);
641 type = type.toLowerCase();
642 var obj = flag(this, 'object')
643 , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
647 , 'expected #{this} to be ' + article + type
648 , 'expected #{this} not to be ' + article + type
652 Assertion.addChainableMethod('an', an);
653 Assertion.addChainableMethod('a', an);
656 * ### .include(value)
658 * The `include` and `contain` assertions can be used as either property
659 * based language chains or as methods to assert the inclusion of an object
660 * in an array or a substring in a string. When used as language chains,
661 * they toggle the `contain` flag for the `keys` assertion.
663 * expect([1,2,3]).to.include(2);
664 * expect('foobar').to.contain('foo');
665 * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
669 * @param {Object|String|Number} obj
670 * @param {String} message _optional_
674 function includeChainingBehavior () {
675 flag(this, 'contains', true);
678 function include (val, msg) {
679 if (msg) flag(this, 'message', msg);
680 var obj = flag(this, 'object')
683 , 'expected #{this} to include ' + _.inspect(val)
684 , 'expected #{this} to not include ' + _.inspect(val));
687 Assertion.addChainableMethod('include', include, includeChainingBehavior);
688 Assertion.addChainableMethod('contain', include, includeChainingBehavior);
693 * Asserts that the target is truthy.
695 * expect('everthing').to.be.ok;
696 * expect(1).to.be.ok;
697 * expect(false).to.not.be.ok;
698 * expect(undefined).to.not.be.ok;
699 * expect(null).to.not.be.ok;
705 Assertion.addProperty('ok', function () {
708 , 'expected #{this} to be truthy'
709 , 'expected #{this} to be falsy');
715 * Asserts that the target is `true`.
717 * expect(true).to.be.true;
718 * expect(1).to.not.be.true;
724 Assertion.addProperty('true', function () {
726 true === flag(this, 'object')
727 , 'expected #{this} to be true'
728 , 'expected #{this} to be false'
729 , this.negate ? false : true
736 * Asserts that the target is `false`.
738 * expect(false).to.be.false;
739 * expect(0).to.not.be.false;
745 Assertion.addProperty('false', function () {
747 false === flag(this, 'object')
748 , 'expected #{this} to be false'
749 , 'expected #{this} to be true'
750 , this.negate ? true : false
757 * Asserts that the target is `null`.
759 * expect(null).to.be.null;
760 * expect(undefined).not.to.be.null;
766 Assertion.addProperty('null', function () {
768 null === flag(this, 'object')
769 , 'expected #{this} to be null'
770 , 'expected #{this} not to be null'
777 * Asserts that the target is `undefined`.
779 * expect(undefined).to.be.undefined;
780 * expect(null).to.not.be.undefined;
786 Assertion.addProperty('undefined', function () {
788 undefined === flag(this, 'object')
789 , 'expected #{this} to be undefined'
790 , 'expected #{this} not to be undefined'
797 * Asserts that the target is neither `null` nor `undefined`.
803 * expect(foo).to.exist;
804 * expect(bar).to.not.exist;
805 * expect(baz).to.not.exist;
811 Assertion.addProperty('exist', function () {
813 null != flag(this, 'object')
814 , 'expected #{this} to exist'
815 , 'expected #{this} to not exist'
823 * Asserts that the target's length is `0`. For arrays, it checks
824 * the `length` property. For objects, it gets the count of
827 * expect([]).to.be.empty;
828 * expect('').to.be.empty;
829 * expect({}).to.be.empty;
835 Assertion.addProperty('empty', function () {
836 var obj = flag(this, 'object')
839 if (Array.isArray(obj) || 'string' === typeof object) {
840 expected = obj.length;
841 } else if (typeof obj === 'object') {
842 expected = Object.keys(obj).length;
847 , 'expected #{this} to be empty'
848 , 'expected #{this} not to be empty'
855 * Asserts that the target is an arguments object.
858 * expect(arguments).to.be.arguments;
866 function checkArguments () {
867 var obj = flag(this, 'object')
868 , type = Object.prototype.toString.call(obj);
870 '[object Arguments]' === type
871 , 'expected #{this} to be arguments but got ' + type
872 , 'expected #{this} to not be arguments'
876 Assertion.addProperty('arguments', checkArguments);
877 Assertion.addProperty('Arguments', checkArguments);
882 * Asserts that the target is strictly equal (`===`) to `value`.
883 * Alternately, if the `deep` flag is set, asserts that
884 * the target is deeply equal to `value`.
886 * expect('hello').to.equal('hello');
887 * expect(42).to.equal(42);
888 * expect(1).to.not.equal(true);
889 * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
890 * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
896 * @param {Mixed} value
897 * @param {String} message _optional_
901 function assertEqual (val, msg) {
902 if (msg) flag(this, 'message', msg);
903 var obj = flag(this, 'object');
904 if (flag(this, 'deep')) {
905 return this.eql(val);
909 , 'expected #{this} to equal #{exp}'
910 , 'expected #{this} to not equal #{exp}'
918 Assertion.addMethod('equal', assertEqual);
919 Assertion.addMethod('equals', assertEqual);
920 Assertion.addMethod('eq', assertEqual);
925 * Asserts that the target is deeply equal to `value`.
927 * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
928 * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
932 * @param {Mixed} value
933 * @param {String} message _optional_
937 function assertEql(obj, msg) {
938 if (msg) flag(this, 'message', msg);
940 _.eql(obj, flag(this, 'object'))
941 , 'expected #{this} to deeply equal #{exp}'
942 , 'expected #{this} to not deeply equal #{exp}'
949 Assertion.addMethod('eql', assertEql);
950 Assertion.addMethod('eqls', assertEql);
955 * Asserts that the target is greater than `value`.
957 * expect(10).to.be.above(5);
959 * Can also be used in conjunction with `length` to
960 * assert a minimum length. The benefit being a
961 * more informative error message than if the length
962 * was supplied directly.
964 * expect('foo').to.have.length.above(2);
965 * expect([ 1, 2, 3 ]).to.have.length.above(2);
970 * @param {Number} value
971 * @param {String} message _optional_
975 function assertAbove (n, msg) {
976 if (msg) flag(this, 'message', msg);
977 var obj = flag(this, 'object');
978 if (flag(this, 'doLength')) {
979 new Assertion(obj, msg).to.have.property('length');
980 var len = obj.length;
983 , 'expected #{this} to have a length above #{exp} but got #{act}'
984 , 'expected #{this} to not have a length above #{exp}'
991 , 'expected #{this} to be above ' + n
992 , 'expected #{this} to be at most ' + n
997 Assertion.addMethod('above', assertAbove);
998 Assertion.addMethod('gt', assertAbove);
999 Assertion.addMethod('greaterThan', assertAbove);
1004 * Asserts that the target is greater than or equal to `value`.
1006 * expect(10).to.be.at.least(10);
1008 * Can also be used in conjunction with `length` to
1009 * assert a minimum length. The benefit being a
1010 * more informative error message than if the length
1011 * was supplied directly.
1013 * expect('foo').to.have.length.of.at.least(2);
1014 * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
1018 * @param {Number} value
1019 * @param {String} message _optional_
1023 function assertLeast (n, msg) {
1024 if (msg) flag(this, 'message', msg);
1025 var obj = flag(this, 'object');
1026 if (flag(this, 'doLength')) {
1027 new Assertion(obj, msg).to.have.property('length');
1028 var len = obj.length;
1031 , 'expected #{this} to have a length at least #{exp} but got #{act}'
1032 , 'expected #{this} to have a length below #{exp}'
1039 , 'expected #{this} to be at least ' + n
1040 , 'expected #{this} to be below ' + n
1045 Assertion.addMethod('least', assertLeast);
1046 Assertion.addMethod('gte', assertLeast);
1051 * Asserts that the target is less than `value`.
1053 * expect(5).to.be.below(10);
1055 * Can also be used in conjunction with `length` to
1056 * assert a maximum length. The benefit being a
1057 * more informative error message than if the length
1058 * was supplied directly.
1060 * expect('foo').to.have.length.below(4);
1061 * expect([ 1, 2, 3 ]).to.have.length.below(4);
1066 * @param {Number} value
1067 * @param {String} message _optional_
1071 function assertBelow (n, msg) {
1072 if (msg) flag(this, 'message', msg);
1073 var obj = flag(this, 'object');
1074 if (flag(this, 'doLength')) {
1075 new Assertion(obj, msg).to.have.property('length');
1076 var len = obj.length;
1079 , 'expected #{this} to have a length below #{exp} but got #{act}'
1080 , 'expected #{this} to not have a length below #{exp}'
1087 , 'expected #{this} to be below ' + n
1088 , 'expected #{this} to be at least ' + n
1093 Assertion.addMethod('below', assertBelow);
1094 Assertion.addMethod('lt', assertBelow);
1095 Assertion.addMethod('lessThan', assertBelow);
1100 * Asserts that the target is less than or equal to `value`.
1102 * expect(5).to.be.at.most(5);
1104 * Can also be used in conjunction with `length` to
1105 * assert a maximum length. The benefit being a
1106 * more informative error message than if the length
1107 * was supplied directly.
1109 * expect('foo').to.have.length.of.at.most(4);
1110 * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
1114 * @param {Number} value
1115 * @param {String} message _optional_
1119 function assertMost (n, msg) {
1120 if (msg) flag(this, 'message', msg);
1121 var obj = flag(this, 'object');
1122 if (flag(this, 'doLength')) {
1123 new Assertion(obj, msg).to.have.property('length');
1124 var len = obj.length;
1127 , 'expected #{this} to have a length at most #{exp} but got #{act}'
1128 , 'expected #{this} to have a length above #{exp}'
1135 , 'expected #{this} to be at most ' + n
1136 , 'expected #{this} to be above ' + n
1141 Assertion.addMethod('most', assertMost);
1142 Assertion.addMethod('lte', assertMost);
1145 * ### .within(start, finish)
1147 * Asserts that the target is within a range.
1149 * expect(7).to.be.within(5,10);
1151 * Can also be used in conjunction with `length` to
1152 * assert a length range. The benefit being a
1153 * more informative error message than if the length
1154 * was supplied directly.
1156 * expect('foo').to.have.length.within(2,4);
1157 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1160 * @param {Number} start lowerbound inclusive
1161 * @param {Number} finish upperbound inclusive
1162 * @param {String} message _optional_
1166 Assertion.addMethod('within', function (start, finish, msg) {
1167 if (msg) flag(this, 'message', msg);
1168 var obj = flag(this, 'object')
1169 , range = start + '..' + finish;
1170 if (flag(this, 'doLength')) {
1171 new Assertion(obj, msg).to.have.property('length');
1172 var len = obj.length;
1174 len >= start && len <= finish
1175 , 'expected #{this} to have a length within ' + range
1176 , 'expected #{this} to not have a length within ' + range
1180 obj >= start && obj <= finish
1181 , 'expected #{this} to be within ' + range
1182 , 'expected #{this} to not be within ' + range
1188 * ### .instanceof(constructor)
1190 * Asserts that the target is an instance of `constructor`.
1192 * var Tea = function (name) { this.name = name; }
1193 * , Chai = new Tea('chai');
1195 * expect(Chai).to.be.an.instanceof(Tea);
1196 * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
1199 * @param {Constructor} constructor
1200 * @param {String} message _optional_
1205 function assertInstanceOf (constructor, msg) {
1206 if (msg) flag(this, 'message', msg);
1207 var name = _.getName(constructor);
1209 flag(this, 'object') instanceof constructor
1210 , 'expected #{this} to be an instance of ' + name
1211 , 'expected #{this} to not be an instance of ' + name
1215 Assertion.addMethod('instanceof', assertInstanceOf);
1216 Assertion.addMethod('instanceOf', assertInstanceOf);
1219 * ### .property(name, [value])
1221 * Asserts that the target has a property `name`, optionally asserting that
1222 * the value of that property is strictly equal to `value`.
1223 * If the `deep` flag is set, you can use dot- and bracket-notation for deep
1224 * references into objects and arrays.
1226 * // simple referencing
1227 * var obj = { foo: 'bar' };
1228 * expect(obj).to.have.property('foo');
1229 * expect(obj).to.have.property('foo', 'bar');
1231 * // deep referencing
1233 * green: { tea: 'matcha' }
1234 * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
1237 * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
1238 * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
1239 * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
1241 * You can also use an array as the starting point of a `deep.property`
1242 * assertion, or traverse nested arrays.
1245 * [ 'chai', 'matcha', 'konacha' ]
1246 * , [ { tea: 'chai' }
1247 * , { tea: 'matcha' }
1248 * , { tea: 'konacha' } ]
1251 * expect(arr).to.have.deep.property('[0][1]', 'matcha');
1252 * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
1254 * Furthermore, `property` changes the subject of the assertion
1255 * to be the value of that property from the original object. This
1256 * permits for further chainable assertions on that property.
1258 * expect(obj).to.have.property('foo')
1259 * .that.is.a('string');
1260 * expect(deepObj).to.have.property('green')
1261 * .that.is.an('object')
1262 * .that.deep.equals({ tea: 'matcha' });
1263 * expect(deepObj).to.have.property('teas')
1264 * .that.is.an('array')
1265 * .with.deep.property('[2]')
1266 * .that.deep.equals({ tea: 'konacha' });
1269 * @alias deep.property
1270 * @param {String} name
1271 * @param {Mixed} value (optional)
1272 * @param {String} message _optional_
1273 * @returns value of property for chaining
1277 Assertion.addMethod('property', function (name, val, msg) {
1278 if (msg) flag(this, 'message', msg);
1280 var descriptor = flag(this, 'deep') ? 'deep property ' : 'property '
1281 , negate = flag(this, 'negate')
1282 , obj = flag(this, 'object')
1283 , value = flag(this, 'deep')
1284 ? _.getPathValue(name, obj)
1287 if (negate && undefined !== val) {
1288 if (undefined === value) {
1289 msg = (msg != null) ? msg + ': ' : '';
1290 throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
1295 , 'expected #{this} to have a ' + descriptor + _.inspect(name)
1296 , 'expected #{this} to not have ' + descriptor + _.inspect(name));
1299 if (undefined !== val) {
1302 , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
1303 , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
1309 flag(this, 'object', value);
1314 * ### .ownProperty(name)
1316 * Asserts that the target has an own property `name`.
1318 * expect('test').to.have.ownProperty('length');
1321 * @alias haveOwnProperty
1322 * @param {String} name
1323 * @param {String} message _optional_
1327 function assertOwnProperty (name, msg) {
1328 if (msg) flag(this, 'message', msg);
1329 var obj = flag(this, 'object');
1331 obj.hasOwnProperty(name)
1332 , 'expected #{this} to have own property ' + _.inspect(name)
1333 , 'expected #{this} to not have own property ' + _.inspect(name)
1337 Assertion.addMethod('ownProperty', assertOwnProperty);
1338 Assertion.addMethod('haveOwnProperty', assertOwnProperty);
1341 * ### .length(value)
1343 * Asserts that the target's `length` property has
1344 * the expected value.
1346 * expect([ 1, 2, 3]).to.have.length(3);
1347 * expect('foobar').to.have.length(6);
1349 * Can also be used as a chain precursor to a value
1350 * comparison for the length property.
1352 * expect('foo').to.have.length.above(2);
1353 * expect([ 1, 2, 3 ]).to.have.length.above(2);
1354 * expect('foo').to.have.length.below(4);
1355 * expect([ 1, 2, 3 ]).to.have.length.below(4);
1356 * expect('foo').to.have.length.within(2,4);
1357 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1361 * @param {Number} length
1362 * @param {String} message _optional_
1366 function assertLengthChain () {
1367 flag(this, 'doLength', true);
1370 function assertLength (n, msg) {
1371 if (msg) flag(this, 'message', msg);
1372 var obj = flag(this, 'object');
1373 new Assertion(obj, msg).to.have.property('length');
1374 var len = obj.length;
1378 , 'expected #{this} to have a length of #{exp} but got #{act}'
1379 , 'expected #{this} to not have a length of #{act}'
1385 Assertion.addChainableMethod('length', assertLength, assertLengthChain);
1386 Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
1389 * ### .match(regexp)
1391 * Asserts that the target matches a regular expression.
1393 * expect('foobar').to.match(/^foo/);
1396 * @param {RegExp} RegularExpression
1397 * @param {String} message _optional_
1401 Assertion.addMethod('match', function (re, msg) {
1402 if (msg) flag(this, 'message', msg);
1403 var obj = flag(this, 'object');
1406 , 'expected #{this} to match ' + re
1407 , 'expected #{this} not to match ' + re
1412 * ### .string(string)
1414 * Asserts that the string target contains another string.
1416 * expect('foobar').to.have.string('bar');
1419 * @param {String} string
1420 * @param {String} message _optional_
1424 Assertion.addMethod('string', function (str, msg) {
1425 if (msg) flag(this, 'message', msg);
1426 var obj = flag(this, 'object');
1427 new Assertion(obj, msg).is.a('string');
1431 , 'expected #{this} to contain ' + _.inspect(str)
1432 , 'expected #{this} to not contain ' + _.inspect(str)
1438 * ### .keys(key1, [key2], [...])
1440 * Asserts that the target has exactly the given keys, or
1441 * asserts the inclusion of some keys when using the
1442 * `include` or `contain` modifiers.
1444 * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
1445 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
1449 * @param {String...|Array} keys
1453 function assertKeys (keys) {
1454 var obj = flag(this, 'object')
1458 keys = keys instanceof Array
1460 : Array.prototype.slice.call(arguments);
1462 if (!keys.length) throw new Error('keys required');
1464 var actual = Object.keys(obj)
1465 , len = keys.length;
1468 ok = keys.every(function(key){
1469 return ~actual.indexOf(key);
1473 if (!flag(this, 'negate') && !flag(this, 'contains')) {
1474 ok = ok && keys.length == actual.length;
1479 keys = keys.map(function(key){
1480 return _.inspect(key);
1482 var last = keys.pop();
1483 str = keys.join(', ') + ', and ' + last;
1485 str = _.inspect(keys[0]);
1489 str = (len > 1 ? 'keys ' : 'key ') + str;
1492 str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
1497 , 'expected #{this} to ' + str
1498 , 'expected #{this} to not ' + str
1502 Assertion.addMethod('keys', assertKeys);
1503 Assertion.addMethod('key', assertKeys);
1506 * ### .throw(constructor)
1508 * Asserts that the function target will throw a specific error, or specific type of error
1509 * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
1510 * for the error's message.
1512 * var err = new ReferenceError('This is a bad function.');
1513 * var fn = function () { throw err; }
1514 * expect(fn).to.throw(ReferenceError);
1515 * expect(fn).to.throw(Error);
1516 * expect(fn).to.throw(/bad function/);
1517 * expect(fn).to.not.throw('good function');
1518 * expect(fn).to.throw(ReferenceError, /bad function/);
1519 * expect(fn).to.throw(err);
1520 * expect(fn).to.not.throw(new RangeError('Out of range.'));
1522 * Please note that when a throw expectation is negated, it will check each
1523 * parameter independently, starting with error constructor type. The appropriate way
1524 * to check for the existence of a type of error but for a message that does not match
1527 * expect(fn).to.throw(ReferenceError)
1528 * .and.not.throw(/good function/);
1533 * @param {ErrorConstructor} constructor
1534 * @param {String|RegExp} expected error message
1535 * @param {String} message _optional_
1536 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
1540 function assertThrows (constructor, errMsg, msg) {
1541 if (msg) flag(this, 'message', msg);
1542 var obj = flag(this, 'object');
1543 new Assertion(obj, msg).is.a('function');
1546 , desiredError = null
1548 , thrownError = null;
1550 if (arguments.length === 0) {
1553 } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
1554 errMsg = constructor;
1556 } else if (constructor && constructor instanceof Error) {
1557 desiredError = constructor;
1560 } else if (typeof constructor === 'function') {
1561 name = (new constructor()).name;
1569 // first, check desired error
1572 err === desiredError
1573 , 'expected #{this} to throw #{exp} but #{act} was thrown'
1574 , 'expected #{this} to not throw #{exp}'
1581 // next, check constructor
1584 err instanceof constructor
1585 , 'expected #{this} to throw #{exp} but #{act} was thrown'
1586 , 'expected #{this} to not throw #{exp} but #{act} was thrown'
1591 if (!errMsg) return this;
1593 // next, check message
1594 var message = 'object' === _.type(err) && "message" in err
1598 if ((message != null) && errMsg && errMsg instanceof RegExp) {
1600 errMsg.exec(message)
1601 , 'expected #{this} to throw error matching #{exp} but got #{act}'
1602 , 'expected #{this} to throw error not matching #{exp}'
1608 } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
1610 ~message.indexOf(errMsg)
1611 , 'expected #{this} to throw error including #{exp} but got #{act}'
1612 , 'expected #{this} to throw error not including #{act}'
1624 var actuallyGot = ''
1625 , expectedThrown = name !== null
1628 ? '#{exp}' //_.inspect(desiredError)
1632 actuallyGot = ' but #{act} was thrown'
1637 , 'expected #{this} to throw ' + expectedThrown + actuallyGot
1638 , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
1644 Assertion.addMethod('throw', assertThrows);
1645 Assertion.addMethod('throws', assertThrows);
1646 Assertion.addMethod('Throw', assertThrows);
1649 * ### .respondTo(method)
1651 * Asserts that the object or class target will respond to a method.
1653 * Klass.prototype.bar = function(){};
1654 * expect(Klass).to.respondTo('bar');
1655 * expect(obj).to.respondTo('bar');
1657 * To check if a constructor will respond to a static function,
1658 * set the `itself` flag.
1660 * Klass.baz = function(){};
1661 * expect(Klass).itself.to.respondTo('baz');
1664 * @param {String} method
1665 * @param {String} message _optional_
1669 Assertion.addMethod('respondTo', function (method, msg) {
1670 if (msg) flag(this, 'message', msg);
1671 var obj = flag(this, 'object')
1672 , itself = flag(this, 'itself')
1673 , context = ('function' === _.type(obj) && !itself)
1674 ? obj.prototype[method]
1678 'function' === typeof context
1679 , 'expected #{this} to respond to ' + _.inspect(method)
1680 , 'expected #{this} to not respond to ' + _.inspect(method)
1687 * Sets the `itself` flag, later used by the `respondTo` assertion.
1690 * Foo.bar = function() {}
1691 * Foo.prototype.baz = function() {}
1693 * expect(Foo).itself.to.respondTo('bar');
1694 * expect(Foo).itself.not.to.respondTo('baz');
1700 Assertion.addProperty('itself', function () {
1701 flag(this, 'itself', true);
1705 * ### .satisfy(method)
1707 * Asserts that the target passes a given truth test.
1709 * expect(1).to.satisfy(function(num) { return num > 0; });
1712 * @param {Function} matcher
1713 * @param {String} message _optional_
1717 Assertion.addMethod('satisfy', function (matcher, msg) {
1718 if (msg) flag(this, 'message', msg);
1719 var obj = flag(this, 'object');
1722 , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
1723 , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
1724 , this.negate ? false : true
1730 * ### .closeTo(expected, delta)
1732 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
1734 * expect(1.5).to.be.closeTo(1, 0.5);
1737 * @param {Number} expected
1738 * @param {Number} delta
1739 * @param {String} message _optional_
1743 Assertion.addMethod('closeTo', function (expected, delta, msg) {
1744 if (msg) flag(this, 'message', msg);
1745 var obj = flag(this, 'object');
1747 Math.abs(obj - expected) <= delta
1748 , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
1749 , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
1753 function isSubsetOf(subset, superset) {
1754 return subset.every(function(elem) {
1755 return superset.indexOf(elem) !== -1;
1762 * Asserts that the target is a superset of `set`,
1763 * or that the target and `set` have the same members.
1765 * expect([1, 2, 3]).to.include.members([3, 2]);
1766 * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
1768 * expect([4, 2]).to.have.members([2, 4]);
1769 * expect([5, 2]).to.not.have.members([5, 2, 1]);
1772 * @param {Array} set
1773 * @param {String} message _optional_
1777 Assertion.addMethod('members', function (subset, msg) {
1778 if (msg) flag(this, 'message', msg);
1779 var obj = flag(this, 'object');
1781 new Assertion(obj).to.be.an('array');
1782 new Assertion(subset).to.be.an('array');
1784 if (flag(this, 'contains')) {
1786 isSubsetOf(subset, obj)
1787 , 'expected #{this} to be a superset of #{act}'
1788 , 'expected #{this} to not be a superset of #{act}'
1795 isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
1796 , 'expected #{this} to have the same members as #{act}'
1797 , 'expected #{this} to not have the same members as #{act}'
1805 require.register("chai/lib/chai/interface/assert.js", function(exports, require, module){
1808 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
1813 module.exports = function (chai, util) {
1816 * Chai dependencies.
1819 var Assertion = chai.Assertion
1827 * ### assert(expression, message)
1829 * Write your own test expressions.
1831 * assert('foo' !== 'bar', 'foo is not bar');
1832 * assert(Array.isArray([]), 'empty arrays are arrays');
1834 * @param {Mixed} expression to test for truthiness
1835 * @param {String} message to display on error
1840 var assert = chai.assert = function (express, errmsg) {
1841 var test = new Assertion(null);
1845 , '[ negation message unavailable ]'
1850 * ### .fail(actual, expected, [message], [operator])
1852 * Throw a failure. Node.js `assert` module-compatible.
1855 * @param {Mixed} actual
1856 * @param {Mixed} expected
1857 * @param {String} message
1858 * @param {String} operator
1862 assert.fail = function (actual, expected, message, operator) {
1863 throw new chai.AssertionError({
1865 , expected: expected
1867 , operator: operator
1868 , stackStartFunction: assert.fail
1873 * ### .ok(object, [message])
1875 * Asserts that `object` is truthy.
1877 * assert.ok('everything', 'everything is ok');
1878 * assert.ok(false, 'this will fail');
1881 * @param {Mixed} object to test
1882 * @param {String} message
1886 assert.ok = function (val, msg) {
1887 new Assertion(val, msg).is.ok;
1891 * ### .notOk(object, [message])
1893 * Asserts that `object` is falsy.
1895 * assert.notOk('everything', 'this will fail');
1896 * assert.notOk(false, 'this will pass');
1899 * @param {Mixed} object to test
1900 * @param {String} message
1904 assert.notOk = function (val, msg) {
1905 new Assertion(val, msg).is.not.ok;
1909 * ### .equal(actual, expected, [message])
1911 * Asserts non-strict equality (`==`) of `actual` and `expected`.
1913 * assert.equal(3, '3', '== coerces values to strings');
1916 * @param {Mixed} actual
1917 * @param {Mixed} expected
1918 * @param {String} message
1922 assert.equal = function (act, exp, msg) {
1923 var test = new Assertion(act, msg);
1926 exp == flag(test, 'object')
1927 , 'expected #{this} to equal #{exp}'
1928 , 'expected #{this} to not equal #{act}'
1935 * ### .notEqual(actual, expected, [message])
1937 * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
1939 * assert.notEqual(3, 4, 'these numbers are not equal');
1942 * @param {Mixed} actual
1943 * @param {Mixed} expected
1944 * @param {String} message
1948 assert.notEqual = function (act, exp, msg) {
1949 var test = new Assertion(act, msg);
1952 exp != flag(test, 'object')
1953 , 'expected #{this} to not equal #{exp}'
1954 , 'expected #{this} to equal #{act}'
1961 * ### .strictEqual(actual, expected, [message])
1963 * Asserts strict equality (`===`) of `actual` and `expected`.
1965 * assert.strictEqual(true, true, 'these booleans are strictly equal');
1968 * @param {Mixed} actual
1969 * @param {Mixed} expected
1970 * @param {String} message
1974 assert.strictEqual = function (act, exp, msg) {
1975 new Assertion(act, msg).to.equal(exp);
1979 * ### .notStrictEqual(actual, expected, [message])
1981 * Asserts strict inequality (`!==`) of `actual` and `expected`.
1983 * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
1985 * @name notStrictEqual
1986 * @param {Mixed} actual
1987 * @param {Mixed} expected
1988 * @param {String} message
1992 assert.notStrictEqual = function (act, exp, msg) {
1993 new Assertion(act, msg).to.not.equal(exp);
1997 * ### .deepEqual(actual, expected, [message])
1999 * Asserts that `actual` is deeply equal to `expected`.
2001 * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
2004 * @param {Mixed} actual
2005 * @param {Mixed} expected
2006 * @param {String} message
2010 assert.deepEqual = function (act, exp, msg) {
2011 new Assertion(act, msg).to.eql(exp);
2015 * ### .notDeepEqual(actual, expected, [message])
2017 * Assert that `actual` is not deeply equal to `expected`.
2019 * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
2021 * @name notDeepEqual
2022 * @param {Mixed} actual
2023 * @param {Mixed} expected
2024 * @param {String} message
2028 assert.notDeepEqual = function (act, exp, msg) {
2029 new Assertion(act, msg).to.not.eql(exp);
2033 * ### .isTrue(value, [message])
2035 * Asserts that `value` is true.
2037 * var teaServed = true;
2038 * assert.isTrue(teaServed, 'the tea has been served');
2041 * @param {Mixed} value
2042 * @param {String} message
2046 assert.isTrue = function (val, msg) {
2047 new Assertion(val, msg).is['true'];
2051 * ### .isFalse(value, [message])
2053 * Asserts that `value` is false.
2055 * var teaServed = false;
2056 * assert.isFalse(teaServed, 'no tea yet? hmm...');
2059 * @param {Mixed} value
2060 * @param {String} message
2064 assert.isFalse = function (val, msg) {
2065 new Assertion(val, msg).is['false'];
2069 * ### .isNull(value, [message])
2071 * Asserts that `value` is null.
2073 * assert.isNull(err, 'there was no error');
2076 * @param {Mixed} value
2077 * @param {String} message
2081 assert.isNull = function (val, msg) {
2082 new Assertion(val, msg).to.equal(null);
2086 * ### .isNotNull(value, [message])
2088 * Asserts that `value` is not null.
2090 * var tea = 'tasty chai';
2091 * assert.isNotNull(tea, 'great, time for tea!');
2094 * @param {Mixed} value
2095 * @param {String} message
2099 assert.isNotNull = function (val, msg) {
2100 new Assertion(val, msg).to.not.equal(null);
2104 * ### .isUndefined(value, [message])
2106 * Asserts that `value` is `undefined`.
2109 * assert.isUndefined(tea, 'no tea defined');
2112 * @param {Mixed} value
2113 * @param {String} message
2117 assert.isUndefined = function (val, msg) {
2118 new Assertion(val, msg).to.equal(undefined);
2122 * ### .isDefined(value, [message])
2124 * Asserts that `value` is not `undefined`.
2126 * var tea = 'cup of chai';
2127 * assert.isDefined(tea, 'tea has been defined');
2130 * @param {Mixed} value
2131 * @param {String} message
2135 assert.isDefined = function (val, msg) {
2136 new Assertion(val, msg).to.not.equal(undefined);
2140 * ### .isFunction(value, [message])
2142 * Asserts that `value` is a function.
2144 * function serveTea() { return 'cup of tea'; };
2145 * assert.isFunction(serveTea, 'great, we can have tea now');
2148 * @param {Mixed} value
2149 * @param {String} message
2153 assert.isFunction = function (val, msg) {
2154 new Assertion(val, msg).to.be.a('function');
2158 * ### .isNotFunction(value, [message])
2160 * Asserts that `value` is _not_ a function.
2162 * var serveTea = [ 'heat', 'pour', 'sip' ];
2163 * assert.isNotFunction(serveTea, 'great, we have listed the steps');
2165 * @name isNotFunction
2166 * @param {Mixed} value
2167 * @param {String} message
2171 assert.isNotFunction = function (val, msg) {
2172 new Assertion(val, msg).to.not.be.a('function');
2176 * ### .isObject(value, [message])
2178 * Asserts that `value` is an object (as revealed by
2179 * `Object.prototype.toString`).
2181 * var selection = { name: 'Chai', serve: 'with spices' };
2182 * assert.isObject(selection, 'tea selection is an object');
2185 * @param {Mixed} value
2186 * @param {String} message
2190 assert.isObject = function (val, msg) {
2191 new Assertion(val, msg).to.be.a('object');
2195 * ### .isNotObject(value, [message])
2197 * Asserts that `value` is _not_ an object.
2199 * var selection = 'chai'
2200 * assert.isObject(selection, 'tea selection is not an object');
2201 * assert.isObject(null, 'null is not an object');
2204 * @param {Mixed} value
2205 * @param {String} message
2209 assert.isNotObject = function (val, msg) {
2210 new Assertion(val, msg).to.not.be.a('object');
2214 * ### .isArray(value, [message])
2216 * Asserts that `value` is an array.
2218 * var menu = [ 'green', 'chai', 'oolong' ];
2219 * assert.isArray(menu, 'what kind of tea do we want?');
2222 * @param {Mixed} value
2223 * @param {String} message
2227 assert.isArray = function (val, msg) {
2228 new Assertion(val, msg).to.be.an('array');
2232 * ### .isNotArray(value, [message])
2234 * Asserts that `value` is _not_ an array.
2236 * var menu = 'green|chai|oolong';
2237 * assert.isNotArray(menu, 'what kind of tea do we want?');
2240 * @param {Mixed} value
2241 * @param {String} message
2245 assert.isNotArray = function (val, msg) {
2246 new Assertion(val, msg).to.not.be.an('array');
2250 * ### .isString(value, [message])
2252 * Asserts that `value` is a string.
2254 * var teaOrder = 'chai';
2255 * assert.isString(teaOrder, 'order placed');
2258 * @param {Mixed} value
2259 * @param {String} message
2263 assert.isString = function (val, msg) {
2264 new Assertion(val, msg).to.be.a('string');
2268 * ### .isNotString(value, [message])
2270 * Asserts that `value` is _not_ a string.
2273 * assert.isNotString(teaOrder, 'order placed');
2276 * @param {Mixed} value
2277 * @param {String} message
2281 assert.isNotString = function (val, msg) {
2282 new Assertion(val, msg).to.not.be.a('string');
2286 * ### .isNumber(value, [message])
2288 * Asserts that `value` is a number.
2291 * assert.isNumber(cups, 'how many cups');
2294 * @param {Number} value
2295 * @param {String} message
2299 assert.isNumber = function (val, msg) {
2300 new Assertion(val, msg).to.be.a('number');
2304 * ### .isNotNumber(value, [message])
2306 * Asserts that `value` is _not_ a number.
2308 * var cups = '2 cups please';
2309 * assert.isNotNumber(cups, 'how many cups');
2312 * @param {Mixed} value
2313 * @param {String} message
2317 assert.isNotNumber = function (val, msg) {
2318 new Assertion(val, msg).to.not.be.a('number');
2322 * ### .isBoolean(value, [message])
2324 * Asserts that `value` is a boolean.
2326 * var teaReady = true
2327 * , teaServed = false;
2329 * assert.isBoolean(teaReady, 'is the tea ready');
2330 * assert.isBoolean(teaServed, 'has tea been served');
2333 * @param {Mixed} value
2334 * @param {String} message
2338 assert.isBoolean = function (val, msg) {
2339 new Assertion(val, msg).to.be.a('boolean');
2343 * ### .isNotBoolean(value, [message])
2345 * Asserts that `value` is _not_ a boolean.
2347 * var teaReady = 'yep'
2348 * , teaServed = 'nope';
2350 * assert.isNotBoolean(teaReady, 'is the tea ready');
2351 * assert.isNotBoolean(teaServed, 'has tea been served');
2353 * @name isNotBoolean
2354 * @param {Mixed} value
2355 * @param {String} message
2359 assert.isNotBoolean = function (val, msg) {
2360 new Assertion(val, msg).to.not.be.a('boolean');
2364 * ### .typeOf(value, name, [message])
2366 * Asserts that `value`'s type is `name`, as determined by
2367 * `Object.prototype.toString`.
2369 * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
2370 * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
2371 * assert.typeOf('tea', 'string', 'we have a string');
2372 * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
2373 * assert.typeOf(null, 'null', 'we have a null');
2374 * assert.typeOf(undefined, 'undefined', 'we have an undefined');
2377 * @param {Mixed} value
2378 * @param {String} name
2379 * @param {String} message
2383 assert.typeOf = function (val, type, msg) {
2384 new Assertion(val, msg).to.be.a(type);
2388 * ### .notTypeOf(value, name, [message])
2390 * Asserts that `value`'s type is _not_ `name`, as determined by
2391 * `Object.prototype.toString`.
2393 * assert.notTypeOf('tea', 'number', 'strings are not numbers');
2396 * @param {Mixed} value
2397 * @param {String} typeof name
2398 * @param {String} message
2402 assert.notTypeOf = function (val, type, msg) {
2403 new Assertion(val, msg).to.not.be.a(type);
2407 * ### .instanceOf(object, constructor, [message])
2409 * Asserts that `value` is an instance of `constructor`.
2411 * var Tea = function (name) { this.name = name; }
2412 * , chai = new Tea('chai');
2414 * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
2417 * @param {Object} object
2418 * @param {Constructor} constructor
2419 * @param {String} message
2423 assert.instanceOf = function (val, type, msg) {
2424 new Assertion(val, msg).to.be.instanceOf(type);
2428 * ### .notInstanceOf(object, constructor, [message])
2430 * Asserts `value` is not an instance of `constructor`.
2432 * var Tea = function (name) { this.name = name; }
2433 * , chai = new String('chai');
2435 * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
2437 * @name notInstanceOf
2438 * @param {Object} object
2439 * @param {Constructor} constructor
2440 * @param {String} message
2444 assert.notInstanceOf = function (val, type, msg) {
2445 new Assertion(val, msg).to.not.be.instanceOf(type);
2449 * ### .include(haystack, needle, [message])
2451 * Asserts that `haystack` includes `needle`. Works
2452 * for strings and arrays.
2454 * assert.include('foobar', 'bar', 'foobar contains string "bar"');
2455 * assert.include([ 1, 2, 3 ], 3, 'array contains value');
2458 * @param {Array|String} haystack
2459 * @param {Mixed} needle
2460 * @param {String} message
2464 assert.include = function (exp, inc, msg) {
2465 var obj = new Assertion(exp, msg);
2467 if (Array.isArray(exp)) {
2468 obj.to.include(inc);
2469 } else if ('string' === typeof exp) {
2470 obj.to.contain.string(inc);
2472 throw new chai.AssertionError(
2473 'expected an array or string'
2481 * ### .notInclude(haystack, needle, [message])
2483 * Asserts that `haystack` does not include `needle`. Works
2484 * for strings and arrays.
2486 * assert.notInclude('foobar', 'baz', 'string not include substring');
2487 * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
2490 * @param {Array|String} haystack
2491 * @param {Mixed} needle
2492 * @param {String} message
2496 assert.notInclude = function (exp, inc, msg) {
2497 var obj = new Assertion(exp, msg);
2499 if (Array.isArray(exp)) {
2500 obj.to.not.include(inc);
2501 } else if ('string' === typeof exp) {
2502 obj.to.not.contain.string(inc);
2504 throw new chai.AssertionError(
2505 'expected an array or string'
2513 * ### .match(value, regexp, [message])
2515 * Asserts that `value` matches the regular expression `regexp`.
2517 * assert.match('foobar', /^foo/, 'regexp matches');
2520 * @param {Mixed} value
2521 * @param {RegExp} regexp
2522 * @param {String} message
2526 assert.match = function (exp, re, msg) {
2527 new Assertion(exp, msg).to.match(re);
2531 * ### .notMatch(value, regexp, [message])
2533 * Asserts that `value` does not match the regular expression `regexp`.
2535 * assert.notMatch('foobar', /^foo/, 'regexp does not match');
2538 * @param {Mixed} value
2539 * @param {RegExp} regexp
2540 * @param {String} message
2544 assert.notMatch = function (exp, re, msg) {
2545 new Assertion(exp, msg).to.not.match(re);
2549 * ### .property(object, property, [message])
2551 * Asserts that `object` has a property named by `property`.
2553 * assert.property({ tea: { green: 'matcha' }}, 'tea');
2556 * @param {Object} object
2557 * @param {String} property
2558 * @param {String} message
2562 assert.property = function (obj, prop, msg) {
2563 new Assertion(obj, msg).to.have.property(prop);
2567 * ### .notProperty(object, property, [message])
2569 * Asserts that `object` does _not_ have a property named by `property`.
2571 * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
2574 * @param {Object} object
2575 * @param {String} property
2576 * @param {String} message
2580 assert.notProperty = function (obj, prop, msg) {
2581 new Assertion(obj, msg).to.not.have.property(prop);
2585 * ### .deepProperty(object, property, [message])
2587 * Asserts that `object` has a property named by `property`, which can be a
2588 * string using dot- and bracket-notation for deep reference.
2590 * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
2592 * @name deepProperty
2593 * @param {Object} object
2594 * @param {String} property
2595 * @param {String} message
2599 assert.deepProperty = function (obj, prop, msg) {
2600 new Assertion(obj, msg).to.have.deep.property(prop);
2604 * ### .notDeepProperty(object, property, [message])
2606 * Asserts that `object` does _not_ have a property named by `property`, which
2607 * can be a string using dot- and bracket-notation for deep reference.
2609 * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
2611 * @name notDeepProperty
2612 * @param {Object} object
2613 * @param {String} property
2614 * @param {String} message
2618 assert.notDeepProperty = function (obj, prop, msg) {
2619 new Assertion(obj, msg).to.not.have.deep.property(prop);
2623 * ### .propertyVal(object, property, value, [message])
2625 * Asserts that `object` has a property named by `property` with value given
2628 * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
2631 * @param {Object} object
2632 * @param {String} property
2633 * @param {Mixed} value
2634 * @param {String} message
2638 assert.propertyVal = function (obj, prop, val, msg) {
2639 new Assertion(obj, msg).to.have.property(prop, val);
2643 * ### .propertyNotVal(object, property, value, [message])
2645 * Asserts that `object` has a property named by `property`, but with a value
2646 * different from that given by `value`.
2648 * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
2650 * @name propertyNotVal
2651 * @param {Object} object
2652 * @param {String} property
2653 * @param {Mixed} value
2654 * @param {String} message
2658 assert.propertyNotVal = function (obj, prop, val, msg) {
2659 new Assertion(obj, msg).to.not.have.property(prop, val);
2663 * ### .deepPropertyVal(object, property, value, [message])
2665 * Asserts that `object` has a property named by `property` with value given
2666 * by `value`. `property` can use dot- and bracket-notation for deep
2669 * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
2671 * @name deepPropertyVal
2672 * @param {Object} object
2673 * @param {String} property
2674 * @param {Mixed} value
2675 * @param {String} message
2679 assert.deepPropertyVal = function (obj, prop, val, msg) {
2680 new Assertion(obj, msg).to.have.deep.property(prop, val);
2684 * ### .deepPropertyNotVal(object, property, value, [message])
2686 * Asserts that `object` has a property named by `property`, but with a value
2687 * different from that given by `value`. `property` can use dot- and
2688 * bracket-notation for deep reference.
2690 * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
2692 * @name deepPropertyNotVal
2693 * @param {Object} object
2694 * @param {String} property
2695 * @param {Mixed} value
2696 * @param {String} message
2700 assert.deepPropertyNotVal = function (obj, prop, val, msg) {
2701 new Assertion(obj, msg).to.not.have.deep.property(prop, val);
2705 * ### .lengthOf(object, length, [message])
2707 * Asserts that `object` has a `length` property with the expected value.
2709 * assert.lengthOf([1,2,3], 3, 'array has length of 3');
2710 * assert.lengthOf('foobar', 5, 'string has length of 6');
2713 * @param {Mixed} object
2714 * @param {Number} length
2715 * @param {String} message
2719 assert.lengthOf = function (exp, len, msg) {
2720 new Assertion(exp, msg).to.have.length(len);
2724 * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
2726 * Asserts that `function` will throw an error that is an instance of
2727 * `constructor`, or alternately that it will throw an error with message
2728 * matching `regexp`.
2730 * assert.throw(fn, 'function throws a reference error');
2731 * assert.throw(fn, /function throws a reference error/);
2732 * assert.throw(fn, ReferenceError);
2733 * assert.throw(fn, ReferenceError, 'function throws a reference error');
2734 * assert.throw(fn, ReferenceError, /function throws a reference error/);
2739 * @param {Function} function
2740 * @param {ErrorConstructor} constructor
2741 * @param {RegExp} regexp
2742 * @param {String} message
2743 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2747 assert.Throw = function (fn, errt, errs, msg) {
2748 if ('string' === typeof errt || errt instanceof RegExp) {
2753 new Assertion(fn, msg).to.Throw(errt, errs);
2757 * ### .doesNotThrow(function, [constructor/regexp], [message])
2759 * Asserts that `function` will _not_ throw an error that is an instance of
2760 * `constructor`, or alternately that it will not throw an error with message
2761 * matching `regexp`.
2763 * assert.doesNotThrow(fn, Error, 'function does not throw');
2765 * @name doesNotThrow
2766 * @param {Function} function
2767 * @param {ErrorConstructor} constructor
2768 * @param {RegExp} regexp
2769 * @param {String} message
2770 * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2774 assert.doesNotThrow = function (fn, type, msg) {
2775 if ('string' === typeof type) {
2780 new Assertion(fn, msg).to.not.Throw(type);
2784 * ### .operator(val1, operator, val2, [message])
2786 * Compares two values using `operator`.
2788 * assert.operator(1, '<', 2, 'everything is ok');
2789 * assert.operator(1, '>', 2, 'this will fail');
2792 * @param {Mixed} val1
2793 * @param {String} operator
2794 * @param {Mixed} val2
2795 * @param {String} message
2799 assert.operator = function (val, operator, val2, msg) {
2800 if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
2801 throw new Error('Invalid operator "' + operator + '"');
2803 var test = new Assertion(eval(val + operator + val2), msg);
2805 true === flag(test, 'object')
2806 , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
2807 , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
2811 * ### .closeTo(actual, expected, delta, [message])
2813 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
2815 * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
2818 * @param {Number} actual
2819 * @param {Number} expected
2820 * @param {Number} delta
2821 * @param {String} message
2825 assert.closeTo = function (act, exp, delta, msg) {
2826 new Assertion(act, msg).to.be.closeTo(exp, delta);
2830 * ### .sameMembers(set1, set2, [message])
2832 * Asserts that `set1` and `set2` have the same members.
2833 * Order is not taken into account.
2835 * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
2838 * @param {Array} superset
2839 * @param {Array} subset
2840 * @param {String} message
2844 assert.sameMembers = function (set1, set2, msg) {
2845 new Assertion(set1, msg).to.have.same.members(set2);
2849 * ### .includeMembers(superset, subset, [message])
2851 * Asserts that `subset` is included in `superset`.
2852 * Order is not taken into account.
2854 * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
2856 * @name includeMembers
2857 * @param {Array} superset
2858 * @param {Array} subset
2859 * @param {String} message
2863 assert.includeMembers = function (superset, subset, msg) {
2864 new Assertion(superset, msg).to.include.members(subset);
2868 * Undocumented / untested
2871 assert.ifError = function (val, msg) {
2872 new Assertion(val, msg).to.not.be.ok;
2879 (function alias(name, as){
2880 assert[as] = assert[name];
2884 ('Throw', 'throws');
2888 require.register("chai/lib/chai/interface/expect.js", function(exports, require, module){
2891 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2895 module.exports = function (chai, util) {
2896 chai.expect = function (val, message) {
2897 return new chai.Assertion(val, message);
2903 require.register("chai/lib/chai/interface/should.js", function(exports, require, module){
2906 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2910 module.exports = function (chai, util) {
2911 var Assertion = chai.Assertion;
2913 function loadShould () {
2914 // modify Object.prototype to have `should`
2915 Object.defineProperty(Object.prototype, 'should',
2917 set: function (value) {
2918 // See https://github.com/chaijs/chai/issues/86: this makes
2919 // `whatever.should = someValue` actually set `someValue`, which is
2920 // especially useful for `global.should = require('chai').should()`.
2922 // Note that we have to use [[DefineProperty]] instead of [[Put]]
2923 // since otherwise we would trigger this very setter!
2924 Object.defineProperty(this, 'should', {
2932 if (this instanceof String || this instanceof Number) {
2933 return new Assertion(this.constructor(this));
2934 } else if (this instanceof Boolean) {
2935 return new Assertion(this == true);
2937 return new Assertion(this);
2939 , configurable: true
2944 should.equal = function (val1, val2, msg) {
2945 new Assertion(val1, msg).to.equal(val2);
2948 should.Throw = function (fn, errt, errs, msg) {
2949 new Assertion(fn, msg).to.Throw(errt, errs);
2952 should.exist = function (val, msg) {
2953 new Assertion(val, msg).to.exist;
2959 should.not.equal = function (val1, val2, msg) {
2960 new Assertion(val1, msg).to.not.equal(val2);
2963 should.not.Throw = function (fn, errt, errs, msg) {
2964 new Assertion(fn, msg).to.not.Throw(errt, errs);
2967 should.not.exist = function (val, msg) {
2968 new Assertion(val, msg).to.not.exist;
2971 should['throw'] = should['Throw'];
2972 should.not['throw'] = should.not['Throw'];
2977 chai.should = loadShould;
2978 chai.Should = loadShould;
2982 require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports, require, module){
2984 * Chai - addChainingMethod utility
2985 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2990 * Module dependencies
2993 var transferFlags = require('./transferFlags');
2999 // Check whether `__proto__` is supported
3000 var hasProtoSupport = '__proto__' in Object;
3002 // Without `__proto__` support, this module will need to add properties to a function.
3003 // However, some Function.prototype methods cannot be overwritten,
3004 // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
3005 var excludeNames = /^(?:length|name|arguments|caller)$/;
3007 // Cache `Function` properties
3008 var call = Function.prototype.call,
3009 apply = Function.prototype.apply;
3012 * ### addChainableMethod (ctx, name, method, chainingBehavior)
3014 * Adds a method to an object, such that the method can also be chained.
3016 * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
3017 * var obj = utils.flag(this, 'object');
3018 * new chai.Assertion(obj).to.be.equal(str);
3021 * Can also be accessed directly from `chai.Assertion`.
3023 * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
3025 * The result can then be used as both a method assertion, executing both `method` and
3026 * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
3028 * expect(fooStr).to.be.foo('bar');
3029 * expect(fooStr).to.be.foo.equal('foo');
3031 * @param {Object} ctx object to which the method is added
3032 * @param {String} name of method to add
3033 * @param {Function} method function to be used for `name`, when called
3034 * @param {Function} chainingBehavior function to be called every time the property is accessed
3035 * @name addChainableMethod
3039 module.exports = function (ctx, name, method, chainingBehavior) {
3040 if (typeof chainingBehavior !== 'function')
3041 chainingBehavior = function () { };
3043 Object.defineProperty(ctx, name,
3044 { get: function () {
3045 chainingBehavior.call(this);
3047 var assert = function () {
3048 var result = method.apply(this, arguments);
3049 return result === undefined ? this : result;
3052 // Use `__proto__` if available
3053 if (hasProtoSupport) {
3054 // Inherit all properties from the object by replacing the `Function` prototype
3055 var prototype = assert.__proto__ = Object.create(this);
3056 // Restore the `call` and `apply` methods from `Function`
3057 prototype.call = call;
3058 prototype.apply = apply;
3060 // Otherwise, redefine all properties (slow!)
3062 var asserterNames = Object.getOwnPropertyNames(ctx);
3063 asserterNames.forEach(function (asserterName) {
3064 if (!excludeNames.test(asserterName)) {
3065 var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
3066 Object.defineProperty(assert, asserterName, pd);
3071 transferFlags(this, assert);
3074 , configurable: true
3079 require.register("chai/lib/chai/utils/addMethod.js", function(exports, require, module){
3081 * Chai - addMethod utility
3082 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3087 * ### .addMethod (ctx, name, method)
3089 * Adds a method to the prototype of an object.
3091 * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
3092 * var obj = utils.flag(this, 'object');
3093 * new chai.Assertion(obj).to.be.equal(str);
3096 * Can also be accessed directly from `chai.Assertion`.
3098 * chai.Assertion.addMethod('foo', fn);
3100 * Then can be used as any other assertion.
3102 * expect(fooStr).to.be.foo('bar');
3104 * @param {Object} ctx object to which the method is added
3105 * @param {String} name of method to add
3106 * @param {Function} method function to be used for name
3111 module.exports = function (ctx, name, method) {
3112 ctx[name] = function () {
3113 var result = method.apply(this, arguments);
3114 return result === undefined ? this : result;
3119 require.register("chai/lib/chai/utils/addProperty.js", function(exports, require, module){
3121 * Chai - addProperty utility
3122 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3127 * ### addProperty (ctx, name, getter)
3129 * Adds a property to the prototype of an object.
3131 * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
3132 * var obj = utils.flag(this, 'object');
3133 * new chai.Assertion(obj).to.be.instanceof(Foo);
3136 * Can also be accessed directly from `chai.Assertion`.
3138 * chai.Assertion.addProperty('foo', fn);
3140 * Then can be used as any other assertion.
3142 * expect(myFoo).to.be.foo;
3144 * @param {Object} ctx object to which the property is added
3145 * @param {String} name of property to add
3146 * @param {Function} getter function to be used for name
3151 module.exports = function (ctx, name, getter) {
3152 Object.defineProperty(ctx, name,
3153 { get: function () {
3154 var result = getter.call(this);
3155 return result === undefined ? this : result;
3157 , configurable: true
3162 require.register("chai/lib/chai/utils/eql.js", function(exports, require, module){
3163 // This is (almost) directly from Node.js assert
3164 // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
3166 module.exports = _deepEqual;
3168 var getEnumerableProperties = require('./getEnumerableProperties');
3173 Buffer = require('buffer').Buffer;
3176 isBuffer: function () { return false; }
3180 function _deepEqual(actual, expected, memos) {
3182 // 7.1. All identical values are equivalent, as determined by ===.
3183 if (actual === expected) {
3186 } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
3187 if (actual.length != expected.length) return false;
3189 for (var i = 0; i < actual.length; i++) {
3190 if (actual[i] !== expected[i]) return false;
3195 // 7.2. If the expected value is a Date object, the actual value is
3196 // equivalent if it is also a Date object that refers to the same time.
3197 } else if (expected instanceof Date) {
3198 if (!(actual instanceof Date)) return false;
3199 return actual.getTime() === expected.getTime();
3201 // 7.3. Other pairs that do not both pass typeof value == 'object',
3202 // equivalence is determined by ==.
3203 } else if (typeof actual != 'object' && typeof expected != 'object') {
3204 return actual === expected;
3206 } else if (expected instanceof RegExp) {
3207 if (!(actual instanceof RegExp)) return false;
3208 return actual.toString() === expected.toString();
3210 // 7.4. For all other Object pairs, including Array objects, equivalence is
3211 // determined by having the same number of owned properties (as verified
3212 // with Object.prototype.hasOwnProperty.call), the same set of keys
3213 // (although not necessarily the same order), equivalent values for every
3214 // corresponding key, and an identical 'prototype' property. Note: this
3215 // accounts for both named and indexed properties on Arrays.
3217 return objEquiv(actual, expected, memos);
3221 function isUndefinedOrNull(value) {
3222 return value === null || value === undefined;
3225 function isArguments(object) {
3226 return Object.prototype.toString.call(object) == '[object Arguments]';
3229 function objEquiv(a, b, memos) {
3230 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
3233 // an identical 'prototype' property.
3234 if (a.prototype !== b.prototype) return false;
3236 // check if we have already compared a and b
3239 for(i = 0; i < memos.length; i++) {
3240 if ((memos[i][0] === a && memos[i][1] === b) ||
3241 (memos[i][0] === b && memos[i][1] === a))
3248 //~~~I've managed to break Object.keys through screwy arguments passing.
3249 // Converting to array solves the problem.
3250 if (isArguments(a)) {
3251 if (!isArguments(b)) {
3256 return _deepEqual(a, b, memos);
3259 var ka = getEnumerableProperties(a),
3260 kb = getEnumerableProperties(b),
3262 } catch (e) {//happens when one is a string literal and the other isn't
3266 // having the same number of owned properties (keys incorporates
3268 if (ka.length != kb.length)
3271 //the same set of keys (although not necessarily the same order),
3275 for (i = ka.length - 1; i >= 0; i--) {
3280 // remember objects we have compared to guard against circular references
3281 memos.push([ a, b ]);
3283 //equivalent values for every corresponding key, and
3284 //~~~possibly expensive deep test
3285 for (i = ka.length - 1; i >= 0; i--) {
3287 if (!_deepEqual(a[key], b[key], memos)) return false;
3294 require.register("chai/lib/chai/utils/flag.js", function(exports, require, module){
3296 * Chai - flag utility
3297 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3302 * ### flag(object ,key, [value])
3304 * Get or set a flag value on an object. If a
3305 * value is provided it will be set, else it will
3306 * return the currently set value or `undefined` if
3307 * the value is not set.
3309 * utils.flag(this, 'foo', 'bar'); // setter
3310 * utils.flag(this, 'foo'); // getter, returns `bar`
3312 * @param {Object} object (constructed Assertion
3313 * @param {String} key
3314 * @param {Mixed} value (optional)
3319 module.exports = function (obj, key, value) {
3320 var flags = obj.__flags || (obj.__flags = Object.create(null));
3321 if (arguments.length === 3) {
3329 require.register("chai/lib/chai/utils/getActual.js", function(exports, require, module){
3331 * Chai - getActual utility
3332 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3337 * # getActual(object, [actual])
3339 * Returns the `actual` value for an Assertion
3341 * @param {Object} object (constructed Assertion)
3342 * @param {Arguments} chai.Assertion.prototype.assert arguments
3345 module.exports = function (obj, args) {
3346 var actual = args[4];
3347 return 'undefined' !== typeof actual ? actual : obj._obj;
3351 require.register("chai/lib/chai/utils/getEnumerableProperties.js", function(exports, require, module){
3353 * Chai - getEnumerableProperties utility
3354 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3359 * ### .getEnumerableProperties(object)
3361 * This allows the retrieval of enumerable property names of an object,
3364 * @param {Object} object
3366 * @name getEnumerableProperties
3370 module.exports = function getEnumerableProperties(object) {
3372 for (var name in object) {
3379 require.register("chai/lib/chai/utils/getMessage.js", function(exports, require, module){
3381 * Chai - message composition utility
3382 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3387 * Module dependancies
3390 var flag = require('./flag')
3391 , getActual = require('./getActual')
3392 , inspect = require('./inspect')
3393 , objDisplay = require('./objDisplay');
3396 * ### .getMessage(object, message, negateMessage)
3398 * Construct the error message based on flags
3399 * and template tags. Template tags will return
3400 * a stringified inspection of the object referenced.
3402 * Message template tags:
3403 * - `#{this}` current asserted object
3404 * - `#{act}` actual value
3405 * - `#{exp}` expected value
3407 * @param {Object} object (constructed Assertion)
3408 * @param {Arguments} chai.Assertion.prototype.assert arguments
3413 module.exports = function (obj, args) {
3414 var negate = flag(obj, 'negate')
3415 , val = flag(obj, 'object')
3416 , expected = args[3]
3417 , actual = getActual(obj, args)
3418 , msg = negate ? args[2] : args[1]
3419 , flagMsg = flag(obj, 'message');
3423 .replace(/#{this}/g, objDisplay(val))
3424 .replace(/#{act}/g, objDisplay(actual))
3425 .replace(/#{exp}/g, objDisplay(expected));
3427 return flagMsg ? flagMsg + ': ' + msg : msg;
3431 require.register("chai/lib/chai/utils/getName.js", function(exports, require, module){
3433 * Chai - getName utility
3434 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3441 * Gets the name of a function, in a cross-browser way.
3443 * @param {Function} a function (usually a constructor)
3446 module.exports = function (func) {
3447 if (func.name) return func.name;
3449 var match = /^\s?function ([^(]*)\(/.exec(func);
3450 return match && match[1] ? match[1] : "";
3454 require.register("chai/lib/chai/utils/getPathValue.js", function(exports, require, module){
3456 * Chai - getPathValue utility
3457 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3458 * @see https://github.com/logicalparadox/filtr
3463 * ### .getPathValue(path, object)
3465 * This allows the retrieval of values in an
3466 * object given a string path.
3470 * arr: ['a', 'b', 'c']
3474 * arr: [ { nested: 'Universe' } ]
3475 * , str: 'Hello again!'
3479 * The following would be the results.
3481 * getPathValue('prop1.str', obj); // Hello
3482 * getPathValue('prop1.att[2]', obj); // b
3483 * getPathValue('prop2.arr[0].nested', obj); // Universe
3485 * @param {String} path
3486 * @param {Object} object
3487 * @returns {Object} value or `undefined`
3488 * @name getPathValue
3492 var getPathValue = module.exports = function (path, obj) {
3493 var parsed = parsePath(path);
3494 return _getPathValue(parsed, obj);
3498 * ## parsePath(path)
3500 * Helper function used to parse string object
3501 * paths. Use in conjunction with `_getPathValue`.
3503 * var parsed = parsePath('myobject.property.subprop');
3507 * * Can be as near infinitely deep and nested
3508 * * Arrays are also valid using the formal `myobject.document[3].property`.
3510 * @param {String} path
3511 * @returns {Object} parsed
3515 function parsePath (path) {
3516 var str = path.replace(/\[/g, '.[')
3517 , parts = str.match(/(\\\.|[^.]+?)+/g);
3518 return parts.map(function (value) {
3519 var re = /\[(\d+)\]$/
3520 , mArr = re.exec(value)
3521 if (mArr) return { i: parseFloat(mArr[1]) };
3522 else return { p: value };
3527 * ## _getPathValue(parsed, obj)
3529 * Helper companion function for `.parsePath` that returns
3530 * the value located at the parsed address.
3532 * var value = getPathValue(parsed, obj);
3534 * @param {Object} parsed definition from `parsePath`.
3535 * @param {Object} object to search against
3536 * @returns {Object|Undefined} value
3540 function _getPathValue (parsed, obj) {
3543 for (var i = 0, l = parsed.length; i < l; i++) {
3544 var part = parsed[i];
3546 if ('undefined' !== typeof part.p)
3548 else if ('undefined' !== typeof part.i)
3550 if (i == (l - 1)) res = tmp;
3559 require.register("chai/lib/chai/utils/getProperties.js", function(exports, require, module){
3561 * Chai - getProperties utility
3562 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3567 * ### .getProperties(object)
3569 * This allows the retrieval of property names of an object, enumerable or not,
3572 * @param {Object} object
3574 * @name getProperties
3578 module.exports = function getProperties(object) {
3579 var result = Object.getOwnPropertyNames(subject);
3581 function addProperty(property) {
3582 if (result.indexOf(property) === -1) {
3583 result.push(property);
3587 var proto = Object.getPrototypeOf(subject);
3588 while (proto !== null) {
3589 Object.getOwnPropertyNames(proto).forEach(addProperty);
3590 proto = Object.getPrototypeOf(proto);
3597 require.register("chai/lib/chai/utils/index.js", function(exports, require, module){
3600 * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
3608 var exports = module.exports = {};
3614 exports.test = require('./test');
3620 exports.type = require('./type');
3626 exports.getMessage = require('./getMessage');
3632 exports.getActual = require('./getActual');
3638 exports.inspect = require('./inspect');
3641 * Object Display util
3644 exports.objDisplay = require('./objDisplay');
3650 exports.flag = require('./flag');
3653 * Flag transferring utility
3656 exports.transferFlags = require('./transferFlags');
3659 * Deep equal utility
3662 exports.eql = require('./eql');
3668 exports.getPathValue = require('./getPathValue');
3674 exports.getName = require('./getName');
3680 exports.addProperty = require('./addProperty');
3686 exports.addMethod = require('./addMethod');
3689 * overwrite Property
3692 exports.overwriteProperty = require('./overwriteProperty');
3698 exports.overwriteMethod = require('./overwriteMethod');
3701 * Add a chainable method
3704 exports.addChainableMethod = require('./addChainableMethod');
3708 require.register("chai/lib/chai/utils/inspect.js", function(exports, require, module){
3709 // This is (almost) directly from Node.js utils
3710 // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
3712 var getName = require('./getName');
3713 var getProperties = require('./getProperties');
3714 var getEnumerableProperties = require('./getEnumerableProperties');
3716 module.exports = inspect;
3719 * Echos the value of a value. Trys to print the value out
3720 * in the best way possible given the different types.
3722 * @param {Object} obj The object to print out.
3723 * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
3724 * properties of objects.
3725 * @param {Number} depth Depth in which to descend in object. Default is 2.
3726 * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
3727 * output. Default is false (no coloring).
3729 function inspect(obj, showHidden, depth, colors) {
3731 showHidden: showHidden,
3733 stylize: function (str) { return str; }
3735 return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
3738 // https://gist.github.com/1044128/
3739 var getOuterHTML = function(element) {
3740 if ('outerHTML' in element) return element.outerHTML;
3741 var ns = "http://www.w3.org/1999/xhtml";
3742 var container = document.createElementNS(ns, '_');
3743 var elemProto = (window.HTMLElement || window.Element).prototype;
3744 var xmlSerializer = new XMLSerializer();
3746 if (document.xmlVersion) {
3747 return xmlSerializer.serializeToString(element);
3749 container.appendChild(element.cloneNode(false));
3750 html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
3751 container.innerHTML = '';
3756 // Returns true if object is a DOM element.
3757 var isDOMElement = function (object) {
3758 if (typeof HTMLElement === 'object') {
3759 return object instanceof HTMLElement;
3762 typeof object === 'object' &&
3763 object.nodeType === 1 &&
3764 typeof object.nodeName === 'string';
3768 function formatValue(ctx, value, recurseTimes) {
3769 // Provide a hook for user-specified inspect functions.
3770 // Check that value is an object with an inspect function on it
3771 if (value && typeof value.inspect === 'function' &&
3772 // Filter out the util module, it's inspect function is special
3773 value.inspect !== exports.inspect &&
3774 // Also filter out any prototype objects using the circular check.
3775 !(value.constructor && value.constructor.prototype === value)) {
3776 var ret = value.inspect(recurseTimes);
3777 if (typeof ret !== 'string') {
3778 ret = formatValue(ctx, ret, recurseTimes);
3783 // Primitive types cannot have properties
3784 var primitive = formatPrimitive(ctx, value);
3789 // If it's DOM elem, get outer HTML.
3790 if (isDOMElement(value)) {
3791 return getOuterHTML(value);
3794 // Look up the keys of the object.
3795 var visibleKeys = getEnumerableProperties(value);
3796 var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
3798 // Some type of object without properties can be shortcutted.
3799 // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
3800 // a `stack` plus `description` property; ignore those for consistency.
3801 if (keys.length === 0 || (isError(value) && (
3802 (keys.length === 1 && keys[0] === 'stack') ||
3803 (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
3805 if (typeof value === 'function') {
3806 var name = getName(value);
3807 var nameSuffix = name ? ': ' + name : '';
3808 return ctx.stylize('[Function' + nameSuffix + ']', 'special');
3810 if (isRegExp(value)) {
3811 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3813 if (isDate(value)) {
3814 return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
3816 if (isError(value)) {
3817 return formatError(value);
3821 var base = '', array = false, braces = ['{', '}'];
3823 // Make Array say that they are Array
3824 if (isArray(value)) {
3826 braces = ['[', ']'];
3829 // Make functions say that they are functions
3830 if (typeof value === 'function') {
3831 var name = getName(value);
3832 var nameSuffix = name ? ': ' + name : '';
3833 base = ' [Function' + nameSuffix + ']';
3836 // Make RegExps say that they are RegExps
3837 if (isRegExp(value)) {
3838 base = ' ' + RegExp.prototype.toString.call(value);
3841 // Make dates with properties first say the date
3842 if (isDate(value)) {
3843 base = ' ' + Date.prototype.toUTCString.call(value);
3846 // Make error with message first say the error
3847 if (isError(value)) {
3848 return formatError(value);
3851 if (keys.length === 0 && (!array || value.length == 0)) {
3852 return braces[0] + base + braces[1];
3855 if (recurseTimes < 0) {
3856 if (isRegExp(value)) {
3857 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3859 return ctx.stylize('[Object]', 'special');
3863 ctx.seen.push(value);
3867 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
3869 output = keys.map(function(key) {
3870 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
3876 return reduceToSingleString(output, base, braces);
3880 function formatPrimitive(ctx, value) {
3881 switch (typeof value) {
3883 return ctx.stylize('undefined', 'undefined');
3886 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
3887 .replace(/'/g, "\\'")
3888 .replace(/\\"/g, '"') + '\'';
3889 return ctx.stylize(simple, 'string');
3892 return ctx.stylize('' + value, 'number');
3895 return ctx.stylize('' + value, 'boolean');
3897 // For some reason typeof null is "object", so special case here.
3898 if (value === null) {
3899 return ctx.stylize('null', 'null');
3904 function formatError(value) {
3905 return '[' + Error.prototype.toString.call(value) + ']';
3909 function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
3911 for (var i = 0, l = value.length; i < l; ++i) {
3912 if (Object.prototype.hasOwnProperty.call(value, String(i))) {
3913 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3919 keys.forEach(function(key) {
3920 if (!key.match(/^\d+$/)) {
3921 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3929 function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3931 if (value.__lookupGetter__) {
3932 if (value.__lookupGetter__(key)) {
3933 if (value.__lookupSetter__(key)) {
3934 str = ctx.stylize('[Getter/Setter]', 'special');
3936 str = ctx.stylize('[Getter]', 'special');
3939 if (value.__lookupSetter__(key)) {
3940 str = ctx.stylize('[Setter]', 'special');
3944 if (visibleKeys.indexOf(key) < 0) {
3945 name = '[' + key + ']';
3948 if (ctx.seen.indexOf(value[key]) < 0) {
3949 if (recurseTimes === null) {
3950 str = formatValue(ctx, value[key], null);
3952 str = formatValue(ctx, value[key], recurseTimes - 1);
3954 if (str.indexOf('\n') > -1) {
3956 str = str.split('\n').map(function(line) {
3958 }).join('\n').substr(2);
3960 str = '\n' + str.split('\n').map(function(line) {
3966 str = ctx.stylize('[Circular]', 'special');
3969 if (typeof name === 'undefined') {
3970 if (array && key.match(/^\d+$/)) {
3973 name = JSON.stringify('' + key);
3974 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
3975 name = name.substr(1, name.length - 2);
3976 name = ctx.stylize(name, 'name');
3978 name = name.replace(/'/g, "\\'")
3979 .replace(/\\"/g, '"')
3980 .replace(/(^"|"$)/g, "'");
3981 name = ctx.stylize(name, 'string');
3985 return name + ': ' + str;
3989 function reduceToSingleString(output, base, braces) {
3990 var numLinesEst = 0;
3991 var length = output.reduce(function(prev, cur) {
3993 if (cur.indexOf('\n') >= 0) numLinesEst++;
3994 return prev + cur.length + 1;
3999 (base === '' ? '' : base + '\n ') +
4001 output.join(',\n ') +
4006 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
4009 function isArray(ar) {
4010 return Array.isArray(ar) ||
4011 (typeof ar === 'object' && objectToString(ar) === '[object Array]');
4014 function isRegExp(re) {
4015 return typeof re === 'object' && objectToString(re) === '[object RegExp]';
4018 function isDate(d) {
4019 return typeof d === 'object' && objectToString(d) === '[object Date]';
4022 function isError(e) {
4023 return typeof e === 'object' && objectToString(e) === '[object Error]';
4026 function objectToString(o) {
4027 return Object.prototype.toString.call(o);
4031 require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require, module){
4033 * Chai - flag utility
4034 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4039 * Module dependancies
4042 var inspect = require('./inspect');
4045 * ### .objDisplay (object)
4047 * Determines if an object or an array matches
4048 * criteria to be inspected in-line for error
4049 * messages or should be truncated.
4051 * @param {Mixed} javascript object to inspect
4056 module.exports = function (obj) {
4057 var str = inspect(obj)
4058 , type = Object.prototype.toString.call(obj);
4060 if (str.length >= 40) {
4061 if (type === '[object Function]') {
4062 return !obj.name || obj.name === ''
4064 : '[Function: ' + obj.name + ']';
4065 } else if (type === '[object Array]') {
4066 return '[ Array(' + obj.length + ') ]';
4067 } else if (type === '[object Object]') {
4068 var keys = Object.keys(obj)
4069 , kstr = keys.length > 2
4070 ? keys.splice(0, 2).join(', ') + ', ...'
4072 return '{ Object (' + kstr + ') }';
4082 require.register("chai/lib/chai/utils/overwriteMethod.js", function(exports, require, module){
4084 * Chai - overwriteMethod utility
4085 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4090 * ### overwriteMethod (ctx, name, fn)
4092 * Overwites an already existing method and provides
4093 * access to previous function. Must return function
4094 * to be used for name.
4096 * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
4097 * return function (str) {
4098 * var obj = utils.flag(this, 'object');
4099 * if (obj instanceof Foo) {
4100 * new chai.Assertion(obj.value).to.equal(str);
4102 * _super.apply(this, arguments);
4107 * Can also be accessed directly from `chai.Assertion`.
4109 * chai.Assertion.overwriteMethod('foo', fn);
4111 * Then can be used as any other assertion.
4113 * expect(myFoo).to.equal('bar');
4115 * @param {Object} ctx object whose method is to be overwritten
4116 * @param {String} name of method to overwrite
4117 * @param {Function} method function that returns a function to be used for name
4118 * @name overwriteMethod
4122 module.exports = function (ctx, name, method) {
4123 var _method = ctx[name]
4124 , _super = function () { return this; };
4126 if (_method && 'function' === typeof _method)
4129 ctx[name] = function () {
4130 var result = method(_super).apply(this, arguments);
4131 return result === undefined ? this : result;
4136 require.register("chai/lib/chai/utils/overwriteProperty.js", function(exports, require, module){
4138 * Chai - overwriteProperty utility
4139 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4144 * ### overwriteProperty (ctx, name, fn)
4146 * Overwites an already existing property getter and provides
4147 * access to previous value. Must return function to use as getter.
4149 * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
4150 * return function () {
4151 * var obj = utils.flag(this, 'object');
4152 * if (obj instanceof Foo) {
4153 * new chai.Assertion(obj.name).to.equal('bar');
4155 * _super.call(this);
4161 * Can also be accessed directly from `chai.Assertion`.
4163 * chai.Assertion.overwriteProperty('foo', fn);
4165 * Then can be used as any other assertion.
4167 * expect(myFoo).to.be.ok;
4169 * @param {Object} ctx object whose property is to be overwritten
4170 * @param {String} name of property to overwrite
4171 * @param {Function} getter function that returns a getter function to be used for name
4172 * @name overwriteProperty
4176 module.exports = function (ctx, name, getter) {
4177 var _get = Object.getOwnPropertyDescriptor(ctx, name)
4178 , _super = function () {};
4180 if (_get && 'function' === typeof _get.get)
4183 Object.defineProperty(ctx, name,
4184 { get: function () {
4185 var result = getter(_super).call(this);
4186 return result === undefined ? this : result;
4188 , configurable: true
4193 require.register("chai/lib/chai/utils/test.js", function(exports, require, module){
4195 * Chai - test utility
4196 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4201 * Module dependancies
4204 var flag = require('./flag');
4207 * # test(object, expression)
4209 * Test and object for expression.
4211 * @param {Object} object (constructed Assertion)
4212 * @param {Arguments} chai.Assertion.prototype.assert arguments
4215 module.exports = function (obj, args) {
4216 var negate = flag(obj, 'negate')
4218 return negate ? !expr : expr;
4222 require.register("chai/lib/chai/utils/transferFlags.js", function(exports, require, module){
4224 * Chai - transferFlags utility
4225 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4230 * ### transferFlags(assertion, object, includeAll = true)
4232 * Transfer all the flags for `assertion` to `object`. If
4233 * `includeAll` is set to `false`, then the base Chai
4234 * assertion flags (namely `object`, `ssfi`, and `message`)
4235 * will not be transferred.
4238 * var newAssertion = new Assertion();
4239 * utils.transferFlags(assertion, newAssertion);
4241 * var anotherAsseriton = new Assertion(myObj);
4242 * utils.transferFlags(assertion, anotherAssertion, false);
4244 * @param {Assertion} assertion the assertion to transfer the flags from
4245 * @param {Object} object the object to transfer the flags too; usually a new assertion
4246 * @param {Boolean} includeAll
4251 module.exports = function (assertion, object, includeAll) {
4252 var flags = assertion.__flags || (assertion.__flags = Object.create(null));
4254 if (!object.__flags) {
4255 object.__flags = Object.create(null);
4258 includeAll = arguments.length === 3 ? includeAll : true;
4260 for (var flag in flags) {
4262 (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
4263 object.__flags[flag] = flags[flag];
4269 require.register("chai/lib/chai/utils/type.js", function(exports, require, module){
4271 * Chai - type utility
4272 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4277 * Detectable javascript natives
4281 '[object Arguments]': 'arguments'
4282 , '[object Array]': 'array'
4283 , '[object Date]': 'date'
4284 , '[object Function]': 'function'
4285 , '[object Number]': 'number'
4286 , '[object RegExp]': 'regexp'
4287 , '[object String]': 'string'
4293 * Better implementation of `typeof` detection that can
4294 * be used cross-browser. Handles the inconsistencies of
4295 * Array, `null`, and `undefined` detection.
4297 * utils.type({}) // 'object'
4298 * utils.type(null) // `null'
4299 * utils.type(undefined) // `undefined`
4300 * utils.type([]) // `array`
4302 * @param {Mixed} object to detect type of
4307 module.exports = function (obj) {
4308 var str = Object.prototype.toString.call(obj);
4309 if (natives[str]) return natives[str];
4310 if (obj === null) return 'null';
4311 if (obj === undefined) return 'undefined';
4312 if (obj === Object(obj)) return 'object';
4317 require.alias("chaijs-assertion-error/index.js", "chai/deps/assertion-error/index.js");
4318 require.alias("chaijs-assertion-error/index.js", "chai/deps/assertion-error/index.js");
4319 require.alias("chaijs-assertion-error/index.js", "assertion-error/index.js");
4320 require.alias("chaijs-assertion-error/index.js", "chaijs-assertion-error/index.js");
4322 require.alias("chai/index.js", "chai/index.js");
4324 if (typeof exports == "object") {
4325 module.exports = require("chai");
4326 } else if (typeof define == "function" && define.amd) {
4327 define(function(){ return require("chai"); });
4329 this["chai"] = require("chai");