UNPKG

110 kBJavaScriptView Raw
1;(function(){
2
3/**
4 * Require the given path.
5 *
6 * @param {String} path
7 * @return {Object} exports
8 * @api public
9 */
10
11function require(path, parent, orig) {
12 var resolved = require.resolve(path);
13
14 // lookup failed
15 if (null == resolved) {
16 orig = orig || path;
17 parent = parent || 'root';
18 var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
19 err.path = orig;
20 err.parent = parent;
21 err.require = true;
22 throw err;
23 }
24
25 var module = require.modules[resolved];
26
27 // perform real require()
28 // by invoking the module's
29 // registered function
30 if (!module.exports) {
31 module.exports = {};
32 module.client = module.component = true;
33 module.call(this, module.exports, require.relative(resolved), module);
34 }
35
36 return module.exports;
37}
38
39/**
40 * Registered modules.
41 */
42
43require.modules = {};
44
45/**
46 * Registered aliases.
47 */
48
49require.aliases = {};
50
51/**
52 * Resolve `path`.
53 *
54 * Lookup:
55 *
56 * - PATH/index.js
57 * - PATH.js
58 * - PATH
59 *
60 * @param {String} path
61 * @return {String} path or null
62 * @api private
63 */
64
65require.resolve = function(path) {
66 if (path.charAt(0) === '/') path = path.slice(1);
67
68 var paths = [
69 path,
70 path + '.js',
71 path + '.json',
72 path + '/index.js',
73 path + '/index.json'
74 ];
75
76 for (var i = 0; i < paths.length; i++) {
77 var path = paths[i];
78 if (require.modules.hasOwnProperty(path)) return path;
79 if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
80 }
81};
82
83/**
84 * Normalize `path` relative to the current path.
85 *
86 * @param {String} curr
87 * @param {String} path
88 * @return {String}
89 * @api private
90 */
91
92require.normalize = function(curr, path) {
93 var segs = [];
94
95 if ('.' != path.charAt(0)) return path;
96
97 curr = curr.split('/');
98 path = path.split('/');
99
100 for (var i = 0; i < path.length; ++i) {
101 if ('..' == path[i]) {
102 curr.pop();
103 } else if ('.' != path[i] && '' != path[i]) {
104 segs.push(path[i]);
105 }
106 }
107
108 return curr.concat(segs).join('/');
109};
110
111/**
112 * Register module at `path` with callback `definition`.
113 *
114 * @param {String} path
115 * @param {Function} definition
116 * @api private
117 */
118
119require.register = function(path, definition) {
120 require.modules[path] = definition;
121};
122
123/**
124 * Alias a module definition.
125 *
126 * @param {String} from
127 * @param {String} to
128 * @api private
129 */
130
131require.alias = function(from, to) {
132 if (!require.modules.hasOwnProperty(from)) {
133 throw new Error('Failed to alias "' + from + '", it does not exist');
134 }
135 require.aliases[to] = from;
136};
137
138/**
139 * Return a require function relative to the `parent` path.
140 *
141 * @param {String} parent
142 * @return {Function}
143 * @api private
144 */
145
146require.relative = function(parent) {
147 var p = require.normalize(parent, '..');
148
149 /**
150 * lastIndexOf helper.
151 */
152
153 function lastIndexOf(arr, obj) {
154 var i = arr.length;
155 while (i--) {
156 if (arr[i] === obj) return i;
157 }
158 return -1;
159 }
160
161 /**
162 * The relative require() itself.
163 */
164
165 function localRequire(path) {
166 var resolved = localRequire.resolve(path);
167 return require(resolved, parent, path);
168 }
169
170 /**
171 * Resolve relative to the parent.
172 */
173
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);
178
179 // resolve deps by returning
180 // the dep in the nearest "deps"
181 // directory
182 var segs = parent.split('/');
183 var i = lastIndexOf(segs, 'deps') + 1;
184 if (!i) i = 0;
185 path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
186 return path;
187 };
188
189 /**
190 * Check if module is defined at `path`.
191 */
192
193 localRequire.exists = function(path) {
194 return require.modules.hasOwnProperty(localRequire.resolve(path));
195 };
196
197 return localRequire;
198};
199require.register("chaijs-assertion-error/index.js", function(exports, require, module){
200/*!
201 * assertion-error
202 * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
203 * MIT Licensed
204 */
205
206/*!
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 `{}`.
210 *
211 * @param {String} excluded properties ...
212 * @return {Function}
213 */
214
215function exclude () {
216 var excludes = [].slice.call(arguments);
217
218 function excludeProps (res, obj) {
219 Object.keys(obj).forEach(function (key) {
220 if (!~excludes.indexOf(key)) res[key] = obj[key];
221 });
222 }
223
224 return function extendExclude () {
225 var args = [].slice.call(arguments)
226 , i = 0
227 , res = {};
228
229 for (; i < args.length; i++) {
230 excludeProps(res, args[i]);
231 }
232
233 return res;
234 };
235};
236
237/*!
238 * Primary Exports
239 */
240
241module.exports = AssertionError;
242
243/**
244 * ### AssertionError
245 *
246 * An extension of the JavaScript `Error` constructor for
247 * assertion and validation scenarios.
248 *
249 * @param {String} message
250 * @param {Object} properties to include (optional)
251 * @param {callee} start stack function (optional)
252 */
253
254function AssertionError (message, _props, ssf) {
255 var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
256 , props = extend(_props || {});
257
258 // default values
259 this.message = message || 'Unspecified AssertionError';
260 this.showDiff = false;
261
262 // copy from properties
263 for (var key in props) {
264 this[key] = props[key];
265 }
266
267 // capture stack trace
268 ssf = ssf || arguments.callee;
269 if (ssf && Error.captureStackTrace) {
270 Error.captureStackTrace(this, ssf);
271 }
272}
273
274/*!
275 * Inherit from Error.prototype
276 */
277
278AssertionError.prototype = Object.create(Error.prototype);
279
280/*!
281 * Statically set name
282 */
283
284AssertionError.prototype.name = 'AssertionError';
285
286/*!
287 * Ensure correct constructor
288 */
289
290AssertionError.prototype.constructor = AssertionError;
291
292/**
293 * Allow errors to be converted to JSON for static transfer.
294 *
295 * @param {Boolean} include stack (default: `true`)
296 * @return {Object} object that can be `JSON.stringify`
297 */
298
299AssertionError.prototype.toJSON = function (stack) {
300 var extend = exclude('constructor', 'toJSON', 'stack')
301 , props = extend({ name: this.name }, this);
302
303 // include stack if exists and not turned off
304 if (false !== stack && this.stack) {
305 props.stack = this.stack;
306 }
307
308 return props;
309};
310
311});
312require.register("chai/index.js", function(exports, require, module){
313module.exports = require('./lib/chai');
314
315});
316require.register("chai/lib/chai.js", function(exports, require, module){
317/*!
318 * chai
319 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
320 * MIT Licensed
321 */
322
323var used = []
324 , exports = module.exports = {};
325
326/*!
327 * Chai version
328 */
329
330exports.version = '1.7.2';
331
332/*!
333 * Assertion Error
334 */
335
336exports.AssertionError = require('assertion-error');
337
338/*!
339 * Utils for plugins (not exported)
340 */
341
342var util = require('./chai/utils');
343
344/**
345 * # .use(function)
346 *
347 * Provides a way to extend the internals of Chai
348 *
349 * @param {Function}
350 * @returns {this} for chaining
351 * @api public
352 */
353
354exports.use = function (fn) {
355 if (!~used.indexOf(fn)) {
356 fn(this, util);
357 used.push(fn);
358 }
359
360 return this;
361};
362
363/*!
364 * Primary `Assertion` prototype
365 */
366
367var assertion = require('./chai/assertion');
368exports.use(assertion);
369
370/*!
371 * Core Assertions
372 */
373
374var core = require('./chai/core/assertions');
375exports.use(core);
376
377/*!
378 * Expect interface
379 */
380
381var expect = require('./chai/interface/expect');
382exports.use(expect);
383
384/*!
385 * Should interface
386 */
387
388var should = require('./chai/interface/should');
389exports.use(should);
390
391/*!
392 * Assert interface
393 */
394
395var assert = require('./chai/interface/assert');
396exports.use(assert);
397
398});
399require.register("chai/lib/chai/assertion.js", function(exports, require, module){
400/*!
401 * chai
402 * http://chaijs.com
403 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
404 * MIT Licensed
405 */
406
407module.exports = function (_chai, util) {
408 /*!
409 * Module dependencies.
410 */
411
412 var AssertionError = _chai.AssertionError
413 , flag = util.flag;
414
415 /*!
416 * Module export.
417 */
418
419 _chai.Assertion = Assertion;
420
421 /*!
422 * Assertion Constructor
423 *
424 * Creates object for chaining.
425 *
426 * @api private
427 */
428
429 function Assertion (obj, msg, stack) {
430 flag(this, 'ssfi', stack || arguments.callee);
431 flag(this, 'object', obj);
432 flag(this, 'message', msg);
433 }
434
435 /*!
436 * ### Assertion.includeStack
437 *
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
441 *
442 * Assertion.includeStack = true; // enable stack on error
443 *
444 * @api public
445 */
446
447 Assertion.includeStack = false;
448
449 /*!
450 * ### Assertion.showDiff
451 *
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
456 * be shown.
457 *
458 * @api public
459 */
460
461 Assertion.showDiff = true;
462
463 Assertion.addProperty = function (name, fn) {
464 util.addProperty(this.prototype, name, fn);
465 };
466
467 Assertion.addMethod = function (name, fn) {
468 util.addMethod(this.prototype, name, fn);
469 };
470
471 Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
472 util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
473 };
474
475 Assertion.overwriteProperty = function (name, fn) {
476 util.overwriteProperty(this.prototype, name, fn);
477 };
478
479 Assertion.overwriteMethod = function (name, fn) {
480 util.overwriteMethod(this.prototype, name, fn);
481 };
482
483 /*!
484 * ### .assert(expression, message, negateMessage, expected, actual)
485 *
486 * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
487 *
488 * @name assert
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`
494 * @api private
495 */
496
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;
501
502 if (!ok) {
503 var msg = util.getMessage(this, arguments)
504 , actual = util.getActual(this, arguments);
505 throw new AssertionError(msg, {
506 actual: actual
507 , expected: expected
508 , showDiff: showDiff
509 }, (Assertion.includeStack) ? this.assert : flag(this, 'ssfi'));
510 }
511 };
512
513 /*!
514 * ### ._obj
515 *
516 * Quick reference to stored `actual` value for plugin developers.
517 *
518 * @api private
519 */
520
521 Object.defineProperty(Assertion.prototype, '_obj',
522 { get: function () {
523 return flag(this, 'object');
524 }
525 , set: function (val) {
526 flag(this, 'object', val);
527 }
528 });
529};
530
531});
532require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
533/*!
534 * chai
535 * http://chaijs.com
536 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
537 * MIT Licensed
538 */
539
540module.exports = function (chai, _) {
541 var Assertion = chai.Assertion
542 , toString = Object.prototype.toString
543 , flag = _.flag;
544
545 /**
546 * ### Language Chains
547 *
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.
552 *
553 * **Chains**
554 *
555 * - to
556 * - be
557 * - been
558 * - is
559 * - that
560 * - and
561 * - have
562 * - with
563 * - at
564 * - of
565 * - same
566 *
567 * @name language chains
568 * @api public
569 */
570
571 [ 'to', 'be', 'been'
572 , 'is', 'and', 'have'
573 , 'with', 'that', 'at'
574 , 'of', 'same' ].forEach(function (chain) {
575 Assertion.addProperty(chain, function () {
576 return this;
577 });
578 });
579
580 /**
581 * ### .not
582 *
583 * Negates any of assertions following in the chain.
584 *
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');
589 *
590 * @name not
591 * @api public
592 */
593
594 Assertion.addProperty('not', function () {
595 flag(this, 'negate', true);
596 });
597
598 /**
599 * ### .deep
600 *
601 * Sets the `deep` flag, later used by the `equal` and
602 * `property` assertions.
603 *
604 * expect(foo).to.deep.equal({ bar: 'baz' });
605 * expect({ foo: { bar: { baz: 'quux' } } })
606 * .to.have.deep.property('foo.bar.baz', 'quux');
607 *
608 * @name deep
609 * @api public
610 */
611
612 Assertion.addProperty('deep', function () {
613 flag(this, 'deep', true);
614 });
615
616 /**
617 * ### .a(type)
618 *
619 * The `a` and `an` assertions are aliases that can be
620 * used either as language chains or to assert a value's
621 * type.
622 *
623 * // typeof
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');
628 *
629 * // language chain
630 * expect(foo).to.be.an.instanceof(Foo);
631 *
632 * @name a
633 * @alias an
634 * @param {String} type
635 * @param {String} message _optional_
636 * @api public
637 */
638
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 ';
644
645 this.assert(
646 type === _.type(obj)
647 , 'expected #{this} to be ' + article + type
648 , 'expected #{this} not to be ' + article + type
649 );
650 }
651
652 Assertion.addChainableMethod('an', an);
653 Assertion.addChainableMethod('a', an);
654
655 /**
656 * ### .include(value)
657 *
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.
662 *
663 * expect([1,2,3]).to.include(2);
664 * expect('foobar').to.contain('foo');
665 * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
666 *
667 * @name include
668 * @alias contain
669 * @param {Object|String|Number} obj
670 * @param {String} message _optional_
671 * @api public
672 */
673
674 function includeChainingBehavior () {
675 flag(this, 'contains', true);
676 }
677
678 function include (val, msg) {
679 if (msg) flag(this, 'message', msg);
680 var obj = flag(this, 'object')
681 this.assert(
682 ~obj.indexOf(val)
683 , 'expected #{this} to include ' + _.inspect(val)
684 , 'expected #{this} to not include ' + _.inspect(val));
685 }
686
687 Assertion.addChainableMethod('include', include, includeChainingBehavior);
688 Assertion.addChainableMethod('contain', include, includeChainingBehavior);
689
690 /**
691 * ### .ok
692 *
693 * Asserts that the target is truthy.
694 *
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;
700 *
701 * @name ok
702 * @api public
703 */
704
705 Assertion.addProperty('ok', function () {
706 this.assert(
707 flag(this, 'object')
708 , 'expected #{this} to be truthy'
709 , 'expected #{this} to be falsy');
710 });
711
712 /**
713 * ### .true
714 *
715 * Asserts that the target is `true`.
716 *
717 * expect(true).to.be.true;
718 * expect(1).to.not.be.true;
719 *
720 * @name true
721 * @api public
722 */
723
724 Assertion.addProperty('true', function () {
725 this.assert(
726 true === flag(this, 'object')
727 , 'expected #{this} to be true'
728 , 'expected #{this} to be false'
729 , this.negate ? false : true
730 );
731 });
732
733 /**
734 * ### .false
735 *
736 * Asserts that the target is `false`.
737 *
738 * expect(false).to.be.false;
739 * expect(0).to.not.be.false;
740 *
741 * @name false
742 * @api public
743 */
744
745 Assertion.addProperty('false', function () {
746 this.assert(
747 false === flag(this, 'object')
748 , 'expected #{this} to be false'
749 , 'expected #{this} to be true'
750 , this.negate ? true : false
751 );
752 });
753
754 /**
755 * ### .null
756 *
757 * Asserts that the target is `null`.
758 *
759 * expect(null).to.be.null;
760 * expect(undefined).not.to.be.null;
761 *
762 * @name null
763 * @api public
764 */
765
766 Assertion.addProperty('null', function () {
767 this.assert(
768 null === flag(this, 'object')
769 , 'expected #{this} to be null'
770 , 'expected #{this} not to be null'
771 );
772 });
773
774 /**
775 * ### .undefined
776 *
777 * Asserts that the target is `undefined`.
778 *
779 * expect(undefined).to.be.undefined;
780 * expect(null).to.not.be.undefined;
781 *
782 * @name undefined
783 * @api public
784 */
785
786 Assertion.addProperty('undefined', function () {
787 this.assert(
788 undefined === flag(this, 'object')
789 , 'expected #{this} to be undefined'
790 , 'expected #{this} not to be undefined'
791 );
792 });
793
794 /**
795 * ### .exist
796 *
797 * Asserts that the target is neither `null` nor `undefined`.
798 *
799 * var foo = 'hi'
800 * , bar = null
801 * , baz;
802 *
803 * expect(foo).to.exist;
804 * expect(bar).to.not.exist;
805 * expect(baz).to.not.exist;
806 *
807 * @name exist
808 * @api public
809 */
810
811 Assertion.addProperty('exist', function () {
812 this.assert(
813 null != flag(this, 'object')
814 , 'expected #{this} to exist'
815 , 'expected #{this} to not exist'
816 );
817 });
818
819
820 /**
821 * ### .empty
822 *
823 * Asserts that the target's length is `0`. For arrays, it checks
824 * the `length` property. For objects, it gets the count of
825 * enumerable keys.
826 *
827 * expect([]).to.be.empty;
828 * expect('').to.be.empty;
829 * expect({}).to.be.empty;
830 *
831 * @name empty
832 * @api public
833 */
834
835 Assertion.addProperty('empty', function () {
836 var obj = flag(this, 'object')
837 , expected = obj;
838
839 if (Array.isArray(obj) || 'string' === typeof object) {
840 expected = obj.length;
841 } else if (typeof obj === 'object') {
842 expected = Object.keys(obj).length;
843 }
844
845 this.assert(
846 !expected
847 , 'expected #{this} to be empty'
848 , 'expected #{this} not to be empty'
849 );
850 });
851
852 /**
853 * ### .arguments
854 *
855 * Asserts that the target is an arguments object.
856 *
857 * function test () {
858 * expect(arguments).to.be.arguments;
859 * }
860 *
861 * @name arguments
862 * @alias Arguments
863 * @api public
864 */
865
866 function checkArguments () {
867 var obj = flag(this, 'object')
868 , type = Object.prototype.toString.call(obj);
869 this.assert(
870 '[object Arguments]' === type
871 , 'expected #{this} to be arguments but got ' + type
872 , 'expected #{this} to not be arguments'
873 );
874 }
875
876 Assertion.addProperty('arguments', checkArguments);
877 Assertion.addProperty('Arguments', checkArguments);
878
879 /**
880 * ### .equal(value)
881 *
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`.
885 *
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' });
891 *
892 * @name equal
893 * @alias equals
894 * @alias eq
895 * @alias deep.equal
896 * @param {Mixed} value
897 * @param {String} message _optional_
898 * @api public
899 */
900
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);
906 } else {
907 this.assert(
908 val === obj
909 , 'expected #{this} to equal #{exp}'
910 , 'expected #{this} to not equal #{exp}'
911 , val
912 , this._obj
913 , true
914 );
915 }
916 }
917
918 Assertion.addMethod('equal', assertEqual);
919 Assertion.addMethod('equals', assertEqual);
920 Assertion.addMethod('eq', assertEqual);
921
922 /**
923 * ### .eql(value)
924 *
925 * Asserts that the target is deeply equal to `value`.
926 *
927 * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
928 * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
929 *
930 * @name eql
931 * @alias eqls
932 * @param {Mixed} value
933 * @param {String} message _optional_
934 * @api public
935 */
936
937 function assertEql(obj, msg) {
938 if (msg) flag(this, 'message', msg);
939 this.assert(
940 _.eql(obj, flag(this, 'object'))
941 , 'expected #{this} to deeply equal #{exp}'
942 , 'expected #{this} to not deeply equal #{exp}'
943 , obj
944 , this._obj
945 , true
946 );
947 }
948
949 Assertion.addMethod('eql', assertEql);
950 Assertion.addMethod('eqls', assertEql);
951
952 /**
953 * ### .above(value)
954 *
955 * Asserts that the target is greater than `value`.
956 *
957 * expect(10).to.be.above(5);
958 *
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.
963 *
964 * expect('foo').to.have.length.above(2);
965 * expect([ 1, 2, 3 ]).to.have.length.above(2);
966 *
967 * @name above
968 * @alias gt
969 * @alias greaterThan
970 * @param {Number} value
971 * @param {String} message _optional_
972 * @api public
973 */
974
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;
981 this.assert(
982 len > n
983 , 'expected #{this} to have a length above #{exp} but got #{act}'
984 , 'expected #{this} to not have a length above #{exp}'
985 , n
986 , len
987 );
988 } else {
989 this.assert(
990 obj > n
991 , 'expected #{this} to be above ' + n
992 , 'expected #{this} to be at most ' + n
993 );
994 }
995 }
996
997 Assertion.addMethod('above', assertAbove);
998 Assertion.addMethod('gt', assertAbove);
999 Assertion.addMethod('greaterThan', assertAbove);
1000
1001 /**
1002 * ### .least(value)
1003 *
1004 * Asserts that the target is greater than or equal to `value`.
1005 *
1006 * expect(10).to.be.at.least(10);
1007 *
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.
1012 *
1013 * expect('foo').to.have.length.of.at.least(2);
1014 * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
1015 *
1016 * @name least
1017 * @alias gte
1018 * @param {Number} value
1019 * @param {String} message _optional_
1020 * @api public
1021 */
1022
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;
1029 this.assert(
1030 len >= n
1031 , 'expected #{this} to have a length at least #{exp} but got #{act}'
1032 , 'expected #{this} to have a length below #{exp}'
1033 , n
1034 , len
1035 );
1036 } else {
1037 this.assert(
1038 obj >= n
1039 , 'expected #{this} to be at least ' + n
1040 , 'expected #{this} to be below ' + n
1041 );
1042 }
1043 }
1044
1045 Assertion.addMethod('least', assertLeast);
1046 Assertion.addMethod('gte', assertLeast);
1047
1048 /**
1049 * ### .below(value)
1050 *
1051 * Asserts that the target is less than `value`.
1052 *
1053 * expect(5).to.be.below(10);
1054 *
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.
1059 *
1060 * expect('foo').to.have.length.below(4);
1061 * expect([ 1, 2, 3 ]).to.have.length.below(4);
1062 *
1063 * @name below
1064 * @alias lt
1065 * @alias lessThan
1066 * @param {Number} value
1067 * @param {String} message _optional_
1068 * @api public
1069 */
1070
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;
1077 this.assert(
1078 len < n
1079 , 'expected #{this} to have a length below #{exp} but got #{act}'
1080 , 'expected #{this} to not have a length below #{exp}'
1081 , n
1082 , len
1083 );
1084 } else {
1085 this.assert(
1086 obj < n
1087 , 'expected #{this} to be below ' + n
1088 , 'expected #{this} to be at least ' + n
1089 );
1090 }
1091 }
1092
1093 Assertion.addMethod('below', assertBelow);
1094 Assertion.addMethod('lt', assertBelow);
1095 Assertion.addMethod('lessThan', assertBelow);
1096
1097 /**
1098 * ### .most(value)
1099 *
1100 * Asserts that the target is less than or equal to `value`.
1101 *
1102 * expect(5).to.be.at.most(5);
1103 *
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.
1108 *
1109 * expect('foo').to.have.length.of.at.most(4);
1110 * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
1111 *
1112 * @name most
1113 * @alias lte
1114 * @param {Number} value
1115 * @param {String} message _optional_
1116 * @api public
1117 */
1118
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;
1125 this.assert(
1126 len <= n
1127 , 'expected #{this} to have a length at most #{exp} but got #{act}'
1128 , 'expected #{this} to have a length above #{exp}'
1129 , n
1130 , len
1131 );
1132 } else {
1133 this.assert(
1134 obj <= n
1135 , 'expected #{this} to be at most ' + n
1136 , 'expected #{this} to be above ' + n
1137 );
1138 }
1139 }
1140
1141 Assertion.addMethod('most', assertMost);
1142 Assertion.addMethod('lte', assertMost);
1143
1144 /**
1145 * ### .within(start, finish)
1146 *
1147 * Asserts that the target is within a range.
1148 *
1149 * expect(7).to.be.within(5,10);
1150 *
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.
1155 *
1156 * expect('foo').to.have.length.within(2,4);
1157 * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1158 *
1159 * @name within
1160 * @param {Number} start lowerbound inclusive
1161 * @param {Number} finish upperbound inclusive
1162 * @param {String} message _optional_
1163 * @api public
1164 */
1165
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;
1173 this.assert(
1174 len >= start && len <= finish
1175 , 'expected #{this} to have a length within ' + range
1176 , 'expected #{this} to not have a length within ' + range
1177 );
1178 } else {
1179 this.assert(
1180 obj >= start && obj <= finish
1181 , 'expected #{this} to be within ' + range
1182 , 'expected #{this} to not be within ' + range
1183 );
1184 }
1185 });
1186
1187 /**
1188 * ### .instanceof(constructor)
1189 *
1190 * Asserts that the target is an instance of `constructor`.
1191 *
1192 * var Tea = function (name) { this.name = name; }
1193 * , Chai = new Tea('chai');
1194 *
1195 * expect(Chai).to.be.an.instanceof(Tea);
1196 * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
1197 *
1198 * @name instanceof
1199 * @param {Constructor} constructor
1200 * @param {String} message _optional_
1201 * @alias instanceOf
1202 * @api public
1203 */
1204
1205 function assertInstanceOf (constructor, msg) {
1206 if (msg) flag(this, 'message', msg);
1207 var name = _.getName(constructor);
1208 this.assert(
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
1212 );
1213 };
1214
1215 Assertion.addMethod('instanceof', assertInstanceOf);
1216 Assertion.addMethod('instanceOf', assertInstanceOf);
1217
1218 /**
1219 * ### .property(name, [value])
1220 *
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.
1225 *
1226 * // simple referencing
1227 * var obj = { foo: 'bar' };
1228 * expect(obj).to.have.property('foo');
1229 * expect(obj).to.have.property('foo', 'bar');
1230 *
1231 * // deep referencing
1232 * var deepObj = {
1233 * green: { tea: 'matcha' }
1234 * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
1235 * };
1236
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');
1240 *
1241 * You can also use an array as the starting point of a `deep.property`
1242 * assertion, or traverse nested arrays.
1243 *
1244 * var arr = [
1245 * [ 'chai', 'matcha', 'konacha' ]
1246 * , [ { tea: 'chai' }
1247 * , { tea: 'matcha' }
1248 * , { tea: 'konacha' } ]
1249 * ];
1250 *
1251 * expect(arr).to.have.deep.property('[0][1]', 'matcha');
1252 * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
1253 *
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.
1257 *
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' });
1267 *
1268 * @name property
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
1274 * @api public
1275 */
1276
1277 Assertion.addMethod('property', function (name, val, msg) {
1278 if (msg) flag(this, 'message', msg);
1279
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)
1285 : obj[name];
1286
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));
1291 }
1292 } else {
1293 this.assert(
1294 undefined !== value
1295 , 'expected #{this} to have a ' + descriptor + _.inspect(name)
1296 , 'expected #{this} to not have ' + descriptor + _.inspect(name));
1297 }
1298
1299 if (undefined !== val) {
1300 this.assert(
1301 val === value
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}'
1304 , val
1305 , value
1306 );
1307 }
1308
1309 flag(this, 'object', value);
1310 });
1311
1312
1313 /**
1314 * ### .ownProperty(name)
1315 *
1316 * Asserts that the target has an own property `name`.
1317 *
1318 * expect('test').to.have.ownProperty('length');
1319 *
1320 * @name ownProperty
1321 * @alias haveOwnProperty
1322 * @param {String} name
1323 * @param {String} message _optional_
1324 * @api public
1325 */
1326
1327 function assertOwnProperty (name, msg) {
1328 if (msg) flag(this, 'message', msg);
1329 var obj = flag(this, 'object');
1330 this.assert(
1331 obj.hasOwnProperty(name)
1332 , 'expected #{this} to have own property ' + _.inspect(name)
1333 , 'expected #{this} to not have own property ' + _.inspect(name)
1334 );
1335 }
1336
1337 Assertion.addMethod('ownProperty', assertOwnProperty);
1338 Assertion.addMethod('haveOwnProperty', assertOwnProperty);
1339
1340 /**
1341 * ### .length(value)
1342 *
1343 * Asserts that the target's `length` property has
1344 * the expected value.
1345 *
1346 * expect([ 1, 2, 3]).to.have.length(3);
1347 * expect('foobar').to.have.length(6);
1348 *
1349 * Can also be used as a chain precursor to a value
1350 * comparison for the length property.
1351 *
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);
1358 *
1359 * @name length
1360 * @alias lengthOf
1361 * @param {Number} length
1362 * @param {String} message _optional_
1363 * @api public
1364 */
1365
1366 function assertLengthChain () {
1367 flag(this, 'doLength', true);
1368 }
1369
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;
1375
1376 this.assert(
1377 len == n
1378 , 'expected #{this} to have a length of #{exp} but got #{act}'
1379 , 'expected #{this} to not have a length of #{act}'
1380 , n
1381 , len
1382 );
1383 }
1384
1385 Assertion.addChainableMethod('length', assertLength, assertLengthChain);
1386 Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
1387
1388 /**
1389 * ### .match(regexp)
1390 *
1391 * Asserts that the target matches a regular expression.
1392 *
1393 * expect('foobar').to.match(/^foo/);
1394 *
1395 * @name match
1396 * @param {RegExp} RegularExpression
1397 * @param {String} message _optional_
1398 * @api public
1399 */
1400
1401 Assertion.addMethod('match', function (re, msg) {
1402 if (msg) flag(this, 'message', msg);
1403 var obj = flag(this, 'object');
1404 this.assert(
1405 re.exec(obj)
1406 , 'expected #{this} to match ' + re
1407 , 'expected #{this} not to match ' + re
1408 );
1409 });
1410
1411 /**
1412 * ### .string(string)
1413 *
1414 * Asserts that the string target contains another string.
1415 *
1416 * expect('foobar').to.have.string('bar');
1417 *
1418 * @name string
1419 * @param {String} string
1420 * @param {String} message _optional_
1421 * @api public
1422 */
1423
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');
1428
1429 this.assert(
1430 ~obj.indexOf(str)
1431 , 'expected #{this} to contain ' + _.inspect(str)
1432 , 'expected #{this} to not contain ' + _.inspect(str)
1433 );
1434 });
1435
1436
1437 /**
1438 * ### .keys(key1, [key2], [...])
1439 *
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.
1443 *
1444 * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
1445 * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
1446 *
1447 * @name keys
1448 * @alias key
1449 * @param {String...|Array} keys
1450 * @api public
1451 */
1452
1453 function assertKeys (keys) {
1454 var obj = flag(this, 'object')
1455 , str
1456 , ok = true;
1457
1458 keys = keys instanceof Array
1459 ? keys
1460 : Array.prototype.slice.call(arguments);
1461
1462 if (!keys.length) throw new Error('keys required');
1463
1464 var actual = Object.keys(obj)
1465 , len = keys.length;
1466
1467 // Inclusion
1468 ok = keys.every(function(key){
1469 return ~actual.indexOf(key);
1470 });
1471
1472 // Strict
1473 if (!flag(this, 'negate') && !flag(this, 'contains')) {
1474 ok = ok && keys.length == actual.length;
1475 }
1476
1477 // Key string
1478 if (len > 1) {
1479 keys = keys.map(function(key){
1480 return _.inspect(key);
1481 });
1482 var last = keys.pop();
1483 str = keys.join(', ') + ', and ' + last;
1484 } else {
1485 str = _.inspect(keys[0]);
1486 }
1487
1488 // Form
1489 str = (len > 1 ? 'keys ' : 'key ') + str;
1490
1491 // Have / include
1492 str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
1493
1494 // Assertion
1495 this.assert(
1496 ok
1497 , 'expected #{this} to ' + str
1498 , 'expected #{this} to not ' + str
1499 );
1500 }
1501
1502 Assertion.addMethod('keys', assertKeys);
1503 Assertion.addMethod('key', assertKeys);
1504
1505 /**
1506 * ### .throw(constructor)
1507 *
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.
1511 *
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.'));
1521 *
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
1525 * is to use `and`.
1526 *
1527 * expect(fn).to.throw(ReferenceError)
1528 * .and.not.throw(/good function/);
1529 *
1530 * @name throw
1531 * @alias throws
1532 * @alias Throw
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
1537 * @api public
1538 */
1539
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');
1544
1545 var thrown = false
1546 , desiredError = null
1547 , name = null
1548 , thrownError = null;
1549
1550 if (arguments.length === 0) {
1551 errMsg = null;
1552 constructor = null;
1553 } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
1554 errMsg = constructor;
1555 constructor = null;
1556 } else if (constructor && constructor instanceof Error) {
1557 desiredError = constructor;
1558 constructor = null;
1559 errMsg = null;
1560 } else if (typeof constructor === 'function') {
1561 name = (new constructor()).name;
1562 } else {
1563 constructor = null;
1564 }
1565
1566 try {
1567 obj();
1568 } catch (err) {
1569 // first, check desired error
1570 if (desiredError) {
1571 this.assert(
1572 err === desiredError
1573 , 'expected #{this} to throw #{exp} but #{act} was thrown'
1574 , 'expected #{this} to not throw #{exp}'
1575 , desiredError
1576 , err
1577 );
1578
1579 return this;
1580 }
1581 // next, check constructor
1582 if (constructor) {
1583 this.assert(
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'
1587 , name
1588 , err
1589 );
1590
1591 if (!errMsg) return this;
1592 }
1593 // next, check message
1594 var message = 'object' === _.type(err) && "message" in err
1595 ? err.message
1596 : '' + err;
1597
1598 if ((message != null) && errMsg && errMsg instanceof RegExp) {
1599 this.assert(
1600 errMsg.exec(message)
1601 , 'expected #{this} to throw error matching #{exp} but got #{act}'
1602 , 'expected #{this} to throw error not matching #{exp}'
1603 , errMsg
1604 , message
1605 );
1606
1607 return this;
1608 } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
1609 this.assert(
1610 ~message.indexOf(errMsg)
1611 , 'expected #{this} to throw error including #{exp} but got #{act}'
1612 , 'expected #{this} to throw error not including #{act}'
1613 , errMsg
1614 , message
1615 );
1616
1617 return this;
1618 } else {
1619 thrown = true;
1620 thrownError = err;
1621 }
1622 }
1623
1624 var actuallyGot = ''
1625 , expectedThrown = name !== null
1626 ? name
1627 : desiredError
1628 ? '#{exp}' //_.inspect(desiredError)
1629 : 'an error';
1630
1631 if (thrown) {
1632 actuallyGot = ' but #{act} was thrown'
1633 }
1634
1635 this.assert(
1636 thrown === true
1637 , 'expected #{this} to throw ' + expectedThrown + actuallyGot
1638 , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
1639 , desiredError
1640 , thrownError
1641 );
1642 };
1643
1644 Assertion.addMethod('throw', assertThrows);
1645 Assertion.addMethod('throws', assertThrows);
1646 Assertion.addMethod('Throw', assertThrows);
1647
1648 /**
1649 * ### .respondTo(method)
1650 *
1651 * Asserts that the object or class target will respond to a method.
1652 *
1653 * Klass.prototype.bar = function(){};
1654 * expect(Klass).to.respondTo('bar');
1655 * expect(obj).to.respondTo('bar');
1656 *
1657 * To check if a constructor will respond to a static function,
1658 * set the `itself` flag.
1659 *
1660 * Klass.baz = function(){};
1661 * expect(Klass).itself.to.respondTo('baz');
1662 *
1663 * @name respondTo
1664 * @param {String} method
1665 * @param {String} message _optional_
1666 * @api public
1667 */
1668
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]
1675 : obj[method];
1676
1677 this.assert(
1678 'function' === typeof context
1679 , 'expected #{this} to respond to ' + _.inspect(method)
1680 , 'expected #{this} to not respond to ' + _.inspect(method)
1681 );
1682 });
1683
1684 /**
1685 * ### .itself
1686 *
1687 * Sets the `itself` flag, later used by the `respondTo` assertion.
1688 *
1689 * function Foo() {}
1690 * Foo.bar = function() {}
1691 * Foo.prototype.baz = function() {}
1692 *
1693 * expect(Foo).itself.to.respondTo('bar');
1694 * expect(Foo).itself.not.to.respondTo('baz');
1695 *
1696 * @name itself
1697 * @api public
1698 */
1699
1700 Assertion.addProperty('itself', function () {
1701 flag(this, 'itself', true);
1702 });
1703
1704 /**
1705 * ### .satisfy(method)
1706 *
1707 * Asserts that the target passes a given truth test.
1708 *
1709 * expect(1).to.satisfy(function(num) { return num > 0; });
1710 *
1711 * @name satisfy
1712 * @param {Function} matcher
1713 * @param {String} message _optional_
1714 * @api public
1715 */
1716
1717 Assertion.addMethod('satisfy', function (matcher, msg) {
1718 if (msg) flag(this, 'message', msg);
1719 var obj = flag(this, 'object');
1720 this.assert(
1721 matcher(obj)
1722 , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
1723 , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
1724 , this.negate ? false : true
1725 , matcher(obj)
1726 );
1727 });
1728
1729 /**
1730 * ### .closeTo(expected, delta)
1731 *
1732 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
1733 *
1734 * expect(1.5).to.be.closeTo(1, 0.5);
1735 *
1736 * @name closeTo
1737 * @param {Number} expected
1738 * @param {Number} delta
1739 * @param {String} message _optional_
1740 * @api public
1741 */
1742
1743 Assertion.addMethod('closeTo', function (expected, delta, msg) {
1744 if (msg) flag(this, 'message', msg);
1745 var obj = flag(this, 'object');
1746 this.assert(
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
1750 );
1751 });
1752
1753 function isSubsetOf(subset, superset) {
1754 return subset.every(function(elem) {
1755 return superset.indexOf(elem) !== -1;
1756 })
1757 }
1758
1759 /**
1760 * ### .members(set)
1761 *
1762 * Asserts that the target is a superset of `set`,
1763 * or that the target and `set` have the same members.
1764 *
1765 * expect([1, 2, 3]).to.include.members([3, 2]);
1766 * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
1767 *
1768 * expect([4, 2]).to.have.members([2, 4]);
1769 * expect([5, 2]).to.not.have.members([5, 2, 1]);
1770 *
1771 * @name members
1772 * @param {Array} set
1773 * @param {String} message _optional_
1774 * @api public
1775 */
1776
1777 Assertion.addMethod('members', function (subset, msg) {
1778 if (msg) flag(this, 'message', msg);
1779 var obj = flag(this, 'object');
1780
1781 new Assertion(obj).to.be.an('array');
1782 new Assertion(subset).to.be.an('array');
1783
1784 if (flag(this, 'contains')) {
1785 return this.assert(
1786 isSubsetOf(subset, obj)
1787 , 'expected #{this} to be a superset of #{act}'
1788 , 'expected #{this} to not be a superset of #{act}'
1789 , obj
1790 , subset
1791 );
1792 }
1793
1794 this.assert(
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}'
1798 , obj
1799 , subset
1800 );
1801 });
1802};
1803
1804});
1805require.register("chai/lib/chai/interface/assert.js", function(exports, require, module){
1806/*!
1807 * chai
1808 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
1809 * MIT Licensed
1810 */
1811
1812
1813module.exports = function (chai, util) {
1814
1815 /*!
1816 * Chai dependencies.
1817 */
1818
1819 var Assertion = chai.Assertion
1820 , flag = util.flag;
1821
1822 /*!
1823 * Module export.
1824 */
1825
1826 /**
1827 * ### assert(expression, message)
1828 *
1829 * Write your own test expressions.
1830 *
1831 * assert('foo' !== 'bar', 'foo is not bar');
1832 * assert(Array.isArray([]), 'empty arrays are arrays');
1833 *
1834 * @param {Mixed} expression to test for truthiness
1835 * @param {String} message to display on error
1836 * @name assert
1837 * @api public
1838 */
1839
1840 var assert = chai.assert = function (express, errmsg) {
1841 var test = new Assertion(null);
1842 test.assert(
1843 express
1844 , errmsg
1845 , '[ negation message unavailable ]'
1846 );
1847 };
1848
1849 /**
1850 * ### .fail(actual, expected, [message], [operator])
1851 *
1852 * Throw a failure. Node.js `assert` module-compatible.
1853 *
1854 * @name fail
1855 * @param {Mixed} actual
1856 * @param {Mixed} expected
1857 * @param {String} message
1858 * @param {String} operator
1859 * @api public
1860 */
1861
1862 assert.fail = function (actual, expected, message, operator) {
1863 throw new chai.AssertionError({
1864 actual: actual
1865 , expected: expected
1866 , message: message
1867 , operator: operator
1868 , stackStartFunction: assert.fail
1869 });
1870 };
1871
1872 /**
1873 * ### .ok(object, [message])
1874 *
1875 * Asserts that `object` is truthy.
1876 *
1877 * assert.ok('everything', 'everything is ok');
1878 * assert.ok(false, 'this will fail');
1879 *
1880 * @name ok
1881 * @param {Mixed} object to test
1882 * @param {String} message
1883 * @api public
1884 */
1885
1886 assert.ok = function (val, msg) {
1887 new Assertion(val, msg).is.ok;
1888 };
1889
1890 /**
1891 * ### .notOk(object, [message])
1892 *
1893 * Asserts that `object` is falsy.
1894 *
1895 * assert.notOk('everything', 'this will fail');
1896 * assert.notOk(false, 'this will pass');
1897 *
1898 * @name notOk
1899 * @param {Mixed} object to test
1900 * @param {String} message
1901 * @api public
1902 */
1903
1904 assert.notOk = function (val, msg) {
1905 new Assertion(val, msg).is.not.ok;
1906 };
1907
1908 /**
1909 * ### .equal(actual, expected, [message])
1910 *
1911 * Asserts non-strict equality (`==`) of `actual` and `expected`.
1912 *
1913 * assert.equal(3, '3', '== coerces values to strings');
1914 *
1915 * @name equal
1916 * @param {Mixed} actual
1917 * @param {Mixed} expected
1918 * @param {String} message
1919 * @api public
1920 */
1921
1922 assert.equal = function (act, exp, msg) {
1923 var test = new Assertion(act, msg);
1924
1925 test.assert(
1926 exp == flag(test, 'object')
1927 , 'expected #{this} to equal #{exp}'
1928 , 'expected #{this} to not equal #{act}'
1929 , exp
1930 , act
1931 );
1932 };
1933
1934 /**
1935 * ### .notEqual(actual, expected, [message])
1936 *
1937 * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
1938 *
1939 * assert.notEqual(3, 4, 'these numbers are not equal');
1940 *
1941 * @name notEqual
1942 * @param {Mixed} actual
1943 * @param {Mixed} expected
1944 * @param {String} message
1945 * @api public
1946 */
1947
1948 assert.notEqual = function (act, exp, msg) {
1949 var test = new Assertion(act, msg);
1950
1951 test.assert(
1952 exp != flag(test, 'object')
1953 , 'expected #{this} to not equal #{exp}'
1954 , 'expected #{this} to equal #{act}'
1955 , exp
1956 , act
1957 );
1958 };
1959
1960 /**
1961 * ### .strictEqual(actual, expected, [message])
1962 *
1963 * Asserts strict equality (`===`) of `actual` and `expected`.
1964 *
1965 * assert.strictEqual(true, true, 'these booleans are strictly equal');
1966 *
1967 * @name strictEqual
1968 * @param {Mixed} actual
1969 * @param {Mixed} expected
1970 * @param {String} message
1971 * @api public
1972 */
1973
1974 assert.strictEqual = function (act, exp, msg) {
1975 new Assertion(act, msg).to.equal(exp);
1976 };
1977
1978 /**
1979 * ### .notStrictEqual(actual, expected, [message])
1980 *
1981 * Asserts strict inequality (`!==`) of `actual` and `expected`.
1982 *
1983 * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
1984 *
1985 * @name notStrictEqual
1986 * @param {Mixed} actual
1987 * @param {Mixed} expected
1988 * @param {String} message
1989 * @api public
1990 */
1991
1992 assert.notStrictEqual = function (act, exp, msg) {
1993 new Assertion(act, msg).to.not.equal(exp);
1994 };
1995
1996 /**
1997 * ### .deepEqual(actual, expected, [message])
1998 *
1999 * Asserts that `actual` is deeply equal to `expected`.
2000 *
2001 * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
2002 *
2003 * @name deepEqual
2004 * @param {Mixed} actual
2005 * @param {Mixed} expected
2006 * @param {String} message
2007 * @api public
2008 */
2009
2010 assert.deepEqual = function (act, exp, msg) {
2011 new Assertion(act, msg).to.eql(exp);
2012 };
2013
2014 /**
2015 * ### .notDeepEqual(actual, expected, [message])
2016 *
2017 * Assert that `actual` is not deeply equal to `expected`.
2018 *
2019 * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
2020 *
2021 * @name notDeepEqual
2022 * @param {Mixed} actual
2023 * @param {Mixed} expected
2024 * @param {String} message
2025 * @api public
2026 */
2027
2028 assert.notDeepEqual = function (act, exp, msg) {
2029 new Assertion(act, msg).to.not.eql(exp);
2030 };
2031
2032 /**
2033 * ### .isTrue(value, [message])
2034 *
2035 * Asserts that `value` is true.
2036 *
2037 * var teaServed = true;
2038 * assert.isTrue(teaServed, 'the tea has been served');
2039 *
2040 * @name isTrue
2041 * @param {Mixed} value
2042 * @param {String} message
2043 * @api public
2044 */
2045
2046 assert.isTrue = function (val, msg) {
2047 new Assertion(val, msg).is['true'];
2048 };
2049
2050 /**
2051 * ### .isFalse(value, [message])
2052 *
2053 * Asserts that `value` is false.
2054 *
2055 * var teaServed = false;
2056 * assert.isFalse(teaServed, 'no tea yet? hmm...');
2057 *
2058 * @name isFalse
2059 * @param {Mixed} value
2060 * @param {String} message
2061 * @api public
2062 */
2063
2064 assert.isFalse = function (val, msg) {
2065 new Assertion(val, msg).is['false'];
2066 };
2067
2068 /**
2069 * ### .isNull(value, [message])
2070 *
2071 * Asserts that `value` is null.
2072 *
2073 * assert.isNull(err, 'there was no error');
2074 *
2075 * @name isNull
2076 * @param {Mixed} value
2077 * @param {String} message
2078 * @api public
2079 */
2080
2081 assert.isNull = function (val, msg) {
2082 new Assertion(val, msg).to.equal(null);
2083 };
2084
2085 /**
2086 * ### .isNotNull(value, [message])
2087 *
2088 * Asserts that `value` is not null.
2089 *
2090 * var tea = 'tasty chai';
2091 * assert.isNotNull(tea, 'great, time for tea!');
2092 *
2093 * @name isNotNull
2094 * @param {Mixed} value
2095 * @param {String} message
2096 * @api public
2097 */
2098
2099 assert.isNotNull = function (val, msg) {
2100 new Assertion(val, msg).to.not.equal(null);
2101 };
2102
2103 /**
2104 * ### .isUndefined(value, [message])
2105 *
2106 * Asserts that `value` is `undefined`.
2107 *
2108 * var tea;
2109 * assert.isUndefined(tea, 'no tea defined');
2110 *
2111 * @name isUndefined
2112 * @param {Mixed} value
2113 * @param {String} message
2114 * @api public
2115 */
2116
2117 assert.isUndefined = function (val, msg) {
2118 new Assertion(val, msg).to.equal(undefined);
2119 };
2120
2121 /**
2122 * ### .isDefined(value, [message])
2123 *
2124 * Asserts that `value` is not `undefined`.
2125 *
2126 * var tea = 'cup of chai';
2127 * assert.isDefined(tea, 'tea has been defined');
2128 *
2129 * @name isDefined
2130 * @param {Mixed} value
2131 * @param {String} message
2132 * @api public
2133 */
2134
2135 assert.isDefined = function (val, msg) {
2136 new Assertion(val, msg).to.not.equal(undefined);
2137 };
2138
2139 /**
2140 * ### .isFunction(value, [message])
2141 *
2142 * Asserts that `value` is a function.
2143 *
2144 * function serveTea() { return 'cup of tea'; };
2145 * assert.isFunction(serveTea, 'great, we can have tea now');
2146 *
2147 * @name isFunction
2148 * @param {Mixed} value
2149 * @param {String} message
2150 * @api public
2151 */
2152
2153 assert.isFunction = function (val, msg) {
2154 new Assertion(val, msg).to.be.a('function');
2155 };
2156
2157 /**
2158 * ### .isNotFunction(value, [message])
2159 *
2160 * Asserts that `value` is _not_ a function.
2161 *
2162 * var serveTea = [ 'heat', 'pour', 'sip' ];
2163 * assert.isNotFunction(serveTea, 'great, we have listed the steps');
2164 *
2165 * @name isNotFunction
2166 * @param {Mixed} value
2167 * @param {String} message
2168 * @api public
2169 */
2170
2171 assert.isNotFunction = function (val, msg) {
2172 new Assertion(val, msg).to.not.be.a('function');
2173 };
2174
2175 /**
2176 * ### .isObject(value, [message])
2177 *
2178 * Asserts that `value` is an object (as revealed by
2179 * `Object.prototype.toString`).
2180 *
2181 * var selection = { name: 'Chai', serve: 'with spices' };
2182 * assert.isObject(selection, 'tea selection is an object');
2183 *
2184 * @name isObject
2185 * @param {Mixed} value
2186 * @param {String} message
2187 * @api public
2188 */
2189
2190 assert.isObject = function (val, msg) {
2191 new Assertion(val, msg).to.be.a('object');
2192 };
2193
2194 /**
2195 * ### .isNotObject(value, [message])
2196 *
2197 * Asserts that `value` is _not_ an object.
2198 *
2199 * var selection = 'chai'
2200 * assert.isObject(selection, 'tea selection is not an object');
2201 * assert.isObject(null, 'null is not an object');
2202 *
2203 * @name isNotObject
2204 * @param {Mixed} value
2205 * @param {String} message
2206 * @api public
2207 */
2208
2209 assert.isNotObject = function (val, msg) {
2210 new Assertion(val, msg).to.not.be.a('object');
2211 };
2212
2213 /**
2214 * ### .isArray(value, [message])
2215 *
2216 * Asserts that `value` is an array.
2217 *
2218 * var menu = [ 'green', 'chai', 'oolong' ];
2219 * assert.isArray(menu, 'what kind of tea do we want?');
2220 *
2221 * @name isArray
2222 * @param {Mixed} value
2223 * @param {String} message
2224 * @api public
2225 */
2226
2227 assert.isArray = function (val, msg) {
2228 new Assertion(val, msg).to.be.an('array');
2229 };
2230
2231 /**
2232 * ### .isNotArray(value, [message])
2233 *
2234 * Asserts that `value` is _not_ an array.
2235 *
2236 * var menu = 'green|chai|oolong';
2237 * assert.isNotArray(menu, 'what kind of tea do we want?');
2238 *
2239 * @name isNotArray
2240 * @param {Mixed} value
2241 * @param {String} message
2242 * @api public
2243 */
2244
2245 assert.isNotArray = function (val, msg) {
2246 new Assertion(val, msg).to.not.be.an('array');
2247 };
2248
2249 /**
2250 * ### .isString(value, [message])
2251 *
2252 * Asserts that `value` is a string.
2253 *
2254 * var teaOrder = 'chai';
2255 * assert.isString(teaOrder, 'order placed');
2256 *
2257 * @name isString
2258 * @param {Mixed} value
2259 * @param {String} message
2260 * @api public
2261 */
2262
2263 assert.isString = function (val, msg) {
2264 new Assertion(val, msg).to.be.a('string');
2265 };
2266
2267 /**
2268 * ### .isNotString(value, [message])
2269 *
2270 * Asserts that `value` is _not_ a string.
2271 *
2272 * var teaOrder = 4;
2273 * assert.isNotString(teaOrder, 'order placed');
2274 *
2275 * @name isNotString
2276 * @param {Mixed} value
2277 * @param {String} message
2278 * @api public
2279 */
2280
2281 assert.isNotString = function (val, msg) {
2282 new Assertion(val, msg).to.not.be.a('string');
2283 };
2284
2285 /**
2286 * ### .isNumber(value, [message])
2287 *
2288 * Asserts that `value` is a number.
2289 *
2290 * var cups = 2;
2291 * assert.isNumber(cups, 'how many cups');
2292 *
2293 * @name isNumber
2294 * @param {Number} value
2295 * @param {String} message
2296 * @api public
2297 */
2298
2299 assert.isNumber = function (val, msg) {
2300 new Assertion(val, msg).to.be.a('number');
2301 };
2302
2303 /**
2304 * ### .isNotNumber(value, [message])
2305 *
2306 * Asserts that `value` is _not_ a number.
2307 *
2308 * var cups = '2 cups please';
2309 * assert.isNotNumber(cups, 'how many cups');
2310 *
2311 * @name isNotNumber
2312 * @param {Mixed} value
2313 * @param {String} message
2314 * @api public
2315 */
2316
2317 assert.isNotNumber = function (val, msg) {
2318 new Assertion(val, msg).to.not.be.a('number');
2319 };
2320
2321 /**
2322 * ### .isBoolean(value, [message])
2323 *
2324 * Asserts that `value` is a boolean.
2325 *
2326 * var teaReady = true
2327 * , teaServed = false;
2328 *
2329 * assert.isBoolean(teaReady, 'is the tea ready');
2330 * assert.isBoolean(teaServed, 'has tea been served');
2331 *
2332 * @name isBoolean
2333 * @param {Mixed} value
2334 * @param {String} message
2335 * @api public
2336 */
2337
2338 assert.isBoolean = function (val, msg) {
2339 new Assertion(val, msg).to.be.a('boolean');
2340 };
2341
2342 /**
2343 * ### .isNotBoolean(value, [message])
2344 *
2345 * Asserts that `value` is _not_ a boolean.
2346 *
2347 * var teaReady = 'yep'
2348 * , teaServed = 'nope';
2349 *
2350 * assert.isNotBoolean(teaReady, 'is the tea ready');
2351 * assert.isNotBoolean(teaServed, 'has tea been served');
2352 *
2353 * @name isNotBoolean
2354 * @param {Mixed} value
2355 * @param {String} message
2356 * @api public
2357 */
2358
2359 assert.isNotBoolean = function (val, msg) {
2360 new Assertion(val, msg).to.not.be.a('boolean');
2361 };
2362
2363 /**
2364 * ### .typeOf(value, name, [message])
2365 *
2366 * Asserts that `value`'s type is `name`, as determined by
2367 * `Object.prototype.toString`.
2368 *
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');
2375 *
2376 * @name typeOf
2377 * @param {Mixed} value
2378 * @param {String} name
2379 * @param {String} message
2380 * @api public
2381 */
2382
2383 assert.typeOf = function (val, type, msg) {
2384 new Assertion(val, msg).to.be.a(type);
2385 };
2386
2387 /**
2388 * ### .notTypeOf(value, name, [message])
2389 *
2390 * Asserts that `value`'s type is _not_ `name`, as determined by
2391 * `Object.prototype.toString`.
2392 *
2393 * assert.notTypeOf('tea', 'number', 'strings are not numbers');
2394 *
2395 * @name notTypeOf
2396 * @param {Mixed} value
2397 * @param {String} typeof name
2398 * @param {String} message
2399 * @api public
2400 */
2401
2402 assert.notTypeOf = function (val, type, msg) {
2403 new Assertion(val, msg).to.not.be.a(type);
2404 };
2405
2406 /**
2407 * ### .instanceOf(object, constructor, [message])
2408 *
2409 * Asserts that `value` is an instance of `constructor`.
2410 *
2411 * var Tea = function (name) { this.name = name; }
2412 * , chai = new Tea('chai');
2413 *
2414 * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
2415 *
2416 * @name instanceOf
2417 * @param {Object} object
2418 * @param {Constructor} constructor
2419 * @param {String} message
2420 * @api public
2421 */
2422
2423 assert.instanceOf = function (val, type, msg) {
2424 new Assertion(val, msg).to.be.instanceOf(type);
2425 };
2426
2427 /**
2428 * ### .notInstanceOf(object, constructor, [message])
2429 *
2430 * Asserts `value` is not an instance of `constructor`.
2431 *
2432 * var Tea = function (name) { this.name = name; }
2433 * , chai = new String('chai');
2434 *
2435 * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
2436 *
2437 * @name notInstanceOf
2438 * @param {Object} object
2439 * @param {Constructor} constructor
2440 * @param {String} message
2441 * @api public
2442 */
2443
2444 assert.notInstanceOf = function (val, type, msg) {
2445 new Assertion(val, msg).to.not.be.instanceOf(type);
2446 };
2447
2448 /**
2449 * ### .include(haystack, needle, [message])
2450 *
2451 * Asserts that `haystack` includes `needle`. Works
2452 * for strings and arrays.
2453 *
2454 * assert.include('foobar', 'bar', 'foobar contains string "bar"');
2455 * assert.include([ 1, 2, 3 ], 3, 'array contains value');
2456 *
2457 * @name include
2458 * @param {Array|String} haystack
2459 * @param {Mixed} needle
2460 * @param {String} message
2461 * @api public
2462 */
2463
2464 assert.include = function (exp, inc, msg) {
2465 var obj = new Assertion(exp, msg);
2466
2467 if (Array.isArray(exp)) {
2468 obj.to.include(inc);
2469 } else if ('string' === typeof exp) {
2470 obj.to.contain.string(inc);
2471 } else {
2472 throw new chai.AssertionError(
2473 'expected an array or string'
2474 , null
2475 , assert.include
2476 );
2477 }
2478 };
2479
2480 /**
2481 * ### .notInclude(haystack, needle, [message])
2482 *
2483 * Asserts that `haystack` does not include `needle`. Works
2484 * for strings and arrays.
2485 *i
2486 * assert.notInclude('foobar', 'baz', 'string not include substring');
2487 * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
2488 *
2489 * @name notInclude
2490 * @param {Array|String} haystack
2491 * @param {Mixed} needle
2492 * @param {String} message
2493 * @api public
2494 */
2495
2496 assert.notInclude = function (exp, inc, msg) {
2497 var obj = new Assertion(exp, msg);
2498
2499 if (Array.isArray(exp)) {
2500 obj.to.not.include(inc);
2501 } else if ('string' === typeof exp) {
2502 obj.to.not.contain.string(inc);
2503 } else {
2504 throw new chai.AssertionError(
2505 'expected an array or string'
2506 , null
2507 , assert.notInclude
2508 );
2509 }
2510 };
2511
2512 /**
2513 * ### .match(value, regexp, [message])
2514 *
2515 * Asserts that `value` matches the regular expression `regexp`.
2516 *
2517 * assert.match('foobar', /^foo/, 'regexp matches');
2518 *
2519 * @name match
2520 * @param {Mixed} value
2521 * @param {RegExp} regexp
2522 * @param {String} message
2523 * @api public
2524 */
2525
2526 assert.match = function (exp, re, msg) {
2527 new Assertion(exp, msg).to.match(re);
2528 };
2529
2530 /**
2531 * ### .notMatch(value, regexp, [message])
2532 *
2533 * Asserts that `value` does not match the regular expression `regexp`.
2534 *
2535 * assert.notMatch('foobar', /^foo/, 'regexp does not match');
2536 *
2537 * @name notMatch
2538 * @param {Mixed} value
2539 * @param {RegExp} regexp
2540 * @param {String} message
2541 * @api public
2542 */
2543
2544 assert.notMatch = function (exp, re, msg) {
2545 new Assertion(exp, msg).to.not.match(re);
2546 };
2547
2548 /**
2549 * ### .property(object, property, [message])
2550 *
2551 * Asserts that `object` has a property named by `property`.
2552 *
2553 * assert.property({ tea: { green: 'matcha' }}, 'tea');
2554 *
2555 * @name property
2556 * @param {Object} object
2557 * @param {String} property
2558 * @param {String} message
2559 * @api public
2560 */
2561
2562 assert.property = function (obj, prop, msg) {
2563 new Assertion(obj, msg).to.have.property(prop);
2564 };
2565
2566 /**
2567 * ### .notProperty(object, property, [message])
2568 *
2569 * Asserts that `object` does _not_ have a property named by `property`.
2570 *
2571 * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
2572 *
2573 * @name notProperty
2574 * @param {Object} object
2575 * @param {String} property
2576 * @param {String} message
2577 * @api public
2578 */
2579
2580 assert.notProperty = function (obj, prop, msg) {
2581 new Assertion(obj, msg).to.not.have.property(prop);
2582 };
2583
2584 /**
2585 * ### .deepProperty(object, property, [message])
2586 *
2587 * Asserts that `object` has a property named by `property`, which can be a
2588 * string using dot- and bracket-notation for deep reference.
2589 *
2590 * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
2591 *
2592 * @name deepProperty
2593 * @param {Object} object
2594 * @param {String} property
2595 * @param {String} message
2596 * @api public
2597 */
2598
2599 assert.deepProperty = function (obj, prop, msg) {
2600 new Assertion(obj, msg).to.have.deep.property(prop);
2601 };
2602
2603 /**
2604 * ### .notDeepProperty(object, property, [message])
2605 *
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.
2608 *
2609 * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
2610 *
2611 * @name notDeepProperty
2612 * @param {Object} object
2613 * @param {String} property
2614 * @param {String} message
2615 * @api public
2616 */
2617
2618 assert.notDeepProperty = function (obj, prop, msg) {
2619 new Assertion(obj, msg).to.not.have.deep.property(prop);
2620 };
2621
2622 /**
2623 * ### .propertyVal(object, property, value, [message])
2624 *
2625 * Asserts that `object` has a property named by `property` with value given
2626 * by `value`.
2627 *
2628 * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
2629 *
2630 * @name propertyVal
2631 * @param {Object} object
2632 * @param {String} property
2633 * @param {Mixed} value
2634 * @param {String} message
2635 * @api public
2636 */
2637
2638 assert.propertyVal = function (obj, prop, val, msg) {
2639 new Assertion(obj, msg).to.have.property(prop, val);
2640 };
2641
2642 /**
2643 * ### .propertyNotVal(object, property, value, [message])
2644 *
2645 * Asserts that `object` has a property named by `property`, but with a value
2646 * different from that given by `value`.
2647 *
2648 * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
2649 *
2650 * @name propertyNotVal
2651 * @param {Object} object
2652 * @param {String} property
2653 * @param {Mixed} value
2654 * @param {String} message
2655 * @api public
2656 */
2657
2658 assert.propertyNotVal = function (obj, prop, val, msg) {
2659 new Assertion(obj, msg).to.not.have.property(prop, val);
2660 };
2661
2662 /**
2663 * ### .deepPropertyVal(object, property, value, [message])
2664 *
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
2667 * reference.
2668 *
2669 * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
2670 *
2671 * @name deepPropertyVal
2672 * @param {Object} object
2673 * @param {String} property
2674 * @param {Mixed} value
2675 * @param {String} message
2676 * @api public
2677 */
2678
2679 assert.deepPropertyVal = function (obj, prop, val, msg) {
2680 new Assertion(obj, msg).to.have.deep.property(prop, val);
2681 };
2682
2683 /**
2684 * ### .deepPropertyNotVal(object, property, value, [message])
2685 *
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.
2689 *
2690 * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
2691 *
2692 * @name deepPropertyNotVal
2693 * @param {Object} object
2694 * @param {String} property
2695 * @param {Mixed} value
2696 * @param {String} message
2697 * @api public
2698 */
2699
2700 assert.deepPropertyNotVal = function (obj, prop, val, msg) {
2701 new Assertion(obj, msg).to.not.have.deep.property(prop, val);
2702 };
2703
2704 /**
2705 * ### .lengthOf(object, length, [message])
2706 *
2707 * Asserts that `object` has a `length` property with the expected value.
2708 *
2709 * assert.lengthOf([1,2,3], 3, 'array has length of 3');
2710 * assert.lengthOf('foobar', 5, 'string has length of 6');
2711 *
2712 * @name lengthOf
2713 * @param {Mixed} object
2714 * @param {Number} length
2715 * @param {String} message
2716 * @api public
2717 */
2718
2719 assert.lengthOf = function (exp, len, msg) {
2720 new Assertion(exp, msg).to.have.length(len);
2721 };
2722
2723 /**
2724 * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
2725 *
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`.
2729 *
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/);
2735 *
2736 * @name throws
2737 * @alias throw
2738 * @alias Throw
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
2744 * @api public
2745 */
2746
2747 assert.Throw = function (fn, errt, errs, msg) {
2748 if ('string' === typeof errt || errt instanceof RegExp) {
2749 errs = errt;
2750 errt = null;
2751 }
2752
2753 new Assertion(fn, msg).to.Throw(errt, errs);
2754 };
2755
2756 /**
2757 * ### .doesNotThrow(function, [constructor/regexp], [message])
2758 *
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`.
2762 *
2763 * assert.doesNotThrow(fn, Error, 'function does not throw');
2764 *
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
2771 * @api public
2772 */
2773
2774 assert.doesNotThrow = function (fn, type, msg) {
2775 if ('string' === typeof type) {
2776 msg = type;
2777 type = null;
2778 }
2779
2780 new Assertion(fn, msg).to.not.Throw(type);
2781 };
2782
2783 /**
2784 * ### .operator(val1, operator, val2, [message])
2785 *
2786 * Compares two values using `operator`.
2787 *
2788 * assert.operator(1, '<', 2, 'everything is ok');
2789 * assert.operator(1, '>', 2, 'this will fail');
2790 *
2791 * @name operator
2792 * @param {Mixed} val1
2793 * @param {String} operator
2794 * @param {Mixed} val2
2795 * @param {String} message
2796 * @api public
2797 */
2798
2799 assert.operator = function (val, operator, val2, msg) {
2800 if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
2801 throw new Error('Invalid operator "' + operator + '"');
2802 }
2803 var test = new Assertion(eval(val + operator + val2), msg);
2804 test.assert(
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) );
2808 };
2809
2810 /**
2811 * ### .closeTo(actual, expected, delta, [message])
2812 *
2813 * Asserts that the target is equal `expected`, to within a +/- `delta` range.
2814 *
2815 * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
2816 *
2817 * @name closeTo
2818 * @param {Number} actual
2819 * @param {Number} expected
2820 * @param {Number} delta
2821 * @param {String} message
2822 * @api public
2823 */
2824
2825 assert.closeTo = function (act, exp, delta, msg) {
2826 new Assertion(act, msg).to.be.closeTo(exp, delta);
2827 };
2828
2829 /**
2830 * ### .sameMembers(set1, set2, [message])
2831 *
2832 * Asserts that `set1` and `set2` have the same members.
2833 * Order is not taken into account.
2834 *
2835 * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
2836 *
2837 * @name sameMembers
2838 * @param {Array} superset
2839 * @param {Array} subset
2840 * @param {String} message
2841 * @api public
2842 */
2843
2844 assert.sameMembers = function (set1, set2, msg) {
2845 new Assertion(set1, msg).to.have.same.members(set2);
2846 }
2847
2848 /**
2849 * ### .includeMembers(superset, subset, [message])
2850 *
2851 * Asserts that `subset` is included in `superset`.
2852 * Order is not taken into account.
2853 *
2854 * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
2855 *
2856 * @name includeMembers
2857 * @param {Array} superset
2858 * @param {Array} subset
2859 * @param {String} message
2860 * @api public
2861 */
2862
2863 assert.includeMembers = function (superset, subset, msg) {
2864 new Assertion(superset, msg).to.include.members(subset);
2865 }
2866
2867 /*!
2868 * Undocumented / untested
2869 */
2870
2871 assert.ifError = function (val, msg) {
2872 new Assertion(val, msg).to.not.be.ok;
2873 };
2874
2875 /*!
2876 * Aliases.
2877 */
2878
2879 (function alias(name, as){
2880 assert[as] = assert[name];
2881 return alias;
2882 })
2883 ('Throw', 'throw')
2884 ('Throw', 'throws');
2885};
2886
2887});
2888require.register("chai/lib/chai/interface/expect.js", function(exports, require, module){
2889/*!
2890 * chai
2891 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2892 * MIT Licensed
2893 */
2894
2895module.exports = function (chai, util) {
2896 chai.expect = function (val, message) {
2897 return new chai.Assertion(val, message);
2898 };
2899};
2900
2901
2902});
2903require.register("chai/lib/chai/interface/should.js", function(exports, require, module){
2904/*!
2905 * chai
2906 * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2907 * MIT Licensed
2908 */
2909
2910module.exports = function (chai, util) {
2911 var Assertion = chai.Assertion;
2912
2913 function loadShould () {
2914 // modify Object.prototype to have `should`
2915 Object.defineProperty(Object.prototype, 'should',
2916 {
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()`.
2921 //
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', {
2925 value: value,
2926 enumerable: true,
2927 configurable: true,
2928 writable: true
2929 });
2930 }
2931 , get: function(){
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);
2936 }
2937 return new Assertion(this);
2938 }
2939 , configurable: true
2940 });
2941
2942 var should = {};
2943
2944 should.equal = function (val1, val2, msg) {
2945 new Assertion(val1, msg).to.equal(val2);
2946 };
2947
2948 should.Throw = function (fn, errt, errs, msg) {
2949 new Assertion(fn, msg).to.Throw(errt, errs);
2950 };
2951
2952 should.exist = function (val, msg) {
2953 new Assertion(val, msg).to.exist;
2954 }
2955
2956 // negation
2957 should.not = {}
2958
2959 should.not.equal = function (val1, val2, msg) {
2960 new Assertion(val1, msg).to.not.equal(val2);
2961 };
2962
2963 should.not.Throw = function (fn, errt, errs, msg) {
2964 new Assertion(fn, msg).to.not.Throw(errt, errs);
2965 };
2966
2967 should.not.exist = function (val, msg) {
2968 new Assertion(val, msg).to.not.exist;
2969 }
2970
2971 should['throw'] = should['Throw'];
2972 should.not['throw'] = should.not['Throw'];
2973
2974 return should;
2975 };
2976
2977 chai.should = loadShould;
2978 chai.Should = loadShould;
2979};
2980
2981});
2982require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports, require, module){
2983/*!
2984 * Chai - addChainingMethod utility
2985 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2986 * MIT Licensed
2987 */
2988
2989/*!
2990 * Module dependencies
2991 */
2992
2993var transferFlags = require('./transferFlags');
2994
2995/*!
2996 * Module variables
2997 */
2998
2999// Check whether `__proto__` is supported
3000var hasProtoSupport = '__proto__' in Object;
3001
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).
3005var excludeNames = /^(?:length|name|arguments|caller)$/;
3006
3007// Cache `Function` properties
3008var call = Function.prototype.call,
3009 apply = Function.prototype.apply;
3010
3011/**
3012 * ### addChainableMethod (ctx, name, method, chainingBehavior)
3013 *
3014 * Adds a method to an object, such that the method can also be chained.
3015 *
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);
3019 * });
3020 *
3021 * Can also be accessed directly from `chai.Assertion`.
3022 *
3023 * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
3024 *
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`.
3027 *
3028 * expect(fooStr).to.be.foo('bar');
3029 * expect(fooStr).to.be.foo.equal('foo');
3030 *
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
3036 * @api public
3037 */
3038
3039module.exports = function (ctx, name, method, chainingBehavior) {
3040 if (typeof chainingBehavior !== 'function')
3041 chainingBehavior = function () { };
3042
3043 Object.defineProperty(ctx, name,
3044 { get: function () {
3045 chainingBehavior.call(this);
3046
3047 var assert = function () {
3048 var result = method.apply(this, arguments);
3049 return result === undefined ? this : result;
3050 };
3051
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;
3059 }
3060 // Otherwise, redefine all properties (slow!)
3061 else {
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);
3067 }
3068 });
3069 }
3070
3071 transferFlags(this, assert);
3072 return assert;
3073 }
3074 , configurable: true
3075 });
3076};
3077
3078});
3079require.register("chai/lib/chai/utils/addMethod.js", function(exports, require, module){
3080/*!
3081 * Chai - addMethod utility
3082 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3083 * MIT Licensed
3084 */
3085
3086/**
3087 * ### .addMethod (ctx, name, method)
3088 *
3089 * Adds a method to the prototype of an object.
3090 *
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);
3094 * });
3095 *
3096 * Can also be accessed directly from `chai.Assertion`.
3097 *
3098 * chai.Assertion.addMethod('foo', fn);
3099 *
3100 * Then can be used as any other assertion.
3101 *
3102 * expect(fooStr).to.be.foo('bar');
3103 *
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
3107 * @name addMethod
3108 * @api public
3109 */
3110
3111module.exports = function (ctx, name, method) {
3112 ctx[name] = function () {
3113 var result = method.apply(this, arguments);
3114 return result === undefined ? this : result;
3115 };
3116};
3117
3118});
3119require.register("chai/lib/chai/utils/addProperty.js", function(exports, require, module){
3120/*!
3121 * Chai - addProperty utility
3122 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3123 * MIT Licensed
3124 */
3125
3126/**
3127 * ### addProperty (ctx, name, getter)
3128 *
3129 * Adds a property to the prototype of an object.
3130 *
3131 * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
3132 * var obj = utils.flag(this, 'object');
3133 * new chai.Assertion(obj).to.be.instanceof(Foo);
3134 * });
3135 *
3136 * Can also be accessed directly from `chai.Assertion`.
3137 *
3138 * chai.Assertion.addProperty('foo', fn);
3139 *
3140 * Then can be used as any other assertion.
3141 *
3142 * expect(myFoo).to.be.foo;
3143 *
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
3147 * @name addProperty
3148 * @api public
3149 */
3150
3151module.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;
3156 }
3157 , configurable: true
3158 });
3159};
3160
3161});
3162require.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
3165
3166module.exports = _deepEqual;
3167
3168var getEnumerableProperties = require('./getEnumerableProperties');
3169
3170// for the browser
3171var Buffer;
3172try {
3173 Buffer = require('buffer').Buffer;
3174} catch (ex) {
3175 Buffer = {
3176 isBuffer: function () { return false; }
3177 };
3178}
3179
3180function _deepEqual(actual, expected, memos) {
3181
3182 // 7.1. All identical values are equivalent, as determined by ===.
3183 if (actual === expected) {
3184 return true;
3185
3186 } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
3187 if (actual.length != expected.length) return false;
3188
3189 for (var i = 0; i < actual.length; i++) {
3190 if (actual[i] !== expected[i]) return false;
3191 }
3192
3193 return true;
3194
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();
3200
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;
3205
3206 } else if (expected instanceof RegExp) {
3207 if (!(actual instanceof RegExp)) return false;
3208 return actual.toString() === expected.toString();
3209
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.
3216 } else {
3217 return objEquiv(actual, expected, memos);
3218 }
3219}
3220
3221function isUndefinedOrNull(value) {
3222 return value === null || value === undefined;
3223}
3224
3225function isArguments(object) {
3226 return Object.prototype.toString.call(object) == '[object Arguments]';
3227}
3228
3229function objEquiv(a, b, memos) {
3230 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
3231 return false;
3232
3233 // an identical 'prototype' property.
3234 if (a.prototype !== b.prototype) return false;
3235
3236 // check if we have already compared a and b
3237 var i;
3238 if (memos) {
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))
3242 return true;
3243 }
3244 } else {
3245 memos = [];
3246 }
3247
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)) {
3252 return false;
3253 }
3254 a = pSlice.call(a);
3255 b = pSlice.call(b);
3256 return _deepEqual(a, b, memos);
3257 }
3258 try {
3259 var ka = getEnumerableProperties(a),
3260 kb = getEnumerableProperties(b),
3261 key;
3262 } catch (e) {//happens when one is a string literal and the other isn't
3263 return false;
3264 }
3265
3266 // having the same number of owned properties (keys incorporates
3267 // hasOwnProperty)
3268 if (ka.length != kb.length)
3269 return false;
3270
3271 //the same set of keys (although not necessarily the same order),
3272 ka.sort();
3273 kb.sort();
3274 //~~~cheap key test
3275 for (i = ka.length - 1; i >= 0; i--) {
3276 if (ka[i] != kb[i])
3277 return false;
3278 }
3279
3280 // remember objects we have compared to guard against circular references
3281 memos.push([ a, b ]);
3282
3283 //equivalent values for every corresponding key, and
3284 //~~~possibly expensive deep test
3285 for (i = ka.length - 1; i >= 0; i--) {
3286 key = ka[i];
3287 if (!_deepEqual(a[key], b[key], memos)) return false;
3288 }
3289
3290 return true;
3291}
3292
3293});
3294require.register("chai/lib/chai/utils/flag.js", function(exports, require, module){
3295/*!
3296 * Chai - flag utility
3297 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3298 * MIT Licensed
3299 */
3300
3301/**
3302 * ### flag(object ,key, [value])
3303 *
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.
3308 *
3309 * utils.flag(this, 'foo', 'bar'); // setter
3310 * utils.flag(this, 'foo'); // getter, returns `bar`
3311 *
3312 * @param {Object} object (constructed Assertion
3313 * @param {String} key
3314 * @param {Mixed} value (optional)
3315 * @name flag
3316 * @api private
3317 */
3318
3319module.exports = function (obj, key, value) {
3320 var flags = obj.__flags || (obj.__flags = Object.create(null));
3321 if (arguments.length === 3) {
3322 flags[key] = value;
3323 } else {
3324 return flags[key];
3325 }
3326};
3327
3328});
3329require.register("chai/lib/chai/utils/getActual.js", function(exports, require, module){
3330/*!
3331 * Chai - getActual utility
3332 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3333 * MIT Licensed
3334 */
3335
3336/**
3337 * # getActual(object, [actual])
3338 *
3339 * Returns the `actual` value for an Assertion
3340 *
3341 * @param {Object} object (constructed Assertion)
3342 * @param {Arguments} chai.Assertion.prototype.assert arguments
3343 */
3344
3345module.exports = function (obj, args) {
3346 var actual = args[4];
3347 return 'undefined' !== typeof actual ? actual : obj._obj;
3348};
3349
3350});
3351require.register("chai/lib/chai/utils/getEnumerableProperties.js", function(exports, require, module){
3352/*!
3353 * Chai - getEnumerableProperties utility
3354 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3355 * MIT Licensed
3356 */
3357
3358/**
3359 * ### .getEnumerableProperties(object)
3360 *
3361 * This allows the retrieval of enumerable property names of an object,
3362 * inherited or not.
3363 *
3364 * @param {Object} object
3365 * @returns {Array}
3366 * @name getEnumerableProperties
3367 * @api public
3368 */
3369
3370module.exports = function getEnumerableProperties(object) {
3371 var result = [];
3372 for (var name in object) {
3373 result.push(name);
3374 }
3375 return result;
3376};
3377
3378});
3379require.register("chai/lib/chai/utils/getMessage.js", function(exports, require, module){
3380/*!
3381 * Chai - message composition utility
3382 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3383 * MIT Licensed
3384 */
3385
3386/*!
3387 * Module dependancies
3388 */
3389
3390var flag = require('./flag')
3391 , getActual = require('./getActual')
3392 , inspect = require('./inspect')
3393 , objDisplay = require('./objDisplay');
3394
3395/**
3396 * ### .getMessage(object, message, negateMessage)
3397 *
3398 * Construct the error message based on flags
3399 * and template tags. Template tags will return
3400 * a stringified inspection of the object referenced.
3401 *
3402 * Message template tags:
3403 * - `#{this}` current asserted object
3404 * - `#{act}` actual value
3405 * - `#{exp}` expected value
3406 *
3407 * @param {Object} object (constructed Assertion)
3408 * @param {Arguments} chai.Assertion.prototype.assert arguments
3409 * @name getMessage
3410 * @api public
3411 */
3412
3413module.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');
3420
3421 msg = msg || '';
3422 msg = msg
3423 .replace(/#{this}/g, objDisplay(val))
3424 .replace(/#{act}/g, objDisplay(actual))
3425 .replace(/#{exp}/g, objDisplay(expected));
3426
3427 return flagMsg ? flagMsg + ': ' + msg : msg;
3428};
3429
3430});
3431require.register("chai/lib/chai/utils/getName.js", function(exports, require, module){
3432/*!
3433 * Chai - getName utility
3434 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3435 * MIT Licensed
3436 */
3437
3438/**
3439 * # getName(func)
3440 *
3441 * Gets the name of a function, in a cross-browser way.
3442 *
3443 * @param {Function} a function (usually a constructor)
3444 */
3445
3446module.exports = function (func) {
3447 if (func.name) return func.name;
3448
3449 var match = /^\s?function ([^(]*)\(/.exec(func);
3450 return match && match[1] ? match[1] : "";
3451};
3452
3453});
3454require.register("chai/lib/chai/utils/getPathValue.js", function(exports, require, module){
3455/*!
3456 * Chai - getPathValue utility
3457 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3458 * @see https://github.com/logicalparadox/filtr
3459 * MIT Licensed
3460 */
3461
3462/**
3463 * ### .getPathValue(path, object)
3464 *
3465 * This allows the retrieval of values in an
3466 * object given a string path.
3467 *
3468 * var obj = {
3469 * prop1: {
3470 * arr: ['a', 'b', 'c']
3471 * , str: 'Hello'
3472 * }
3473 * , prop2: {
3474 * arr: [ { nested: 'Universe' } ]
3475 * , str: 'Hello again!'
3476 * }
3477 * }
3478 *
3479 * The following would be the results.
3480 *
3481 * getPathValue('prop1.str', obj); // Hello
3482 * getPathValue('prop1.att[2]', obj); // b
3483 * getPathValue('prop2.arr[0].nested', obj); // Universe
3484 *
3485 * @param {String} path
3486 * @param {Object} object
3487 * @returns {Object} value or `undefined`
3488 * @name getPathValue
3489 * @api public
3490 */
3491
3492var getPathValue = module.exports = function (path, obj) {
3493 var parsed = parsePath(path);
3494 return _getPathValue(parsed, obj);
3495};
3496
3497/*!
3498 * ## parsePath(path)
3499 *
3500 * Helper function used to parse string object
3501 * paths. Use in conjunction with `_getPathValue`.
3502 *
3503 * var parsed = parsePath('myobject.property.subprop');
3504 *
3505 * ### Paths:
3506 *
3507 * * Can be as near infinitely deep and nested
3508 * * Arrays are also valid using the formal `myobject.document[3].property`.
3509 *
3510 * @param {String} path
3511 * @returns {Object} parsed
3512 * @api private
3513 */
3514
3515function 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 };
3523 });
3524};
3525
3526/*!
3527 * ## _getPathValue(parsed, obj)
3528 *
3529 * Helper companion function for `.parsePath` that returns
3530 * the value located at the parsed address.
3531 *
3532 * var value = getPathValue(parsed, obj);
3533 *
3534 * @param {Object} parsed definition from `parsePath`.
3535 * @param {Object} object to search against
3536 * @returns {Object|Undefined} value
3537 * @api private
3538 */
3539
3540function _getPathValue (parsed, obj) {
3541 var tmp = obj
3542 , res;
3543 for (var i = 0, l = parsed.length; i < l; i++) {
3544 var part = parsed[i];
3545 if (tmp) {
3546 if ('undefined' !== typeof part.p)
3547 tmp = tmp[part.p];
3548 else if ('undefined' !== typeof part.i)
3549 tmp = tmp[part.i];
3550 if (i == (l - 1)) res = tmp;
3551 } else {
3552 res = undefined;
3553 }
3554 }
3555 return res;
3556};
3557
3558});
3559require.register("chai/lib/chai/utils/getProperties.js", function(exports, require, module){
3560/*!
3561 * Chai - getProperties utility
3562 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3563 * MIT Licensed
3564 */
3565
3566/**
3567 * ### .getProperties(object)
3568 *
3569 * This allows the retrieval of property names of an object, enumerable or not,
3570 * inherited or not.
3571 *
3572 * @param {Object} object
3573 * @returns {Array}
3574 * @name getProperties
3575 * @api public
3576 */
3577
3578module.exports = function getProperties(object) {
3579 var result = Object.getOwnPropertyNames(subject);
3580
3581 function addProperty(property) {
3582 if (result.indexOf(property) === -1) {
3583 result.push(property);
3584 }
3585 }
3586
3587 var proto = Object.getPrototypeOf(subject);
3588 while (proto !== null) {
3589 Object.getOwnPropertyNames(proto).forEach(addProperty);
3590 proto = Object.getPrototypeOf(proto);
3591 }
3592
3593 return result;
3594};
3595
3596});
3597require.register("chai/lib/chai/utils/index.js", function(exports, require, module){
3598/*!
3599 * chai
3600 * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
3601 * MIT Licensed
3602 */
3603
3604/*!
3605 * Main exports
3606 */
3607
3608var exports = module.exports = {};
3609
3610/*!
3611 * test utility
3612 */
3613
3614exports.test = require('./test');
3615
3616/*!
3617 * type utility
3618 */
3619
3620exports.type = require('./type');
3621
3622/*!
3623 * message utility
3624 */
3625
3626exports.getMessage = require('./getMessage');
3627
3628/*!
3629 * actual utility
3630 */
3631
3632exports.getActual = require('./getActual');
3633
3634/*!
3635 * Inspect util
3636 */
3637
3638exports.inspect = require('./inspect');
3639
3640/*!
3641 * Object Display util
3642 */
3643
3644exports.objDisplay = require('./objDisplay');
3645
3646/*!
3647 * Flag utility
3648 */
3649
3650exports.flag = require('./flag');
3651
3652/*!
3653 * Flag transferring utility
3654 */
3655
3656exports.transferFlags = require('./transferFlags');
3657
3658/*!
3659 * Deep equal utility
3660 */
3661
3662exports.eql = require('./eql');
3663
3664/*!
3665 * Deep path value
3666 */
3667
3668exports.getPathValue = require('./getPathValue');
3669
3670/*!
3671 * Function name
3672 */
3673
3674exports.getName = require('./getName');
3675
3676/*!
3677 * add Property
3678 */
3679
3680exports.addProperty = require('./addProperty');
3681
3682/*!
3683 * add Method
3684 */
3685
3686exports.addMethod = require('./addMethod');
3687
3688/*!
3689 * overwrite Property
3690 */
3691
3692exports.overwriteProperty = require('./overwriteProperty');
3693
3694/*!
3695 * overwrite Method
3696 */
3697
3698exports.overwriteMethod = require('./overwriteMethod');
3699
3700/*!
3701 * Add a chainable method
3702 */
3703
3704exports.addChainableMethod = require('./addChainableMethod');
3705
3706
3707});
3708require.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
3711
3712var getName = require('./getName');
3713var getProperties = require('./getProperties');
3714var getEnumerableProperties = require('./getEnumerableProperties');
3715
3716module.exports = inspect;
3717
3718/**
3719 * Echos the value of a value. Trys to print the value out
3720 * in the best way possible given the different types.
3721 *
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).
3728 */
3729function inspect(obj, showHidden, depth, colors) {
3730 var ctx = {
3731 showHidden: showHidden,
3732 seen: [],
3733 stylize: function (str) { return str; }
3734 };
3735 return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
3736}
3737
3738// https://gist.github.com/1044128/
3739var 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();
3745 var html;
3746 if (document.xmlVersion) {
3747 return xmlSerializer.serializeToString(element);
3748 } else {
3749 container.appendChild(element.cloneNode(false));
3750 html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
3751 container.innerHTML = '';
3752 return html;
3753 }
3754};
3755
3756// Returns true if object is a DOM element.
3757var isDOMElement = function (object) {
3758 if (typeof HTMLElement === 'object') {
3759 return object instanceof HTMLElement;
3760 } else {
3761 return object &&
3762 typeof object === 'object' &&
3763 object.nodeType === 1 &&
3764 typeof object.nodeName === 'string';
3765 }
3766};
3767
3768function 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);
3779 }
3780 return ret;
3781 }
3782
3783 // Primitive types cannot have properties
3784 var primitive = formatPrimitive(ctx, value);
3785 if (primitive) {
3786 return primitive;
3787 }
3788
3789 // If it's DOM elem, get outer HTML.
3790 if (isDOMElement(value)) {
3791 return getOuterHTML(value);
3792 }
3793
3794 // Look up the keys of the object.
3795 var visibleKeys = getEnumerableProperties(value);
3796 var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
3797
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')
3804 ))) {
3805 if (typeof value === 'function') {
3806 var name = getName(value);
3807 var nameSuffix = name ? ': ' + name : '';
3808 return ctx.stylize('[Function' + nameSuffix + ']', 'special');
3809 }
3810 if (isRegExp(value)) {
3811 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3812 }
3813 if (isDate(value)) {
3814 return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
3815 }
3816 if (isError(value)) {
3817 return formatError(value);
3818 }
3819 }
3820
3821 var base = '', array = false, braces = ['{', '}'];
3822
3823 // Make Array say that they are Array
3824 if (isArray(value)) {
3825 array = true;
3826 braces = ['[', ']'];
3827 }
3828
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 + ']';
3834 }
3835
3836 // Make RegExps say that they are RegExps
3837 if (isRegExp(value)) {
3838 base = ' ' + RegExp.prototype.toString.call(value);
3839 }
3840
3841 // Make dates with properties first say the date
3842 if (isDate(value)) {
3843 base = ' ' + Date.prototype.toUTCString.call(value);
3844 }
3845
3846 // Make error with message first say the error
3847 if (isError(value)) {
3848 return formatError(value);
3849 }
3850
3851 if (keys.length === 0 && (!array || value.length == 0)) {
3852 return braces[0] + base + braces[1];
3853 }
3854
3855 if (recurseTimes < 0) {
3856 if (isRegExp(value)) {
3857 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3858 } else {
3859 return ctx.stylize('[Object]', 'special');
3860 }
3861 }
3862
3863 ctx.seen.push(value);
3864
3865 var output;
3866 if (array) {
3867 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
3868 } else {
3869 output = keys.map(function(key) {
3870 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
3871 });
3872 }
3873
3874 ctx.seen.pop();
3875
3876 return reduceToSingleString(output, base, braces);
3877}
3878
3879
3880function formatPrimitive(ctx, value) {
3881 switch (typeof value) {
3882 case 'undefined':
3883 return ctx.stylize('undefined', 'undefined');
3884
3885 case 'string':
3886 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
3887 .replace(/'/g, "\\'")
3888 .replace(/\\"/g, '"') + '\'';
3889 return ctx.stylize(simple, 'string');
3890
3891 case 'number':
3892 return ctx.stylize('' + value, 'number');
3893
3894 case 'boolean':
3895 return ctx.stylize('' + value, 'boolean');
3896 }
3897 // For some reason typeof null is "object", so special case here.
3898 if (value === null) {
3899 return ctx.stylize('null', 'null');
3900 }
3901}
3902
3903
3904function formatError(value) {
3905 return '[' + Error.prototype.toString.call(value) + ']';
3906}
3907
3908
3909function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
3910 var output = [];
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,
3914 String(i), true));
3915 } else {
3916 output.push('');
3917 }
3918 }
3919 keys.forEach(function(key) {
3920 if (!key.match(/^\d+$/)) {
3921 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3922 key, true));
3923 }
3924 });
3925 return output;
3926}
3927
3928
3929function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3930 var name, str;
3931 if (value.__lookupGetter__) {
3932 if (value.__lookupGetter__(key)) {
3933 if (value.__lookupSetter__(key)) {
3934 str = ctx.stylize('[Getter/Setter]', 'special');
3935 } else {
3936 str = ctx.stylize('[Getter]', 'special');
3937 }
3938 } else {
3939 if (value.__lookupSetter__(key)) {
3940 str = ctx.stylize('[Setter]', 'special');
3941 }
3942 }
3943 }
3944 if (visibleKeys.indexOf(key) < 0) {
3945 name = '[' + key + ']';
3946 }
3947 if (!str) {
3948 if (ctx.seen.indexOf(value[key]) < 0) {
3949 if (recurseTimes === null) {
3950 str = formatValue(ctx, value[key], null);
3951 } else {
3952 str = formatValue(ctx, value[key], recurseTimes - 1);
3953 }
3954 if (str.indexOf('\n') > -1) {
3955 if (array) {
3956 str = str.split('\n').map(function(line) {
3957 return ' ' + line;
3958 }).join('\n').substr(2);
3959 } else {
3960 str = '\n' + str.split('\n').map(function(line) {
3961 return ' ' + line;
3962 }).join('\n');
3963 }
3964 }
3965 } else {
3966 str = ctx.stylize('[Circular]', 'special');
3967 }
3968 }
3969 if (typeof name === 'undefined') {
3970 if (array && key.match(/^\d+$/)) {
3971 return str;
3972 }
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');
3977 } else {
3978 name = name.replace(/'/g, "\\'")
3979 .replace(/\\"/g, '"')
3980 .replace(/(^"|"$)/g, "'");
3981 name = ctx.stylize(name, 'string');
3982 }
3983 }
3984
3985 return name + ': ' + str;
3986}
3987
3988
3989function reduceToSingleString(output, base, braces) {
3990 var numLinesEst = 0;
3991 var length = output.reduce(function(prev, cur) {
3992 numLinesEst++;
3993 if (cur.indexOf('\n') >= 0) numLinesEst++;
3994 return prev + cur.length + 1;
3995 }, 0);
3996
3997 if (length > 60) {
3998 return braces[0] +
3999 (base === '' ? '' : base + '\n ') +
4000 ' ' +
4001 output.join(',\n ') +
4002 ' ' +
4003 braces[1];
4004 }
4005
4006 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
4007}
4008
4009function isArray(ar) {
4010 return Array.isArray(ar) ||
4011 (typeof ar === 'object' && objectToString(ar) === '[object Array]');
4012}
4013
4014function isRegExp(re) {
4015 return typeof re === 'object' && objectToString(re) === '[object RegExp]';
4016}
4017
4018function isDate(d) {
4019 return typeof d === 'object' && objectToString(d) === '[object Date]';
4020}
4021
4022function isError(e) {
4023 return typeof e === 'object' && objectToString(e) === '[object Error]';
4024}
4025
4026function objectToString(o) {
4027 return Object.prototype.toString.call(o);
4028}
4029
4030});
4031require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require, module){
4032/*!
4033 * Chai - flag utility
4034 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4035 * MIT Licensed
4036 */
4037
4038/*!
4039 * Module dependancies
4040 */
4041
4042var inspect = require('./inspect');
4043
4044/**
4045 * ### .objDisplay (object)
4046 *
4047 * Determines if an object or an array matches
4048 * criteria to be inspected in-line for error
4049 * messages or should be truncated.
4050 *
4051 * @param {Mixed} javascript object to inspect
4052 * @name objDisplay
4053 * @api public
4054 */
4055
4056module.exports = function (obj) {
4057 var str = inspect(obj)
4058 , type = Object.prototype.toString.call(obj);
4059
4060 if (str.length >= 40) {
4061 if (type === '[object Function]') {
4062 return !obj.name || obj.name === ''
4063 ? '[Function]'
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(', ') + ', ...'
4071 : keys.join(', ');
4072 return '{ Object (' + kstr + ') }';
4073 } else {
4074 return str;
4075 }
4076 } else {
4077 return str;
4078 }
4079};
4080
4081});
4082require.register("chai/lib/chai/utils/overwriteMethod.js", function(exports, require, module){
4083/*!
4084 * Chai - overwriteMethod utility
4085 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4086 * MIT Licensed
4087 */
4088
4089/**
4090 * ### overwriteMethod (ctx, name, fn)
4091 *
4092 * Overwites an already existing method and provides
4093 * access to previous function. Must return function
4094 * to be used for name.
4095 *
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);
4101 * } else {
4102 * _super.apply(this, arguments);
4103 * }
4104 * }
4105 * });
4106 *
4107 * Can also be accessed directly from `chai.Assertion`.
4108 *
4109 * chai.Assertion.overwriteMethod('foo', fn);
4110 *
4111 * Then can be used as any other assertion.
4112 *
4113 * expect(myFoo).to.equal('bar');
4114 *
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
4119 * @api public
4120 */
4121
4122module.exports = function (ctx, name, method) {
4123 var _method = ctx[name]
4124 , _super = function () { return this; };
4125
4126 if (_method && 'function' === typeof _method)
4127 _super = _method;
4128
4129 ctx[name] = function () {
4130 var result = method(_super).apply(this, arguments);
4131 return result === undefined ? this : result;
4132 }
4133};
4134
4135});
4136require.register("chai/lib/chai/utils/overwriteProperty.js", function(exports, require, module){
4137/*!
4138 * Chai - overwriteProperty utility
4139 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4140 * MIT Licensed
4141 */
4142
4143/**
4144 * ### overwriteProperty (ctx, name, fn)
4145 *
4146 * Overwites an already existing property getter and provides
4147 * access to previous value. Must return function to use as getter.
4148 *
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');
4154 * } else {
4155 * _super.call(this);
4156 * }
4157 * }
4158 * });
4159 *
4160 *
4161 * Can also be accessed directly from `chai.Assertion`.
4162 *
4163 * chai.Assertion.overwriteProperty('foo', fn);
4164 *
4165 * Then can be used as any other assertion.
4166 *
4167 * expect(myFoo).to.be.ok;
4168 *
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
4173 * @api public
4174 */
4175
4176module.exports = function (ctx, name, getter) {
4177 var _get = Object.getOwnPropertyDescriptor(ctx, name)
4178 , _super = function () {};
4179
4180 if (_get && 'function' === typeof _get.get)
4181 _super = _get.get
4182
4183 Object.defineProperty(ctx, name,
4184 { get: function () {
4185 var result = getter(_super).call(this);
4186 return result === undefined ? this : result;
4187 }
4188 , configurable: true
4189 });
4190};
4191
4192});
4193require.register("chai/lib/chai/utils/test.js", function(exports, require, module){
4194/*!
4195 * Chai - test utility
4196 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4197 * MIT Licensed
4198 */
4199
4200/*!
4201 * Module dependancies
4202 */
4203
4204var flag = require('./flag');
4205
4206/**
4207 * # test(object, expression)
4208 *
4209 * Test and object for expression.
4210 *
4211 * @param {Object} object (constructed Assertion)
4212 * @param {Arguments} chai.Assertion.prototype.assert arguments
4213 */
4214
4215module.exports = function (obj, args) {
4216 var negate = flag(obj, 'negate')
4217 , expr = args[0];
4218 return negate ? !expr : expr;
4219};
4220
4221});
4222require.register("chai/lib/chai/utils/transferFlags.js", function(exports, require, module){
4223/*!
4224 * Chai - transferFlags utility
4225 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4226 * MIT Licensed
4227 */
4228
4229/**
4230 * ### transferFlags(assertion, object, includeAll = true)
4231 *
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.
4236 *
4237 *
4238 * var newAssertion = new Assertion();
4239 * utils.transferFlags(assertion, newAssertion);
4240 *
4241 * var anotherAsseriton = new Assertion(myObj);
4242 * utils.transferFlags(assertion, anotherAssertion, false);
4243 *
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
4247 * @name getAllFlags
4248 * @api private
4249 */
4250
4251module.exports = function (assertion, object, includeAll) {
4252 var flags = assertion.__flags || (assertion.__flags = Object.create(null));
4253
4254 if (!object.__flags) {
4255 object.__flags = Object.create(null);
4256 }
4257
4258 includeAll = arguments.length === 3 ? includeAll : true;
4259
4260 for (var flag in flags) {
4261 if (includeAll ||
4262 (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
4263 object.__flags[flag] = flags[flag];
4264 }
4265 }
4266};
4267
4268});
4269require.register("chai/lib/chai/utils/type.js", function(exports, require, module){
4270/*!
4271 * Chai - type utility
4272 * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4273 * MIT Licensed
4274 */
4275
4276/*!
4277 * Detectable javascript natives
4278 */
4279
4280var 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'
4288};
4289
4290/**
4291 * ### type(object)
4292 *
4293 * Better implementation of `typeof` detection that can
4294 * be used cross-browser. Handles the inconsistencies of
4295 * Array, `null`, and `undefined` detection.
4296 *
4297 * utils.type({}) // 'object'
4298 * utils.type(null) // `null'
4299 * utils.type(undefined) // `undefined`
4300 * utils.type([]) // `array`
4301 *
4302 * @param {Mixed} object to detect type of
4303 * @name type
4304 * @api private
4305 */
4306
4307module.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';
4313 return typeof obj;
4314};
4315
4316});
4317require.alias("chaijs-assertion-error/index.js", "chai/deps/assertion-error/index.js");
4318require.alias("chaijs-assertion-error/index.js", "chai/deps/assertion-error/index.js");
4319require.alias("chaijs-assertion-error/index.js", "assertion-error/index.js");
4320require.alias("chaijs-assertion-error/index.js", "chaijs-assertion-error/index.js");
4321
4322require.alias("chai/index.js", "chai/index.js");
4323
4324if (typeof exports == "object") {
4325 module.exports = require("chai");
4326} else if (typeof define == "function" && define.amd) {
4327 define(function(){ return require("chai"); });
4328} else {
4329 this["chai"] = require("chai");
4330}})();
\No newline at end of file