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