new 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +79 -0
  6. data/Guardfile +14 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +121 -0
  9. data/bin/new +6 -0
  10. data/lib/new/cli.rb +94 -0
  11. data/lib/new/core.rb +6 -0
  12. data/lib/new/dsl.rb +42 -0
  13. data/lib/new/interpolate.rb +100 -0
  14. data/lib/new/project.rb +34 -0
  15. data/lib/new/task.rb +41 -0
  16. data/lib/new/template.rb +64 -0
  17. data/lib/new/version.rb +41 -0
  18. data/lib/new.rb +72 -0
  19. data/new-0.0.0.gem +0 -0
  20. data/new-0.0.1.gem +0 -0
  21. data/spec/fixtures/custom/tasks/custom_bar_task/custom_bar_task.rb +3 -0
  22. data/spec/fixtures/custom/templates/custom_bar_template/custom_bar.txt +0 -0
  23. data/spec/fixtures/tasks/custom_bar_task/custom_bar_task.rb +1 -0
  24. data/spec/fixtures/tasks/foo_task/foo_task.rb +7 -0
  25. data/spec/fixtures/templates/foo_template/[FOO.BAR].txt.erb +1 -0
  26. data/spec/fixtures/templates/foo_template/nested_[FOO.BAR]/foo.txt.erb +1 -0
  27. data/spec/lib/new/cli_spec.rb +104 -0
  28. data/spec/lib/new/interpolate_spec.rb +41 -0
  29. data/spec/lib/new/project_spec.rb +30 -0
  30. data/spec/lib/new/task_spec.rb +39 -0
  31. data/spec/lib/new/template_spec.rb +59 -0
  32. data/spec/lib/new/version_spec.rb +28 -0
  33. data/spec/lib/new_spec.rb +19 -0
  34. data/spec/spec_helper.rb +26 -0
  35. data/tasks/gem/README.md +36 -0
  36. data/tasks/gem/gem.rb +122 -0
  37. data/templates/js/Gemfile +30 -0
  38. data/templates/js/Guardfile +7 -0
  39. data/templates/js/LICENSE-MIT.erb +22 -0
  40. data/templates/js/README.md.erb +61 -0
  41. data/templates/js/demo/index.html.erb +7 -0
  42. data/templates/js/lib/README.md +2 -0
  43. data/templates/js/spec/[PROJECT_NAME].spec.js.coffee.erb +1 -0
  44. data/templates/js/spec/index.html.erb +29 -0
  45. data/templates/js/spec/spec_helper.js.coffee +0 -0
  46. data/templates/js/spec/vendor/chai.js +3765 -0
  47. data/templates/js/spec/vendor/sinon-chai.js +106 -0
  48. data/templates/js/spec/vendor/sinon.js +4246 -0
  49. data/templates/js/src/README.md +3 -0
  50. data/templates/js/src/[PROJECT_NAME].js.coffee.erb +10 -0
  51. data/templates/js/testem.yml +12 -0
  52. metadata +70 -8
@@ -0,0 +1,3765 @@
1
+ !
2
+ function(name, context, definition) {
3
+ if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
4
+ module.exports = definition();
5
+ } else if (typeof define === 'function' && typeof define.amd === 'object') {
6
+ define(function() {
7
+ return definition();
8
+ });
9
+ } else {
10
+ context[name] = definition();
11
+ }
12
+ }('chai', this, function() {
13
+
14
+ function require(p) {
15
+ var path = require.resolve(p),
16
+ mod = require.modules[path];
17
+ if (!mod) throw new Error('failed to require "' + p + '"');
18
+ if (!mod.exports) {
19
+ mod.exports = {};
20
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
21
+ }
22
+ return mod.exports;
23
+ }
24
+
25
+ require.modules = {};
26
+
27
+ require.resolve = function(path) {
28
+ var orig = path,
29
+ reg = path + '.js',
30
+ index = path + '/index.js';
31
+ return require.modules[reg] && reg || require.modules[index] && index || orig;
32
+ };
33
+
34
+ require.register = function(path, fn) {
35
+ require.modules[path] = fn;
36
+ };
37
+
38
+ require.relative = function(parent) {
39
+ return function(p) {
40
+ if ('.' != p.charAt(0)) return require(p);
41
+
42
+ var path = parent.split('/'),
43
+ segs = p.split('/');
44
+ path.pop();
45
+
46
+ for (var i = 0; i < segs.length; i++) {
47
+ var seg = segs[i];
48
+ if ('..' == seg) path.pop();
49
+ else if ('.' != seg) path.push(seg);
50
+ }
51
+
52
+ return require(path.join('/'));
53
+ };
54
+ };
55
+
56
+ require.alias = function(from, to) {
57
+ var fn = require.modules[from];
58
+ require.modules[to] = fn;
59
+ };
60
+
61
+
62
+ require.register("chai.js", function(module, exports, require) {
63
+ /*!
64
+ * chai
65
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
66
+ * MIT Licensed
67
+ */
68
+
69
+ var used = [],
70
+ exports = module.exports = {};
71
+
72
+ /*!
73
+ * Chai version
74
+ */
75
+
76
+ exports.version = '1.5.0';
77
+
78
+ /*!
79
+ * Primary `Assertion` prototype
80
+ */
81
+
82
+ exports.Assertion = require('./chai/assertion');
83
+
84
+ /*!
85
+ * Assertion Error
86
+ */
87
+
88
+ exports.AssertionError = require('./chai/error');
89
+
90
+ /*!
91
+ * Utils for plugins (not exported)
92
+ */
93
+
94
+ var util = require('./chai/utils');
95
+
96
+ /**
97
+ * # .use(function)
98
+ *
99
+ * Provides a way to extend the internals of Chai
100
+ *
101
+ * @param {Function}
102
+ * @returns {this} for chaining
103
+ * @api public
104
+ */
105
+
106
+ exports.use = function(fn) {
107
+ if (!~used.indexOf(fn)) {
108
+ fn(this, util);
109
+ used.push(fn);
110
+ }
111
+
112
+ return this;
113
+ };
114
+
115
+ /*!
116
+ * Core Assertions
117
+ */
118
+
119
+ var core = require('./chai/core/assertions');
120
+ exports.use(core);
121
+
122
+ /*!
123
+ * Expect interface
124
+ */
125
+
126
+ var expect = require('./chai/interface/expect');
127
+ exports.use(expect);
128
+
129
+ /*!
130
+ * Should interface
131
+ */
132
+
133
+ var should = require('./chai/interface/should');
134
+ exports.use(should);
135
+
136
+ /*!
137
+ * Assert interface
138
+ */
139
+
140
+ var assert = require('./chai/interface/assert');
141
+ exports.use(assert);
142
+
143
+ }); // module: chai.js
144
+ require.register("chai/assertion.js", function(module, exports, require) {
145
+ /*!
146
+ * chai
147
+ * http://chaijs.com
148
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
149
+ * MIT Licensed
150
+ */
151
+
152
+ /*!
153
+ * Module dependencies.
154
+ */
155
+
156
+ var AssertionError = require('./error'),
157
+ util = require('./utils'),
158
+ flag = util.flag;
159
+
160
+ /*!
161
+ * Module export.
162
+ */
163
+
164
+ module.exports = Assertion;
165
+
166
+
167
+ /*!
168
+ * Assertion Constructor
169
+ *
170
+ * Creates object for chaining.
171
+ *
172
+ * @api private
173
+ */
174
+
175
+ function Assertion(obj, msg, stack) {
176
+ flag(this, 'ssfi', stack || arguments.callee);
177
+ flag(this, 'object', obj);
178
+ flag(this, 'message', msg);
179
+ }
180
+
181
+ /*!
182
+ * ### Assertion.includeStack
183
+ *
184
+ * User configurable property, influences whether stack trace
185
+ * is included in Assertion error message. Default of false
186
+ * suppresses stack trace in the error message
187
+ *
188
+ * Assertion.includeStack = true; // enable stack on error
189
+ *
190
+ * @api public
191
+ */
192
+
193
+ Assertion.includeStack = false;
194
+
195
+ /*!
196
+ * ### Assertion.showDiff
197
+ *
198
+ * User configurable property, influences whether or not
199
+ * the `showDiff` flag should be included in the thrown
200
+ * AssertionErrors. `false` will always be `false`; `true`
201
+ * will be true when the assertion has requested a diff
202
+ * be shown.
203
+ *
204
+ * @api public
205
+ */
206
+
207
+ Assertion.showDiff = true;
208
+
209
+ Assertion.addProperty = function(name, fn) {
210
+ util.addProperty(this.prototype, name, fn);
211
+ };
212
+
213
+ Assertion.addMethod = function(name, fn) {
214
+ util.addMethod(this.prototype, name, fn);
215
+ };
216
+
217
+ Assertion.addChainableMethod = function(name, fn, chainingBehavior) {
218
+ util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
219
+ };
220
+
221
+ Assertion.overwriteProperty = function(name, fn) {
222
+ util.overwriteProperty(this.prototype, name, fn);
223
+ };
224
+
225
+ Assertion.overwriteMethod = function(name, fn) {
226
+ util.overwriteMethod(this.prototype, name, fn);
227
+ };
228
+
229
+ /*!
230
+ * ### .assert(expression, message, negateMessage, expected, actual)
231
+ *
232
+ * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
233
+ *
234
+ * @name assert
235
+ * @param {Philosophical} expression to be tested
236
+ * @param {String} message to display if fails
237
+ * @param {String} negatedMessage to display if negated expression fails
238
+ * @param {Mixed} expected value (remember to check for negation)
239
+ * @param {Mixed} actual (optional) will default to `this.obj`
240
+ * @api private
241
+ */
242
+
243
+ Assertion.prototype.assert = function(expr, msg, negateMsg, expected, _actual, showDiff) {
244
+ var ok = util.test(this, arguments);
245
+ if (true !== showDiff) showDiff = false;
246
+ if (true !== Assertion.showDiff) showDiff = false;
247
+
248
+ if (!ok) {
249
+ var msg = util.getMessage(this, arguments),
250
+ actual = util.getActual(this, arguments);
251
+ throw new AssertionError({
252
+ message: msg,
253
+ actual: actual,
254
+ expected: expected,
255
+ stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi'),
256
+ showDiff: showDiff
257
+ });
258
+ }
259
+ };
260
+
261
+ /*!
262
+ * ### ._obj
263
+ *
264
+ * Quick reference to stored `actual` value for plugin developers.
265
+ *
266
+ * @api private
267
+ */
268
+
269
+ Object.defineProperty(Assertion.prototype, '_obj', {
270
+ get: function() {
271
+ return flag(this, 'object');
272
+ },
273
+ set: function(val) {
274
+ flag(this, 'object', val);
275
+ }
276
+ });
277
+
278
+ }); // module: chai/assertion.js
279
+ require.register("chai/core/assertions.js", function(module, exports, require) {
280
+ /*!
281
+ * chai
282
+ * http://chaijs.com
283
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
284
+ * MIT Licensed
285
+ */
286
+
287
+ module.exports = function(chai, _) {
288
+ var Assertion = chai.Assertion,
289
+ toString = Object.prototype.toString,
290
+ flag = _.flag;
291
+
292
+ /**
293
+ * ### Language Chains
294
+ *
295
+ * The following are provide as chainable getters to
296
+ * improve the readability of your assertions. They
297
+ * do not provide an testing capability unless they
298
+ * have been overwritten by a plugin.
299
+ *
300
+ * **Chains**
301
+ *
302
+ * - to
303
+ * - be
304
+ * - been
305
+ * - is
306
+ * - that
307
+ * - and
308
+ * - have
309
+ * - with
310
+ * - at
311
+ * - of
312
+ *
313
+ * @name language chains
314
+ * @api public
315
+ */
316
+
317
+ ['to', 'be', 'been', 'is', 'and', 'have', 'with', 'that', 'at', 'of'].forEach(function(chain) {
318
+ Assertion.addProperty(chain, function() {
319
+ return this;
320
+ });
321
+ });
322
+
323
+ /**
324
+ * ### .not
325
+ *
326
+ * Negates any of assertions following in the chain.
327
+ *
328
+ * expect(foo).to.not.equal('bar');
329
+ * expect(goodFn).to.not.throw(Error);
330
+ * expect({ foo: 'baz' }).to.have.property('foo')
331
+ * .and.not.equal('bar');
332
+ *
333
+ * @name not
334
+ * @api public
335
+ */
336
+
337
+ Assertion.addProperty('not', function() {
338
+ flag(this, 'negate', true);
339
+ });
340
+
341
+ /**
342
+ * ### .deep
343
+ *
344
+ * Sets the `deep` flag, later used by the `equal` and
345
+ * `property` assertions.
346
+ *
347
+ * expect(foo).to.deep.equal({ bar: 'baz' });
348
+ * expect({ foo: { bar: { baz: 'quux' } } })
349
+ * .to.have.deep.property('foo.bar.baz', 'quux');
350
+ *
351
+ * @name deep
352
+ * @api public
353
+ */
354
+
355
+ Assertion.addProperty('deep', function() {
356
+ flag(this, 'deep', true);
357
+ });
358
+
359
+ /**
360
+ * ### .a(type)
361
+ *
362
+ * The `a` and `an` assertions are aliases that can be
363
+ * used either as language chains or to assert a value's
364
+ * type.
365
+ *
366
+ * // typeof
367
+ * expect('test').to.be.a('string');
368
+ * expect({ foo: 'bar' }).to.be.an('object');
369
+ * expect(null).to.be.a('null');
370
+ * expect(undefined).to.be.an('undefined');
371
+ *
372
+ * // language chain
373
+ * expect(foo).to.be.an.instanceof(Foo);
374
+ *
375
+ * @name a
376
+ * @alias an
377
+ * @param {String} type
378
+ * @param {String} message _optional_
379
+ * @api public
380
+ */
381
+
382
+ function an(type, msg) {
383
+ if (msg) flag(this, 'message', msg);
384
+ type = type.toLowerCase();
385
+ var obj = flag(this, 'object'),
386
+ article = ~ ['a', 'e', 'i', 'o', 'u'].indexOf(type.charAt(0)) ? 'an ' : 'a ';
387
+
388
+ this.assert(
389
+ type === _.type(obj), 'expected #{this} to be ' + article + type, 'expected #{this} not to be ' + article + type);
390
+ }
391
+
392
+ Assertion.addChainableMethod('an', an);
393
+ Assertion.addChainableMethod('a', an);
394
+
395
+ /**
396
+ * ### .include(value)
397
+ *
398
+ * The `include` and `contain` assertions can be used as either property
399
+ * based language chains or as methods to assert the inclusion of an object
400
+ * in an array or a substring in a string. When used as language chains,
401
+ * they toggle the `contain` flag for the `keys` assertion.
402
+ *
403
+ * expect([1,2,3]).to.include(2);
404
+ * expect('foobar').to.contain('foo');
405
+ * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
406
+ *
407
+ * @name include
408
+ * @alias contain
409
+ * @param {Object|String|Number} obj
410
+ * @param {String} message _optional_
411
+ * @api public
412
+ */
413
+
414
+ function includeChainingBehavior() {
415
+ flag(this, 'contains', true);
416
+ }
417
+
418
+ function include(val, msg) {
419
+ if (msg) flag(this, 'message', msg);
420
+ var obj = flag(this, 'object')
421
+ this.assert(~obj.indexOf(val), 'expected #{this} to include ' + _.inspect(val), 'expected #{this} to not include ' + _.inspect(val));
422
+ }
423
+
424
+ Assertion.addChainableMethod('include', include, includeChainingBehavior);
425
+ Assertion.addChainableMethod('contain', include, includeChainingBehavior);
426
+
427
+ /**
428
+ * ### .ok
429
+ *
430
+ * Asserts that the target is truthy.
431
+ *
432
+ * expect('everthing').to.be.ok;
433
+ * expect(1).to.be.ok;
434
+ * expect(false).to.not.be.ok;
435
+ * expect(undefined).to.not.be.ok;
436
+ * expect(null).to.not.be.ok;
437
+ *
438
+ * @name ok
439
+ * @api public
440
+ */
441
+
442
+ Assertion.addProperty('ok', function() {
443
+ this.assert(
444
+ flag(this, 'object'), 'expected #{this} to be truthy', 'expected #{this} to be falsy');
445
+ });
446
+
447
+ /**
448
+ * ### .true
449
+ *
450
+ * Asserts that the target is `true`.
451
+ *
452
+ * expect(true).to.be.true;
453
+ * expect(1).to.not.be.true;
454
+ *
455
+ * @name true
456
+ * @api public
457
+ */
458
+
459
+ Assertion.addProperty('true', function() {
460
+ this.assert(
461
+ true === flag(this, 'object'), 'expected #{this} to be true', 'expected #{this} to be false', this.negate ? false : true);
462
+ });
463
+
464
+ /**
465
+ * ### .false
466
+ *
467
+ * Asserts that the target is `false`.
468
+ *
469
+ * expect(false).to.be.false;
470
+ * expect(0).to.not.be.false;
471
+ *
472
+ * @name false
473
+ * @api public
474
+ */
475
+
476
+ Assertion.addProperty('false', function() {
477
+ this.assert(
478
+ false === flag(this, 'object'), 'expected #{this} to be false', 'expected #{this} to be true', this.negate ? true : false);
479
+ });
480
+
481
+ /**
482
+ * ### .null
483
+ *
484
+ * Asserts that the target is `null`.
485
+ *
486
+ * expect(null).to.be.null;
487
+ * expect(undefined).not.to.be.null;
488
+ *
489
+ * @name null
490
+ * @api public
491
+ */
492
+
493
+ Assertion.addProperty('null', function() {
494
+ this.assert(
495
+ null === flag(this, 'object'), 'expected #{this} to be null', 'expected #{this} not to be null');
496
+ });
497
+
498
+ /**
499
+ * ### .undefined
500
+ *
501
+ * Asserts that the target is `undefined`.
502
+ *
503
+ * expect(undefined).to.be.undefined;
504
+ * expect(null).to.not.be.undefined;
505
+ *
506
+ * @name undefined
507
+ * @api public
508
+ */
509
+
510
+ Assertion.addProperty('undefined', function() {
511
+ this.assert(
512
+ undefined === flag(this, 'object'), 'expected #{this} to be undefined', 'expected #{this} not to be undefined');
513
+ });
514
+
515
+ /**
516
+ * ### .exist
517
+ *
518
+ * Asserts that the target is neither `null` nor `undefined`.
519
+ *
520
+ * var foo = 'hi'
521
+ * , bar = null
522
+ * , baz;
523
+ *
524
+ * expect(foo).to.exist;
525
+ * expect(bar).to.not.exist;
526
+ * expect(baz).to.not.exist;
527
+ *
528
+ * @name exist
529
+ * @api public
530
+ */
531
+
532
+ Assertion.addProperty('exist', function() {
533
+ this.assert(
534
+ null != flag(this, 'object'), 'expected #{this} to exist', 'expected #{this} to not exist');
535
+ });
536
+
537
+
538
+ /**
539
+ * ### .empty
540
+ *
541
+ * Asserts that the target's length is `0`. For arrays, it checks
542
+ * the `length` property. For objects, it gets the count of
543
+ * enumerable keys.
544
+ *
545
+ * expect([]).to.be.empty;
546
+ * expect('').to.be.empty;
547
+ * expect({}).to.be.empty;
548
+ *
549
+ * @name empty
550
+ * @api public
551
+ */
552
+
553
+ Assertion.addProperty('empty', function() {
554
+ var obj = flag(this, 'object'),
555
+ expected = obj;
556
+
557
+ if (Array.isArray(obj) || 'string' === typeof object) {
558
+ expected = obj.length;
559
+ } else if (typeof obj === 'object') {
560
+ expected = Object.keys(obj).length;
561
+ }
562
+
563
+ this.assert(!expected, 'expected #{this} to be empty', 'expected #{this} not to be empty');
564
+ });
565
+
566
+ /**
567
+ * ### .arguments
568
+ *
569
+ * Asserts that the target is an arguments object.
570
+ *
571
+ * function test () {
572
+ * expect(arguments).to.be.arguments;
573
+ * }
574
+ *
575
+ * @name arguments
576
+ * @alias Arguments
577
+ * @api public
578
+ */
579
+
580
+ function checkArguments() {
581
+ var obj = flag(this, 'object'),
582
+ type = Object.prototype.toString.call(obj);
583
+ this.assert('[object Arguments]' === type, 'expected #{this} to be arguments but got ' + type, 'expected #{this} to not be arguments');
584
+ }
585
+
586
+ Assertion.addProperty('arguments', checkArguments);
587
+ Assertion.addProperty('Arguments', checkArguments);
588
+
589
+ /**
590
+ * ### .equal(value)
591
+ *
592
+ * Asserts that the target is strictly equal (`===`) to `value`.
593
+ * Alternately, if the `deep` flag is set, asserts that
594
+ * the target is deeply equal to `value`.
595
+ *
596
+ * expect('hello').to.equal('hello');
597
+ * expect(42).to.equal(42);
598
+ * expect(1).to.not.equal(true);
599
+ * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
600
+ * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
601
+ *
602
+ * @name equal
603
+ * @alias equals
604
+ * @alias eq
605
+ * @alias deep.equal
606
+ * @param {Mixed} value
607
+ * @param {String} message _optional_
608
+ * @api public
609
+ */
610
+
611
+ function assertEqual(val, msg) {
612
+ if (msg) flag(this, 'message', msg);
613
+ var obj = flag(this, 'object');
614
+ if (flag(this, 'deep')) {
615
+ return this.eql(val);
616
+ } else {
617
+ this.assert(
618
+ val === obj, 'expected #{this} to equal #{exp}', 'expected #{this} to not equal #{exp}', val, this._obj, true);
619
+ }
620
+ }
621
+
622
+ Assertion.addMethod('equal', assertEqual);
623
+ Assertion.addMethod('equals', assertEqual);
624
+ Assertion.addMethod('eq', assertEqual);
625
+
626
+ /**
627
+ * ### .eql(value)
628
+ *
629
+ * Asserts that the target is deeply equal to `value`.
630
+ *
631
+ * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
632
+ * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
633
+ *
634
+ * @name eql
635
+ * @alias eqls
636
+ * @param {Mixed} value
637
+ * @param {String} message _optional_
638
+ * @api public
639
+ */
640
+
641
+ function assertEql(obj, msg) {
642
+ if (msg) flag(this, 'message', msg);
643
+ this.assert(
644
+ _.eql(obj, flag(this, 'object')), 'expected #{this} to deeply equal #{exp}', 'expected #{this} to not deeply equal #{exp}', obj, this._obj, true);
645
+ }
646
+
647
+ Assertion.addMethod('eql', assertEql);
648
+ Assertion.addMethod('eqls', assertEql);
649
+
650
+ /**
651
+ * ### .above(value)
652
+ *
653
+ * Asserts that the target is greater than `value`.
654
+ *
655
+ * expect(10).to.be.above(5);
656
+ *
657
+ * Can also be used in conjunction with `length` to
658
+ * assert a minimum length. The benefit being a
659
+ * more informative error message than if the length
660
+ * was supplied directly.
661
+ *
662
+ * expect('foo').to.have.length.above(2);
663
+ * expect([ 1, 2, 3 ]).to.have.length.above(2);
664
+ *
665
+ * @name above
666
+ * @alias gt
667
+ * @alias greaterThan
668
+ * @param {Number} value
669
+ * @param {String} message _optional_
670
+ * @api public
671
+ */
672
+
673
+ function assertAbove(n, msg) {
674
+ if (msg) flag(this, 'message', msg);
675
+ var obj = flag(this, 'object');
676
+ if (flag(this, 'doLength')) {
677
+ new Assertion(obj, msg).to.have.property('length');
678
+ var len = obj.length;
679
+ this.assert(
680
+ len > n, 'expected #{this} to have a length above #{exp} but got #{act}', 'expected #{this} to not have a length above #{exp}', n, len);
681
+ } else {
682
+ this.assert(
683
+ obj > n, 'expected #{this} to be above ' + n, 'expected #{this} to be at most ' + n);
684
+ }
685
+ }
686
+
687
+ Assertion.addMethod('above', assertAbove);
688
+ Assertion.addMethod('gt', assertAbove);
689
+ Assertion.addMethod('greaterThan', assertAbove);
690
+
691
+ /**
692
+ * ### .least(value)
693
+ *
694
+ * Asserts that the target is greater than or equal to `value`.
695
+ *
696
+ * expect(10).to.be.at.least(10);
697
+ *
698
+ * Can also be used in conjunction with `length` to
699
+ * assert a minimum length. The benefit being a
700
+ * more informative error message than if the length
701
+ * was supplied directly.
702
+ *
703
+ * expect('foo').to.have.length.of.at.least(2);
704
+ * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
705
+ *
706
+ * @name least
707
+ * @alias gte
708
+ * @param {Number} value
709
+ * @param {String} message _optional_
710
+ * @api public
711
+ */
712
+
713
+ function assertLeast(n, msg) {
714
+ if (msg) flag(this, 'message', msg);
715
+ var obj = flag(this, 'object');
716
+ if (flag(this, 'doLength')) {
717
+ new Assertion(obj, msg).to.have.property('length');
718
+ var len = obj.length;
719
+ this.assert(
720
+ len >= n, 'expected #{this} to have a length at least #{exp} but got #{act}', 'expected #{this} to have a length below #{exp}', n, len);
721
+ } else {
722
+ this.assert(
723
+ obj >= n, 'expected #{this} to be at least ' + n, 'expected #{this} to be below ' + n);
724
+ }
725
+ }
726
+
727
+ Assertion.addMethod('least', assertLeast);
728
+ Assertion.addMethod('gte', assertLeast);
729
+
730
+ /**
731
+ * ### .below(value)
732
+ *
733
+ * Asserts that the target is less than `value`.
734
+ *
735
+ * expect(5).to.be.below(10);
736
+ *
737
+ * Can also be used in conjunction with `length` to
738
+ * assert a maximum length. The benefit being a
739
+ * more informative error message than if the length
740
+ * was supplied directly.
741
+ *
742
+ * expect('foo').to.have.length.below(4);
743
+ * expect([ 1, 2, 3 ]).to.have.length.below(4);
744
+ *
745
+ * @name below
746
+ * @alias lt
747
+ * @alias lessThan
748
+ * @param {Number} value
749
+ * @param {String} message _optional_
750
+ * @api public
751
+ */
752
+
753
+ function assertBelow(n, msg) {
754
+ if (msg) flag(this, 'message', msg);
755
+ var obj = flag(this, 'object');
756
+ if (flag(this, 'doLength')) {
757
+ new Assertion(obj, msg).to.have.property('length');
758
+ var len = obj.length;
759
+ this.assert(
760
+ len < n, 'expected #{this} to have a length below #{exp} but got #{act}', 'expected #{this} to not have a length below #{exp}', n, len);
761
+ } else {
762
+ this.assert(
763
+ obj < n, 'expected #{this} to be below ' + n, 'expected #{this} to be at least ' + n);
764
+ }
765
+ }
766
+
767
+ Assertion.addMethod('below', assertBelow);
768
+ Assertion.addMethod('lt', assertBelow);
769
+ Assertion.addMethod('lessThan', assertBelow);
770
+
771
+ /**
772
+ * ### .most(value)
773
+ *
774
+ * Asserts that the target is less than or equal to `value`.
775
+ *
776
+ * expect(5).to.be.at.most(5);
777
+ *
778
+ * Can also be used in conjunction with `length` to
779
+ * assert a maximum length. The benefit being a
780
+ * more informative error message than if the length
781
+ * was supplied directly.
782
+ *
783
+ * expect('foo').to.have.length.of.at.most(4);
784
+ * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
785
+ *
786
+ * @name most
787
+ * @alias lte
788
+ * @param {Number} value
789
+ * @param {String} message _optional_
790
+ * @api public
791
+ */
792
+
793
+ function assertMost(n, msg) {
794
+ if (msg) flag(this, 'message', msg);
795
+ var obj = flag(this, 'object');
796
+ if (flag(this, 'doLength')) {
797
+ new Assertion(obj, msg).to.have.property('length');
798
+ var len = obj.length;
799
+ this.assert(
800
+ len <= n, 'expected #{this} to have a length at most #{exp} but got #{act}', 'expected #{this} to have a length above #{exp}', n, len);
801
+ } else {
802
+ this.assert(
803
+ obj <= n, 'expected #{this} to be at most ' + n, 'expected #{this} to be above ' + n);
804
+ }
805
+ }
806
+
807
+ Assertion.addMethod('most', assertMost);
808
+ Assertion.addMethod('lte', assertMost);
809
+
810
+ /**
811
+ * ### .within(start, finish)
812
+ *
813
+ * Asserts that the target is within a range.
814
+ *
815
+ * expect(7).to.be.within(5,10);
816
+ *
817
+ * Can also be used in conjunction with `length` to
818
+ * assert a length range. The benefit being a
819
+ * more informative error message than if the length
820
+ * was supplied directly.
821
+ *
822
+ * expect('foo').to.have.length.within(2,4);
823
+ * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
824
+ *
825
+ * @name within
826
+ * @param {Number} start lowerbound inclusive
827
+ * @param {Number} finish upperbound inclusive
828
+ * @param {String} message _optional_
829
+ * @api public
830
+ */
831
+
832
+ Assertion.addMethod('within', function(start, finish, msg) {
833
+ if (msg) flag(this, 'message', msg);
834
+ var obj = flag(this, 'object'),
835
+ range = start + '..' + finish;
836
+ if (flag(this, 'doLength')) {
837
+ new Assertion(obj, msg).to.have.property('length');
838
+ var len = obj.length;
839
+ this.assert(
840
+ len >= start && len <= finish, 'expected #{this} to have a length within ' + range, 'expected #{this} to not have a length within ' + range);
841
+ } else {
842
+ this.assert(
843
+ obj >= start && obj <= finish, 'expected #{this} to be within ' + range, 'expected #{this} to not be within ' + range);
844
+ }
845
+ });
846
+
847
+ /**
848
+ * ### .instanceof(constructor)
849
+ *
850
+ * Asserts that the target is an instance of `constructor`.
851
+ *
852
+ * var Tea = function (name) { this.name = name; }
853
+ * , Chai = new Tea('chai');
854
+ *
855
+ * expect(Chai).to.be.an.instanceof(Tea);
856
+ * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
857
+ *
858
+ * @name instanceof
859
+ * @param {Constructor} constructor
860
+ * @param {String} message _optional_
861
+ * @alias instanceOf
862
+ * @api public
863
+ */
864
+
865
+ function assertInstanceOf(constructor, msg) {
866
+ if (msg) flag(this, 'message', msg);
867
+ var name = _.getName(constructor);
868
+ this.assert(
869
+ flag(this, 'object') instanceof constructor, 'expected #{this} to be an instance of ' + name, 'expected #{this} to not be an instance of ' + name);
870
+ };
871
+
872
+ Assertion.addMethod('instanceof', assertInstanceOf);
873
+ Assertion.addMethod('instanceOf', assertInstanceOf);
874
+
875
+ /**
876
+ * ### .property(name, [value])
877
+ *
878
+ * Asserts that the target has a property `name`, optionally asserting that
879
+ * the value of that property is strictly equal to `value`.
880
+ * If the `deep` flag is set, you can use dot- and bracket-notation for deep
881
+ * references into objects and arrays.
882
+ *
883
+ * // simple referencing
884
+ * var obj = { foo: 'bar' };
885
+ * expect(obj).to.have.property('foo');
886
+ * expect(obj).to.have.property('foo', 'bar');
887
+ *
888
+ * // deep referencing
889
+ * var deepObj = {
890
+ * green: { tea: 'matcha' }
891
+ * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
892
+ * };
893
+
894
+ * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
895
+ * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
896
+ * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
897
+ *
898
+ * You can also use an array as the starting point of a `deep.property`
899
+ * assertion, or traverse nested arrays.
900
+ *
901
+ * var arr = [
902
+ * [ 'chai', 'matcha', 'konacha' ]
903
+ * , [ { tea: 'chai' }
904
+ * , { tea: 'matcha' }
905
+ * , { tea: 'konacha' } ]
906
+ * ];
907
+ *
908
+ * expect(arr).to.have.deep.property('[0][1]', 'matcha');
909
+ * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
910
+ *
911
+ * Furthermore, `property` changes the subject of the assertion
912
+ * to be the value of that property from the original object. This
913
+ * permits for further chainable assertions on that property.
914
+ *
915
+ * expect(obj).to.have.property('foo')
916
+ * .that.is.a('string');
917
+ * expect(deepObj).to.have.property('green')
918
+ * .that.is.an('object')
919
+ * .that.deep.equals({ tea: 'matcha' });
920
+ * expect(deepObj).to.have.property('teas')
921
+ * .that.is.an('array')
922
+ * .with.deep.property('[2]')
923
+ * .that.deep.equals({ tea: 'konacha' });
924
+ *
925
+ * @name property
926
+ * @alias deep.property
927
+ * @param {String} name
928
+ * @param {Mixed} value (optional)
929
+ * @param {String} message _optional_
930
+ * @returns value of property for chaining
931
+ * @api public
932
+ */
933
+
934
+ Assertion.addMethod('property', function(name, val, msg) {
935
+ if (msg) flag(this, 'message', msg);
936
+
937
+ var descriptor = flag(this, 'deep') ? 'deep property ' : 'property ',
938
+ negate = flag(this, 'negate'),
939
+ obj = flag(this, 'object'),
940
+ value = flag(this, 'deep') ? _.getPathValue(name, obj) : obj[name];
941
+
942
+ if (negate && undefined !== val) {
943
+ if (undefined === value) {
944
+ msg = (msg != null) ? msg + ': ' : '';
945
+ throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
946
+ }
947
+ } else {
948
+ this.assert(
949
+ undefined !== value, 'expected #{this} to have a ' + descriptor + _.inspect(name), 'expected #{this} to not have ' + descriptor + _.inspect(name));
950
+ }
951
+
952
+ if (undefined !== val) {
953
+ this.assert(
954
+ val === value, 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}', 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}', val, value);
955
+ }
956
+
957
+ flag(this, 'object', value);
958
+ });
959
+
960
+
961
+ /**
962
+ * ### .ownProperty(name)
963
+ *
964
+ * Asserts that the target has an own property `name`.
965
+ *
966
+ * expect('test').to.have.ownProperty('length');
967
+ *
968
+ * @name ownProperty
969
+ * @alias haveOwnProperty
970
+ * @param {String} name
971
+ * @param {String} message _optional_
972
+ * @api public
973
+ */
974
+
975
+ function assertOwnProperty(name, msg) {
976
+ if (msg) flag(this, 'message', msg);
977
+ var obj = flag(this, 'object');
978
+ this.assert(
979
+ obj.hasOwnProperty(name), 'expected #{this} to have own property ' + _.inspect(name), 'expected #{this} to not have own property ' + _.inspect(name));
980
+ }
981
+
982
+ Assertion.addMethod('ownProperty', assertOwnProperty);
983
+ Assertion.addMethod('haveOwnProperty', assertOwnProperty);
984
+
985
+ /**
986
+ * ### .length(value)
987
+ *
988
+ * Asserts that the target's `length` property has
989
+ * the expected value.
990
+ *
991
+ * expect([ 1, 2, 3]).to.have.length(3);
992
+ * expect('foobar').to.have.length(6);
993
+ *
994
+ * Can also be used as a chain precursor to a value
995
+ * comparison for the length property.
996
+ *
997
+ * expect('foo').to.have.length.above(2);
998
+ * expect([ 1, 2, 3 ]).to.have.length.above(2);
999
+ * expect('foo').to.have.length.below(4);
1000
+ * expect([ 1, 2, 3 ]).to.have.length.below(4);
1001
+ * expect('foo').to.have.length.within(2,4);
1002
+ * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1003
+ *
1004
+ * @name length
1005
+ * @alias lengthOf
1006
+ * @param {Number} length
1007
+ * @param {String} message _optional_
1008
+ * @api public
1009
+ */
1010
+
1011
+ function assertLengthChain() {
1012
+ flag(this, 'doLength', true);
1013
+ }
1014
+
1015
+ function assertLength(n, msg) {
1016
+ if (msg) flag(this, 'message', msg);
1017
+ var obj = flag(this, 'object');
1018
+ new Assertion(obj, msg).to.have.property('length');
1019
+ var len = obj.length;
1020
+
1021
+ this.assert(
1022
+ len == n, 'expected #{this} to have a length of #{exp} but got #{act}', 'expected #{this} to not have a length of #{act}', n, len);
1023
+ }
1024
+
1025
+ Assertion.addChainableMethod('length', assertLength, assertLengthChain);
1026
+ Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
1027
+
1028
+ /**
1029
+ * ### .match(regexp)
1030
+ *
1031
+ * Asserts that the target matches a regular expression.
1032
+ *
1033
+ * expect('foobar').to.match(/^foo/);
1034
+ *
1035
+ * @name match
1036
+ * @param {RegExp} RegularExpression
1037
+ * @param {String} message _optional_
1038
+ * @api public
1039
+ */
1040
+
1041
+ Assertion.addMethod('match', function(re, msg) {
1042
+ if (msg) flag(this, 'message', msg);
1043
+ var obj = flag(this, 'object');
1044
+ this.assert(
1045
+ re.exec(obj), 'expected #{this} to match ' + re, 'expected #{this} not to match ' + re);
1046
+ });
1047
+
1048
+ /**
1049
+ * ### .string(string)
1050
+ *
1051
+ * Asserts that the string target contains another string.
1052
+ *
1053
+ * expect('foobar').to.have.string('bar');
1054
+ *
1055
+ * @name string
1056
+ * @param {String} string
1057
+ * @param {String} message _optional_
1058
+ * @api public
1059
+ */
1060
+
1061
+ Assertion.addMethod('string', function(str, msg) {
1062
+ if (msg) flag(this, 'message', msg);
1063
+ var obj = flag(this, 'object');
1064
+ new Assertion(obj, msg).is.a('string');
1065
+
1066
+ this.assert(~obj.indexOf(str), 'expected #{this} to contain ' + _.inspect(str), 'expected #{this} to not contain ' + _.inspect(str));
1067
+ });
1068
+
1069
+
1070
+ /**
1071
+ * ### .keys(key1, [key2], [...])
1072
+ *
1073
+ * Asserts that the target has exactly the given keys, or
1074
+ * asserts the inclusion of some keys when using the
1075
+ * `include` or `contain` modifiers.
1076
+ *
1077
+ * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
1078
+ * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
1079
+ *
1080
+ * @name keys
1081
+ * @alias key
1082
+ * @param {String...|Array} keys
1083
+ * @api public
1084
+ */
1085
+
1086
+ function assertKeys(keys) {
1087
+ var obj = flag(this, 'object'),
1088
+ str, ok = true;
1089
+
1090
+ keys = keys instanceof Array ? keys : Array.prototype.slice.call(arguments);
1091
+
1092
+ if (!keys.length) throw new Error('keys required');
1093
+
1094
+ var actual = Object.keys(obj),
1095
+ len = keys.length;
1096
+
1097
+ // Inclusion
1098
+ ok = keys.every(function(key) {
1099
+ return ~actual.indexOf(key);
1100
+ });
1101
+
1102
+ // Strict
1103
+ if (!flag(this, 'negate') && !flag(this, 'contains')) {
1104
+ ok = ok && keys.length == actual.length;
1105
+ }
1106
+
1107
+ // Key string
1108
+ if (len > 1) {
1109
+ keys = keys.map(function(key) {
1110
+ return _.inspect(key);
1111
+ });
1112
+ var last = keys.pop();
1113
+ str = keys.join(', ') + ', and ' + last;
1114
+ } else {
1115
+ str = _.inspect(keys[0]);
1116
+ }
1117
+
1118
+ // Form
1119
+ str = (len > 1 ? 'keys ' : 'key ') + str;
1120
+
1121
+ // Have / include
1122
+ str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
1123
+
1124
+ // Assertion
1125
+ this.assert(
1126
+ ok, 'expected #{this} to ' + str, 'expected #{this} to not ' + str);
1127
+ }
1128
+
1129
+ Assertion.addMethod('keys', assertKeys);
1130
+ Assertion.addMethod('key', assertKeys);
1131
+
1132
+ /**
1133
+ * ### .throw(constructor)
1134
+ *
1135
+ * Asserts that the function target will throw a specific error, or specific type of error
1136
+ * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
1137
+ * for the error's message.
1138
+ *
1139
+ * var err = new ReferenceError('This is a bad function.');
1140
+ * var fn = function () { throw err; }
1141
+ * expect(fn).to.throw(ReferenceError);
1142
+ * expect(fn).to.throw(Error);
1143
+ * expect(fn).to.throw(/bad function/);
1144
+ * expect(fn).to.not.throw('good function');
1145
+ * expect(fn).to.throw(ReferenceError, /bad function/);
1146
+ * expect(fn).to.throw(err);
1147
+ * expect(fn).to.not.throw(new RangeError('Out of range.'));
1148
+ *
1149
+ * Please note that when a throw expectation is negated, it will check each
1150
+ * parameter independently, starting with error constructor type. The appropriate way
1151
+ * to check for the existence of a type of error but for a message that does not match
1152
+ * is to use `and`.
1153
+ *
1154
+ * expect(fn).to.throw(ReferenceError)
1155
+ * .and.not.throw(/good function/);
1156
+ *
1157
+ * @name throw
1158
+ * @alias throws
1159
+ * @alias Throw
1160
+ * @param {ErrorConstructor} constructor
1161
+ * @param {String|RegExp} expected error message
1162
+ * @param {String} message _optional_
1163
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
1164
+ * @api public
1165
+ */
1166
+
1167
+ function assertThrows(constructor, errMsg, msg) {
1168
+ if (msg) flag(this, 'message', msg);
1169
+ var obj = flag(this, 'object');
1170
+ new Assertion(obj, msg).is.a('function');
1171
+
1172
+ var thrown = false,
1173
+ desiredError = null,
1174
+ name = null,
1175
+ thrownError = null;
1176
+
1177
+ if (arguments.length === 0) {
1178
+ errMsg = null;
1179
+ constructor = null;
1180
+ } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
1181
+ errMsg = constructor;
1182
+ constructor = null;
1183
+ } else if (constructor && constructor instanceof Error) {
1184
+ desiredError = constructor;
1185
+ constructor = null;
1186
+ errMsg = null;
1187
+ } else if (typeof constructor === 'function') {
1188
+ name = (new constructor()).name;
1189
+ } else {
1190
+ constructor = null;
1191
+ }
1192
+
1193
+ try {
1194
+ obj();
1195
+ } catch (err) {
1196
+ // first, check desired error
1197
+ if (desiredError) {
1198
+ this.assert(
1199
+ err === desiredError, 'expected #{this} to throw #{exp} but #{act} was thrown', 'expected #{this} to not throw #{exp}', desiredError, err);
1200
+
1201
+ return this;
1202
+ }
1203
+ // next, check constructor
1204
+ if (constructor) {
1205
+ this.assert(
1206
+ err instanceof constructor, 'expected #{this} to throw #{exp} but #{act} was thrown', 'expected #{this} to not throw #{exp} but #{act} was thrown', name, err);
1207
+
1208
+ if (!errMsg) return this;
1209
+ }
1210
+ // next, check message
1211
+ var message = 'object' === _.type(err) && "message" in err ? err.message : '' + err;
1212
+
1213
+ if ((message != null) && errMsg && errMsg instanceof RegExp) {
1214
+ this.assert(
1215
+ errMsg.exec(message), 'expected #{this} to throw error matching #{exp} but got #{act}', 'expected #{this} to throw error not matching #{exp}', errMsg, message);
1216
+
1217
+ return this;
1218
+ } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
1219
+ this.assert(~message.indexOf(errMsg), 'expected #{this} to throw error including #{exp} but got #{act}', 'expected #{this} to throw error not including #{act}', errMsg, message);
1220
+
1221
+ return this;
1222
+ } else {
1223
+ thrown = true;
1224
+ thrownError = err;
1225
+ }
1226
+ }
1227
+
1228
+ var actuallyGot = '',
1229
+ expectedThrown = name !== null ? name : desiredError ? '#{exp}' //_.inspect(desiredError)
1230
+ :
1231
+ 'an error';
1232
+
1233
+ if (thrown) {
1234
+ actuallyGot = ' but #{act} was thrown'
1235
+ }
1236
+
1237
+ this.assert(
1238
+ thrown === true, 'expected #{this} to throw ' + expectedThrown + actuallyGot, 'expected #{this} to not throw ' + expectedThrown + actuallyGot, desiredError, thrownError);
1239
+ };
1240
+
1241
+ Assertion.addMethod('throw', assertThrows);
1242
+ Assertion.addMethod('throws', assertThrows);
1243
+ Assertion.addMethod('Throw', assertThrows);
1244
+
1245
+ /**
1246
+ * ### .respondTo(method)
1247
+ *
1248
+ * Asserts that the object or class target will respond to a method.
1249
+ *
1250
+ * Klass.prototype.bar = function(){};
1251
+ * expect(Klass).to.respondTo('bar');
1252
+ * expect(obj).to.respondTo('bar');
1253
+ *
1254
+ * To check if a constructor will respond to a static function,
1255
+ * set the `itself` flag.
1256
+ *
1257
+ * Klass.baz = function(){};
1258
+ * expect(Klass).itself.to.respondTo('baz');
1259
+ *
1260
+ * @name respondTo
1261
+ * @param {String} method
1262
+ * @param {String} message _optional_
1263
+ * @api public
1264
+ */
1265
+
1266
+ Assertion.addMethod('respondTo', function(method, msg) {
1267
+ if (msg) flag(this, 'message', msg);
1268
+ var obj = flag(this, 'object'),
1269
+ itself = flag(this, 'itself'),
1270
+ context = ('function' === _.type(obj) && !itself) ? obj.prototype[method] : obj[method];
1271
+
1272
+ this.assert('function' === typeof context, 'expected #{this} to respond to ' + _.inspect(method), 'expected #{this} to not respond to ' + _.inspect(method));
1273
+ });
1274
+
1275
+ /**
1276
+ * ### .itself
1277
+ *
1278
+ * Sets the `itself` flag, later used by the `respondTo` assertion.
1279
+ *
1280
+ * function Foo() {}
1281
+ * Foo.bar = function() {}
1282
+ * Foo.prototype.baz = function() {}
1283
+ *
1284
+ * expect(Foo).itself.to.respondTo('bar');
1285
+ * expect(Foo).itself.not.to.respondTo('baz');
1286
+ *
1287
+ * @name itself
1288
+ * @api public
1289
+ */
1290
+
1291
+ Assertion.addProperty('itself', function() {
1292
+ flag(this, 'itself', true);
1293
+ });
1294
+
1295
+ /**
1296
+ * ### .satisfy(method)
1297
+ *
1298
+ * Asserts that the target passes a given truth test.
1299
+ *
1300
+ * expect(1).to.satisfy(function(num) { return num > 0; });
1301
+ *
1302
+ * @name satisfy
1303
+ * @param {Function} matcher
1304
+ * @param {String} message _optional_
1305
+ * @api public
1306
+ */
1307
+
1308
+ Assertion.addMethod('satisfy', function(matcher, msg) {
1309
+ if (msg) flag(this, 'message', msg);
1310
+ var obj = flag(this, 'object');
1311
+ this.assert(
1312
+ matcher(obj), 'expected #{this} to satisfy ' + _.objDisplay(matcher), 'expected #{this} to not satisfy' + _.objDisplay(matcher), this.negate ? false : true, matcher(obj));
1313
+ });
1314
+
1315
+ /**
1316
+ * ### .closeTo(expected, delta)
1317
+ *
1318
+ * Asserts that the target is equal `expected`, to within a +/- `delta` range.
1319
+ *
1320
+ * expect(1.5).to.be.closeTo(1, 0.5);
1321
+ *
1322
+ * @name closeTo
1323
+ * @param {Number} expected
1324
+ * @param {Number} delta
1325
+ * @param {String} message _optional_
1326
+ * @api public
1327
+ */
1328
+
1329
+ Assertion.addMethod('closeTo', function(expected, delta, msg) {
1330
+ if (msg) flag(this, 'message', msg);
1331
+ var obj = flag(this, 'object');
1332
+ this.assert(
1333
+ Math.abs(obj - expected) <= delta, 'expected #{this} to be close to ' + expected + ' +/- ' + delta, 'expected #{this} not to be close to ' + expected + ' +/- ' + delta);
1334
+ });
1335
+
1336
+ };
1337
+
1338
+ }); // module: chai/core/assertions.js
1339
+ require.register("chai/error.js", function(module, exports, require) {
1340
+ /*!
1341
+ * chai
1342
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
1343
+ * MIT Licensed
1344
+ */
1345
+
1346
+ /*!
1347
+ * Main export
1348
+ */
1349
+
1350
+ module.exports = AssertionError;
1351
+
1352
+ /**
1353
+ * # AssertionError (constructor)
1354
+ *
1355
+ * Create a new assertion error based on the Javascript
1356
+ * `Error` prototype.
1357
+ *
1358
+ * **Options**
1359
+ * - message
1360
+ * - actual
1361
+ * - expected
1362
+ * - operator
1363
+ * - startStackFunction
1364
+ *
1365
+ * @param {Object} options
1366
+ * @api public
1367
+ */
1368
+
1369
+ function AssertionError(options) {
1370
+ options = options || {};
1371
+ this.message = options.message;
1372
+ this.actual = options.actual;
1373
+ this.expected = options.expected;
1374
+ this.operator = options.operator;
1375
+ this.showDiff = options.showDiff;
1376
+
1377
+ if (options.stackStartFunction && Error.captureStackTrace) {
1378
+ var stackStartFunction = options.stackStartFunction;
1379
+ Error.captureStackTrace(this, stackStartFunction);
1380
+ }
1381
+ }
1382
+
1383
+ /*!
1384
+ * Inherit from Error
1385
+ */
1386
+
1387
+ AssertionError.prototype = Object.create(Error.prototype);
1388
+ AssertionError.prototype.name = 'AssertionError';
1389
+ AssertionError.prototype.constructor = AssertionError;
1390
+
1391
+ /**
1392
+ * # toString()
1393
+ *
1394
+ * Override default to string method
1395
+ */
1396
+
1397
+ AssertionError.prototype.toString = function() {
1398
+ return this.message;
1399
+ };
1400
+
1401
+ }); // module: chai/error.js
1402
+ require.register("chai/interface/assert.js", function(module, exports, require) {
1403
+ /*!
1404
+ * chai
1405
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
1406
+ * MIT Licensed
1407
+ */
1408
+
1409
+
1410
+ module.exports = function(chai, util) {
1411
+
1412
+ /*!
1413
+ * Chai dependencies.
1414
+ */
1415
+
1416
+ var Assertion = chai.Assertion,
1417
+ flag = util.flag;
1418
+
1419
+ /*!
1420
+ * Module export.
1421
+ */
1422
+
1423
+ /**
1424
+ * ### assert(expression, message)
1425
+ *
1426
+ * Write your own test expressions.
1427
+ *
1428
+ * assert('foo' !== 'bar', 'foo is not bar');
1429
+ * assert(Array.isArray([]), 'empty arrays are arrays');
1430
+ *
1431
+ * @param {Mixed} expression to test for truthiness
1432
+ * @param {String} message to display on error
1433
+ * @name assert
1434
+ * @api public
1435
+ */
1436
+
1437
+ var assert = chai.assert = function(express, errmsg) {
1438
+ var test = new Assertion(null);
1439
+ test.assert(
1440
+ express, errmsg, '[ negation message unavailable ]');
1441
+ };
1442
+
1443
+ /**
1444
+ * ### .fail(actual, expected, [message], [operator])
1445
+ *
1446
+ * Throw a failure. Node.js `assert` module-compatible.
1447
+ *
1448
+ * @name fail
1449
+ * @param {Mixed} actual
1450
+ * @param {Mixed} expected
1451
+ * @param {String} message
1452
+ * @param {String} operator
1453
+ * @api public
1454
+ */
1455
+
1456
+ assert.fail = function(actual, expected, message, operator) {
1457
+ throw new chai.AssertionError({
1458
+ actual: actual,
1459
+ expected: expected,
1460
+ message: message,
1461
+ operator: operator,
1462
+ stackStartFunction: assert.fail
1463
+ });
1464
+ };
1465
+
1466
+ /**
1467
+ * ### .ok(object, [message])
1468
+ *
1469
+ * Asserts that `object` is truthy.
1470
+ *
1471
+ * assert.ok('everything', 'everything is ok');
1472
+ * assert.ok(false, 'this will fail');
1473
+ *
1474
+ * @name ok
1475
+ * @param {Mixed} object to test
1476
+ * @param {String} message
1477
+ * @api public
1478
+ */
1479
+
1480
+ assert.ok = function(val, msg) {
1481
+ new Assertion(val, msg).is.ok;
1482
+ };
1483
+
1484
+ /**
1485
+ * ### .equal(actual, expected, [message])
1486
+ *
1487
+ * Asserts non-strict equality (`==`) of `actual` and `expected`.
1488
+ *
1489
+ * assert.equal(3, '3', '== coerces values to strings');
1490
+ *
1491
+ * @name equal
1492
+ * @param {Mixed} actual
1493
+ * @param {Mixed} expected
1494
+ * @param {String} message
1495
+ * @api public
1496
+ */
1497
+
1498
+ assert.equal = function(act, exp, msg) {
1499
+ var test = new Assertion(act, msg);
1500
+
1501
+ test.assert(
1502
+ exp == flag(test, 'object'), 'expected #{this} to equal #{exp}', 'expected #{this} to not equal #{act}', exp, act);
1503
+ };
1504
+
1505
+ /**
1506
+ * ### .notEqual(actual, expected, [message])
1507
+ *
1508
+ * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
1509
+ *
1510
+ * assert.notEqual(3, 4, 'these numbers are not equal');
1511
+ *
1512
+ * @name notEqual
1513
+ * @param {Mixed} actual
1514
+ * @param {Mixed} expected
1515
+ * @param {String} message
1516
+ * @api public
1517
+ */
1518
+
1519
+ assert.notEqual = function(act, exp, msg) {
1520
+ var test = new Assertion(act, msg);
1521
+
1522
+ test.assert(
1523
+ exp != flag(test, 'object'), 'expected #{this} to not equal #{exp}', 'expected #{this} to equal #{act}', exp, act);
1524
+ };
1525
+
1526
+ /**
1527
+ * ### .strictEqual(actual, expected, [message])
1528
+ *
1529
+ * Asserts strict equality (`===`) of `actual` and `expected`.
1530
+ *
1531
+ * assert.strictEqual(true, true, 'these booleans are strictly equal');
1532
+ *
1533
+ * @name strictEqual
1534
+ * @param {Mixed} actual
1535
+ * @param {Mixed} expected
1536
+ * @param {String} message
1537
+ * @api public
1538
+ */
1539
+
1540
+ assert.strictEqual = function(act, exp, msg) {
1541
+ new Assertion(act, msg).to.equal(exp);
1542
+ };
1543
+
1544
+ /**
1545
+ * ### .notStrictEqual(actual, expected, [message])
1546
+ *
1547
+ * Asserts strict inequality (`!==`) of `actual` and `expected`.
1548
+ *
1549
+ * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
1550
+ *
1551
+ * @name notStrictEqual
1552
+ * @param {Mixed} actual
1553
+ * @param {Mixed} expected
1554
+ * @param {String} message
1555
+ * @api public
1556
+ */
1557
+
1558
+ assert.notStrictEqual = function(act, exp, msg) {
1559
+ new Assertion(act, msg).to.not.equal(exp);
1560
+ };
1561
+
1562
+ /**
1563
+ * ### .deepEqual(actual, expected, [message])
1564
+ *
1565
+ * Asserts that `actual` is deeply equal to `expected`.
1566
+ *
1567
+ * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
1568
+ *
1569
+ * @name deepEqual
1570
+ * @param {Mixed} actual
1571
+ * @param {Mixed} expected
1572
+ * @param {String} message
1573
+ * @api public
1574
+ */
1575
+
1576
+ assert.deepEqual = function(act, exp, msg) {
1577
+ new Assertion(act, msg).to.eql(exp);
1578
+ };
1579
+
1580
+ /**
1581
+ * ### .notDeepEqual(actual, expected, [message])
1582
+ *
1583
+ * Assert that `actual` is not deeply equal to `expected`.
1584
+ *
1585
+ * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
1586
+ *
1587
+ * @name notDeepEqual
1588
+ * @param {Mixed} actual
1589
+ * @param {Mixed} expected
1590
+ * @param {String} message
1591
+ * @api public
1592
+ */
1593
+
1594
+ assert.notDeepEqual = function(act, exp, msg) {
1595
+ new Assertion(act, msg).to.not.eql(exp);
1596
+ };
1597
+
1598
+ /**
1599
+ * ### .isTrue(value, [message])
1600
+ *
1601
+ * Asserts that `value` is true.
1602
+ *
1603
+ * var teaServed = true;
1604
+ * assert.isTrue(teaServed, 'the tea has been served');
1605
+ *
1606
+ * @name isTrue
1607
+ * @param {Mixed} value
1608
+ * @param {String} message
1609
+ * @api public
1610
+ */
1611
+
1612
+ assert.isTrue = function(val, msg) {
1613
+ new Assertion(val, msg).is['true'];
1614
+ };
1615
+
1616
+ /**
1617
+ * ### .isFalse(value, [message])
1618
+ *
1619
+ * Asserts that `value` is false.
1620
+ *
1621
+ * var teaServed = false;
1622
+ * assert.isFalse(teaServed, 'no tea yet? hmm...');
1623
+ *
1624
+ * @name isFalse
1625
+ * @param {Mixed} value
1626
+ * @param {String} message
1627
+ * @api public
1628
+ */
1629
+
1630
+ assert.isFalse = function(val, msg) {
1631
+ new Assertion(val, msg).is['false'];
1632
+ };
1633
+
1634
+ /**
1635
+ * ### .isNull(value, [message])
1636
+ *
1637
+ * Asserts that `value` is null.
1638
+ *
1639
+ * assert.isNull(err, 'there was no error');
1640
+ *
1641
+ * @name isNull
1642
+ * @param {Mixed} value
1643
+ * @param {String} message
1644
+ * @api public
1645
+ */
1646
+
1647
+ assert.isNull = function(val, msg) {
1648
+ new Assertion(val, msg).to.equal(null);
1649
+ };
1650
+
1651
+ /**
1652
+ * ### .isNotNull(value, [message])
1653
+ *
1654
+ * Asserts that `value` is not null.
1655
+ *
1656
+ * var tea = 'tasty chai';
1657
+ * assert.isNotNull(tea, 'great, time for tea!');
1658
+ *
1659
+ * @name isNotNull
1660
+ * @param {Mixed} value
1661
+ * @param {String} message
1662
+ * @api public
1663
+ */
1664
+
1665
+ assert.isNotNull = function(val, msg) {
1666
+ new Assertion(val, msg).to.not.equal(null);
1667
+ };
1668
+
1669
+ /**
1670
+ * ### .isUndefined(value, [message])
1671
+ *
1672
+ * Asserts that `value` is `undefined`.
1673
+ *
1674
+ * var tea;
1675
+ * assert.isUndefined(tea, 'no tea defined');
1676
+ *
1677
+ * @name isUndefined
1678
+ * @param {Mixed} value
1679
+ * @param {String} message
1680
+ * @api public
1681
+ */
1682
+
1683
+ assert.isUndefined = function(val, msg) {
1684
+ new Assertion(val, msg).to.equal(undefined);
1685
+ };
1686
+
1687
+ /**
1688
+ * ### .isDefined(value, [message])
1689
+ *
1690
+ * Asserts that `value` is not `undefined`.
1691
+ *
1692
+ * var tea = 'cup of chai';
1693
+ * assert.isDefined(tea, 'tea has been defined');
1694
+ *
1695
+ * @name isUndefined
1696
+ * @param {Mixed} value
1697
+ * @param {String} message
1698
+ * @api public
1699
+ */
1700
+
1701
+ assert.isDefined = function(val, msg) {
1702
+ new Assertion(val, msg).to.not.equal(undefined);
1703
+ };
1704
+
1705
+ /**
1706
+ * ### .isFunction(value, [message])
1707
+ *
1708
+ * Asserts that `value` is a function.
1709
+ *
1710
+ * function serveTea() { return 'cup of tea'; };
1711
+ * assert.isFunction(serveTea, 'great, we can have tea now');
1712
+ *
1713
+ * @name isFunction
1714
+ * @param {Mixed} value
1715
+ * @param {String} message
1716
+ * @api public
1717
+ */
1718
+
1719
+ assert.isFunction = function(val, msg) {
1720
+ new Assertion(val, msg).to.be.a('function');
1721
+ };
1722
+
1723
+ /**
1724
+ * ### .isNotFunction(value, [message])
1725
+ *
1726
+ * Asserts that `value` is _not_ a function.
1727
+ *
1728
+ * var serveTea = [ 'heat', 'pour', 'sip' ];
1729
+ * assert.isNotFunction(serveTea, 'great, we have listed the steps');
1730
+ *
1731
+ * @name isNotFunction
1732
+ * @param {Mixed} value
1733
+ * @param {String} message
1734
+ * @api public
1735
+ */
1736
+
1737
+ assert.isNotFunction = function(val, msg) {
1738
+ new Assertion(val, msg).to.not.be.a('function');
1739
+ };
1740
+
1741
+ /**
1742
+ * ### .isObject(value, [message])
1743
+ *
1744
+ * Asserts that `value` is an object (as revealed by
1745
+ * `Object.prototype.toString`).
1746
+ *
1747
+ * var selection = { name: 'Chai', serve: 'with spices' };
1748
+ * assert.isObject(selection, 'tea selection is an object');
1749
+ *
1750
+ * @name isObject
1751
+ * @param {Mixed} value
1752
+ * @param {String} message
1753
+ * @api public
1754
+ */
1755
+
1756
+ assert.isObject = function(val, msg) {
1757
+ new Assertion(val, msg).to.be.a('object');
1758
+ };
1759
+
1760
+ /**
1761
+ * ### .isNotObject(value, [message])
1762
+ *
1763
+ * Asserts that `value` is _not_ an object.
1764
+ *
1765
+ * var selection = 'chai'
1766
+ * assert.isObject(selection, 'tea selection is not an object');
1767
+ * assert.isObject(null, 'null is not an object');
1768
+ *
1769
+ * @name isNotObject
1770
+ * @param {Mixed} value
1771
+ * @param {String} message
1772
+ * @api public
1773
+ */
1774
+
1775
+ assert.isNotObject = function(val, msg) {
1776
+ new Assertion(val, msg).to.not.be.a('object');
1777
+ };
1778
+
1779
+ /**
1780
+ * ### .isArray(value, [message])
1781
+ *
1782
+ * Asserts that `value` is an array.
1783
+ *
1784
+ * var menu = [ 'green', 'chai', 'oolong' ];
1785
+ * assert.isArray(menu, 'what kind of tea do we want?');
1786
+ *
1787
+ * @name isArray
1788
+ * @param {Mixed} value
1789
+ * @param {String} message
1790
+ * @api public
1791
+ */
1792
+
1793
+ assert.isArray = function(val, msg) {
1794
+ new Assertion(val, msg).to.be.an('array');
1795
+ };
1796
+
1797
+ /**
1798
+ * ### .isNotArray(value, [message])
1799
+ *
1800
+ * Asserts that `value` is _not_ an array.
1801
+ *
1802
+ * var menu = 'green|chai|oolong';
1803
+ * assert.isNotArray(menu, 'what kind of tea do we want?');
1804
+ *
1805
+ * @name isNotArray
1806
+ * @param {Mixed} value
1807
+ * @param {String} message
1808
+ * @api public
1809
+ */
1810
+
1811
+ assert.isNotArray = function(val, msg) {
1812
+ new Assertion(val, msg).to.not.be.an('array');
1813
+ };
1814
+
1815
+ /**
1816
+ * ### .isString(value, [message])
1817
+ *
1818
+ * Asserts that `value` is a string.
1819
+ *
1820
+ * var teaOrder = 'chai';
1821
+ * assert.isString(teaOrder, 'order placed');
1822
+ *
1823
+ * @name isString
1824
+ * @param {Mixed} value
1825
+ * @param {String} message
1826
+ * @api public
1827
+ */
1828
+
1829
+ assert.isString = function(val, msg) {
1830
+ new Assertion(val, msg).to.be.a('string');
1831
+ };
1832
+
1833
+ /**
1834
+ * ### .isNotString(value, [message])
1835
+ *
1836
+ * Asserts that `value` is _not_ a string.
1837
+ *
1838
+ * var teaOrder = 4;
1839
+ * assert.isNotString(teaOrder, 'order placed');
1840
+ *
1841
+ * @name isNotString
1842
+ * @param {Mixed} value
1843
+ * @param {String} message
1844
+ * @api public
1845
+ */
1846
+
1847
+ assert.isNotString = function(val, msg) {
1848
+ new Assertion(val, msg).to.not.be.a('string');
1849
+ };
1850
+
1851
+ /**
1852
+ * ### .isNumber(value, [message])
1853
+ *
1854
+ * Asserts that `value` is a number.
1855
+ *
1856
+ * var cups = 2;
1857
+ * assert.isNumber(cups, 'how many cups');
1858
+ *
1859
+ * @name isNumber
1860
+ * @param {Number} value
1861
+ * @param {String} message
1862
+ * @api public
1863
+ */
1864
+
1865
+ assert.isNumber = function(val, msg) {
1866
+ new Assertion(val, msg).to.be.a('number');
1867
+ };
1868
+
1869
+ /**
1870
+ * ### .isNotNumber(value, [message])
1871
+ *
1872
+ * Asserts that `value` is _not_ a number.
1873
+ *
1874
+ * var cups = '2 cups please';
1875
+ * assert.isNotNumber(cups, 'how many cups');
1876
+ *
1877
+ * @name isNotNumber
1878
+ * @param {Mixed} value
1879
+ * @param {String} message
1880
+ * @api public
1881
+ */
1882
+
1883
+ assert.isNotNumber = function(val, msg) {
1884
+ new Assertion(val, msg).to.not.be.a('number');
1885
+ };
1886
+
1887
+ /**
1888
+ * ### .isBoolean(value, [message])
1889
+ *
1890
+ * Asserts that `value` is a boolean.
1891
+ *
1892
+ * var teaReady = true
1893
+ * , teaServed = false;
1894
+ *
1895
+ * assert.isBoolean(teaReady, 'is the tea ready');
1896
+ * assert.isBoolean(teaServed, 'has tea been served');
1897
+ *
1898
+ * @name isBoolean
1899
+ * @param {Mixed} value
1900
+ * @param {String} message
1901
+ * @api public
1902
+ */
1903
+
1904
+ assert.isBoolean = function(val, msg) {
1905
+ new Assertion(val, msg).to.be.a('boolean');
1906
+ };
1907
+
1908
+ /**
1909
+ * ### .isNotBoolean(value, [message])
1910
+ *
1911
+ * Asserts that `value` is _not_ a boolean.
1912
+ *
1913
+ * var teaReady = 'yep'
1914
+ * , teaServed = 'nope';
1915
+ *
1916
+ * assert.isNotBoolean(teaReady, 'is the tea ready');
1917
+ * assert.isNotBoolean(teaServed, 'has tea been served');
1918
+ *
1919
+ * @name isNotBoolean
1920
+ * @param {Mixed} value
1921
+ * @param {String} message
1922
+ * @api public
1923
+ */
1924
+
1925
+ assert.isNotBoolean = function(val, msg) {
1926
+ new Assertion(val, msg).to.not.be.a('boolean');
1927
+ };
1928
+
1929
+ /**
1930
+ * ### .typeOf(value, name, [message])
1931
+ *
1932
+ * Asserts that `value`'s type is `name`, as determined by
1933
+ * `Object.prototype.toString`.
1934
+ *
1935
+ * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
1936
+ * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
1937
+ * assert.typeOf('tea', 'string', 'we have a string');
1938
+ * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
1939
+ * assert.typeOf(null, 'null', 'we have a null');
1940
+ * assert.typeOf(undefined, 'undefined', 'we have an undefined');
1941
+ *
1942
+ * @name typeOf
1943
+ * @param {Mixed} value
1944
+ * @param {String} name
1945
+ * @param {String} message
1946
+ * @api public
1947
+ */
1948
+
1949
+ assert.typeOf = function(val, type, msg) {
1950
+ new Assertion(val, msg).to.be.a(type);
1951
+ };
1952
+
1953
+ /**
1954
+ * ### .notTypeOf(value, name, [message])
1955
+ *
1956
+ * Asserts that `value`'s type is _not_ `name`, as determined by
1957
+ * `Object.prototype.toString`.
1958
+ *
1959
+ * assert.notTypeOf('tea', 'number', 'strings are not numbers');
1960
+ *
1961
+ * @name notTypeOf
1962
+ * @param {Mixed} value
1963
+ * @param {String} typeof name
1964
+ * @param {String} message
1965
+ * @api public
1966
+ */
1967
+
1968
+ assert.notTypeOf = function(val, type, msg) {
1969
+ new Assertion(val, msg).to.not.be.a(type);
1970
+ };
1971
+
1972
+ /**
1973
+ * ### .instanceOf(object, constructor, [message])
1974
+ *
1975
+ * Asserts that `value` is an instance of `constructor`.
1976
+ *
1977
+ * var Tea = function (name) { this.name = name; }
1978
+ * , chai = new Tea('chai');
1979
+ *
1980
+ * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
1981
+ *
1982
+ * @name instanceOf
1983
+ * @param {Object} object
1984
+ * @param {Constructor} constructor
1985
+ * @param {String} message
1986
+ * @api public
1987
+ */
1988
+
1989
+ assert.instanceOf = function(val, type, msg) {
1990
+ new Assertion(val, msg).to.be.instanceOf(type);
1991
+ };
1992
+
1993
+ /**
1994
+ * ### .notInstanceOf(object, constructor, [message])
1995
+ *
1996
+ * Asserts `value` is not an instance of `constructor`.
1997
+ *
1998
+ * var Tea = function (name) { this.name = name; }
1999
+ * , chai = new String('chai');
2000
+ *
2001
+ * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
2002
+ *
2003
+ * @name notInstanceOf
2004
+ * @param {Object} object
2005
+ * @param {Constructor} constructor
2006
+ * @param {String} message
2007
+ * @api public
2008
+ */
2009
+
2010
+ assert.notInstanceOf = function(val, type, msg) {
2011
+ new Assertion(val, msg).to.not.be.instanceOf(type);
2012
+ };
2013
+
2014
+ /**
2015
+ * ### .include(haystack, needle, [message])
2016
+ *
2017
+ * Asserts that `haystack` includes `needle`. Works
2018
+ * for strings and arrays.
2019
+ *
2020
+ * assert.include('foobar', 'bar', 'foobar contains string "bar"');
2021
+ * assert.include([ 1, 2, 3 ], 3, 'array contains value');
2022
+ *
2023
+ * @name include
2024
+ * @param {Array|String} haystack
2025
+ * @param {Mixed} needle
2026
+ * @param {String} message
2027
+ * @api public
2028
+ */
2029
+
2030
+ assert.include = function(exp, inc, msg) {
2031
+ var obj = new Assertion(exp, msg);
2032
+
2033
+ if (Array.isArray(exp)) {
2034
+ obj.to.include(inc);
2035
+ } else if ('string' === typeof exp) {
2036
+ obj.to.contain.string(inc);
2037
+ }
2038
+ };
2039
+
2040
+ /**
2041
+ * ### .match(value, regexp, [message])
2042
+ *
2043
+ * Asserts that `value` matches the regular expression `regexp`.
2044
+ *
2045
+ * assert.match('foobar', /^foo/, 'regexp matches');
2046
+ *
2047
+ * @name match
2048
+ * @param {Mixed} value
2049
+ * @param {RegExp} regexp
2050
+ * @param {String} message
2051
+ * @api public
2052
+ */
2053
+
2054
+ assert.match = function(exp, re, msg) {
2055
+ new Assertion(exp, msg).to.match(re);
2056
+ };
2057
+
2058
+ /**
2059
+ * ### .notMatch(value, regexp, [message])
2060
+ *
2061
+ * Asserts that `value` does not match the regular expression `regexp`.
2062
+ *
2063
+ * assert.notMatch('foobar', /^foo/, 'regexp does not match');
2064
+ *
2065
+ * @name notMatch
2066
+ * @param {Mixed} value
2067
+ * @param {RegExp} regexp
2068
+ * @param {String} message
2069
+ * @api public
2070
+ */
2071
+
2072
+ assert.notMatch = function(exp, re, msg) {
2073
+ new Assertion(exp, msg).to.not.match(re);
2074
+ };
2075
+
2076
+ /**
2077
+ * ### .property(object, property, [message])
2078
+ *
2079
+ * Asserts that `object` has a property named by `property`.
2080
+ *
2081
+ * assert.property({ tea: { green: 'matcha' }}, 'tea');
2082
+ *
2083
+ * @name property
2084
+ * @param {Object} object
2085
+ * @param {String} property
2086
+ * @param {String} message
2087
+ * @api public
2088
+ */
2089
+
2090
+ assert.property = function(obj, prop, msg) {
2091
+ new Assertion(obj, msg).to.have.property(prop);
2092
+ };
2093
+
2094
+ /**
2095
+ * ### .notProperty(object, property, [message])
2096
+ *
2097
+ * Asserts that `object` does _not_ have a property named by `property`.
2098
+ *
2099
+ * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
2100
+ *
2101
+ * @name notProperty
2102
+ * @param {Object} object
2103
+ * @param {String} property
2104
+ * @param {String} message
2105
+ * @api public
2106
+ */
2107
+
2108
+ assert.notProperty = function(obj, prop, msg) {
2109
+ new Assertion(obj, msg).to.not.have.property(prop);
2110
+ };
2111
+
2112
+ /**
2113
+ * ### .deepProperty(object, property, [message])
2114
+ *
2115
+ * Asserts that `object` has a property named by `property`, which can be a
2116
+ * string using dot- and bracket-notation for deep reference.
2117
+ *
2118
+ * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
2119
+ *
2120
+ * @name deepProperty
2121
+ * @param {Object} object
2122
+ * @param {String} property
2123
+ * @param {String} message
2124
+ * @api public
2125
+ */
2126
+
2127
+ assert.deepProperty = function(obj, prop, msg) {
2128
+ new Assertion(obj, msg).to.have.deep.property(prop);
2129
+ };
2130
+
2131
+ /**
2132
+ * ### .notDeepProperty(object, property, [message])
2133
+ *
2134
+ * Asserts that `object` does _not_ have a property named by `property`, which
2135
+ * can be a string using dot- and bracket-notation for deep reference.
2136
+ *
2137
+ * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
2138
+ *
2139
+ * @name notDeepProperty
2140
+ * @param {Object} object
2141
+ * @param {String} property
2142
+ * @param {String} message
2143
+ * @api public
2144
+ */
2145
+
2146
+ assert.notDeepProperty = function(obj, prop, msg) {
2147
+ new Assertion(obj, msg).to.not.have.deep.property(prop);
2148
+ };
2149
+
2150
+ /**
2151
+ * ### .propertyVal(object, property, value, [message])
2152
+ *
2153
+ * Asserts that `object` has a property named by `property` with value given
2154
+ * by `value`.
2155
+ *
2156
+ * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
2157
+ *
2158
+ * @name propertyVal
2159
+ * @param {Object} object
2160
+ * @param {String} property
2161
+ * @param {Mixed} value
2162
+ * @param {String} message
2163
+ * @api public
2164
+ */
2165
+
2166
+ assert.propertyVal = function(obj, prop, val, msg) {
2167
+ new Assertion(obj, msg).to.have.property(prop, val);
2168
+ };
2169
+
2170
+ /**
2171
+ * ### .propertyNotVal(object, property, value, [message])
2172
+ *
2173
+ * Asserts that `object` has a property named by `property`, but with a value
2174
+ * different from that given by `value`.
2175
+ *
2176
+ * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
2177
+ *
2178
+ * @name propertyNotVal
2179
+ * @param {Object} object
2180
+ * @param {String} property
2181
+ * @param {Mixed} value
2182
+ * @param {String} message
2183
+ * @api public
2184
+ */
2185
+
2186
+ assert.propertyNotVal = function(obj, prop, val, msg) {
2187
+ new Assertion(obj, msg).to.not.have.property(prop, val);
2188
+ };
2189
+
2190
+ /**
2191
+ * ### .deepPropertyVal(object, property, value, [message])
2192
+ *
2193
+ * Asserts that `object` has a property named by `property` with value given
2194
+ * by `value`. `property` can use dot- and bracket-notation for deep
2195
+ * reference.
2196
+ *
2197
+ * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
2198
+ *
2199
+ * @name deepPropertyVal
2200
+ * @param {Object} object
2201
+ * @param {String} property
2202
+ * @param {Mixed} value
2203
+ * @param {String} message
2204
+ * @api public
2205
+ */
2206
+
2207
+ assert.deepPropertyVal = function(obj, prop, val, msg) {
2208
+ new Assertion(obj, msg).to.have.deep.property(prop, val);
2209
+ };
2210
+
2211
+ /**
2212
+ * ### .deepPropertyNotVal(object, property, value, [message])
2213
+ *
2214
+ * Asserts that `object` has a property named by `property`, but with a value
2215
+ * different from that given by `value`. `property` can use dot- and
2216
+ * bracket-notation for deep reference.
2217
+ *
2218
+ * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
2219
+ *
2220
+ * @name deepPropertyNotVal
2221
+ * @param {Object} object
2222
+ * @param {String} property
2223
+ * @param {Mixed} value
2224
+ * @param {String} message
2225
+ * @api public
2226
+ */
2227
+
2228
+ assert.deepPropertyNotVal = function(obj, prop, val, msg) {
2229
+ new Assertion(obj, msg).to.not.have.deep.property(prop, val);
2230
+ };
2231
+
2232
+ /**
2233
+ * ### .lengthOf(object, length, [message])
2234
+ *
2235
+ * Asserts that `object` has a `length` property with the expected value.
2236
+ *
2237
+ * assert.lengthOf([1,2,3], 3, 'array has length of 3');
2238
+ * assert.lengthOf('foobar', 5, 'string has length of 6');
2239
+ *
2240
+ * @name lengthOf
2241
+ * @param {Mixed} object
2242
+ * @param {Number} length
2243
+ * @param {String} message
2244
+ * @api public
2245
+ */
2246
+
2247
+ assert.lengthOf = function(exp, len, msg) {
2248
+ new Assertion(exp, msg).to.have.length(len);
2249
+ };
2250
+
2251
+ /**
2252
+ * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
2253
+ *
2254
+ * Asserts that `function` will throw an error that is an instance of
2255
+ * `constructor`, or alternately that it will throw an error with message
2256
+ * matching `regexp`.
2257
+ *
2258
+ * assert.throw(fn, 'function throws a reference error');
2259
+ * assert.throw(fn, /function throws a reference error/);
2260
+ * assert.throw(fn, ReferenceError);
2261
+ * assert.throw(fn, ReferenceError, 'function throws a reference error');
2262
+ * assert.throw(fn, ReferenceError, /function throws a reference error/);
2263
+ *
2264
+ * @name throws
2265
+ * @alias throw
2266
+ * @alias Throw
2267
+ * @param {Function} function
2268
+ * @param {ErrorConstructor} constructor
2269
+ * @param {RegExp} regexp
2270
+ * @param {String} message
2271
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2272
+ * @api public
2273
+ */
2274
+
2275
+ assert.Throw = function(fn, errt, errs, msg) {
2276
+ if ('string' === typeof errt || errt instanceof RegExp) {
2277
+ errs = errt;
2278
+ errt = null;
2279
+ }
2280
+
2281
+ new Assertion(fn, msg).to.Throw(errt, errs);
2282
+ };
2283
+
2284
+ /**
2285
+ * ### .doesNotThrow(function, [constructor/regexp], [message])
2286
+ *
2287
+ * Asserts that `function` will _not_ throw an error that is an instance of
2288
+ * `constructor`, or alternately that it will not throw an error with message
2289
+ * matching `regexp`.
2290
+ *
2291
+ * assert.doesNotThrow(fn, Error, 'function does not throw');
2292
+ *
2293
+ * @name doesNotThrow
2294
+ * @param {Function} function
2295
+ * @param {ErrorConstructor} constructor
2296
+ * @param {RegExp} regexp
2297
+ * @param {String} message
2298
+ * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2299
+ * @api public
2300
+ */
2301
+
2302
+ assert.doesNotThrow = function(fn, type, msg) {
2303
+ if ('string' === typeof type) {
2304
+ msg = type;
2305
+ type = null;
2306
+ }
2307
+
2308
+ new Assertion(fn, msg).to.not.Throw(type);
2309
+ };
2310
+
2311
+ /**
2312
+ * ### .operator(val1, operator, val2, [message])
2313
+ *
2314
+ * Compares two values using `operator`.
2315
+ *
2316
+ * assert.operator(1, '<', 2, 'everything is ok');
2317
+ * assert.operator(1, '>', 2, 'this will fail');
2318
+ *
2319
+ * @name operator
2320
+ * @param {Mixed} val1
2321
+ * @param {String} operator
2322
+ * @param {Mixed} val2
2323
+ * @param {String} message
2324
+ * @api public
2325
+ */
2326
+
2327
+ assert.operator = function(val, operator, val2, msg) {
2328
+ if (!~ ['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
2329
+ throw new Error('Invalid operator "' + operator + '"');
2330
+ }
2331
+ var test = new Assertion(eval(val + operator + val2), msg);
2332
+ test.assert(
2333
+ true === flag(test, 'object'), 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2), 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2));
2334
+ };
2335
+
2336
+ /**
2337
+ * ### .closeTo(actual, expected, delta, [message])
2338
+ *
2339
+ * Asserts that the target is equal `expected`, to within a +/- `delta` range.
2340
+ *
2341
+ * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
2342
+ *
2343
+ * @name closeTo
2344
+ * @param {Number} actual
2345
+ * @param {Number} expected
2346
+ * @param {Number} delta
2347
+ * @param {String} message
2348
+ * @api public
2349
+ */
2350
+
2351
+ assert.closeTo = function(act, exp, delta, msg) {
2352
+ new Assertion(act, msg).to.be.closeTo(exp, delta);
2353
+ };
2354
+
2355
+ /*!
2356
+ * Undocumented / untested
2357
+ */
2358
+
2359
+ assert.ifError = function(val, msg) {
2360
+ new Assertion(val, msg).to.not.be.ok;
2361
+ };
2362
+
2363
+ /*!
2364
+ * Aliases.
2365
+ */
2366
+
2367
+ (function alias(name, as) {
2368
+ assert[as] = assert[name];
2369
+ return alias;
2370
+ })
2371
+ ('Throw', 'throw')
2372
+ ('Throw', 'throws');
2373
+ };
2374
+
2375
+ }); // module: chai/interface/assert.js
2376
+ require.register("chai/interface/expect.js", function(module, exports, require) {
2377
+ /*!
2378
+ * chai
2379
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2380
+ * MIT Licensed
2381
+ */
2382
+
2383
+ module.exports = function(chai, util) {
2384
+ chai.expect = function(val, message) {
2385
+ return new chai.Assertion(val, message);
2386
+ };
2387
+ };
2388
+
2389
+
2390
+ }); // module: chai/interface/expect.js
2391
+ require.register("chai/interface/should.js", function(module, exports, require) {
2392
+ /*!
2393
+ * chai
2394
+ * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2395
+ * MIT Licensed
2396
+ */
2397
+
2398
+ module.exports = function(chai, util) {
2399
+ var Assertion = chai.Assertion;
2400
+
2401
+ function loadShould() {
2402
+ // modify Object.prototype to have `should`
2403
+ Object.defineProperty(Object.prototype, 'should', {
2404
+ set: function(value) {
2405
+ // See https://github.com/chaijs/chai/issues/86: this makes
2406
+ // `whatever.should = someValue` actually set `someValue`, which is
2407
+ // especially useful for `global.should = require('chai').should()`.
2408
+ //
2409
+ // Note that we have to use [[DefineProperty]] instead of [[Put]]
2410
+ // since otherwise we would trigger this very setter!
2411
+ Object.defineProperty(this, 'should', {
2412
+ value: value,
2413
+ enumerable: true,
2414
+ configurable: true,
2415
+ writable: true
2416
+ });
2417
+ },
2418
+ get: function() {
2419
+ if (this instanceof String || this instanceof Number) {
2420
+ return new Assertion(this.constructor(this));
2421
+ } else if (this instanceof Boolean) {
2422
+ return new Assertion(this == true);
2423
+ }
2424
+ return new Assertion(this);
2425
+ },
2426
+ configurable: true
2427
+ });
2428
+
2429
+ var should = {};
2430
+
2431
+ should.equal = function(val1, val2, msg) {
2432
+ new Assertion(val1, msg).to.equal(val2);
2433
+ };
2434
+
2435
+ should.Throw = function(fn, errt, errs, msg) {
2436
+ new Assertion(fn, msg).to.Throw(errt, errs);
2437
+ };
2438
+
2439
+ should.exist = function(val, msg) {
2440
+ new Assertion(val, msg).to.exist;
2441
+ }
2442
+
2443
+ // negation
2444
+ should.not = {}
2445
+
2446
+ should.not.equal = function(val1, val2, msg) {
2447
+ new Assertion(val1, msg).to.not.equal(val2);
2448
+ };
2449
+
2450
+ should.not.Throw = function(fn, errt, errs, msg) {
2451
+ new Assertion(fn, msg).to.not.Throw(errt, errs);
2452
+ };
2453
+
2454
+ should.not.exist = function(val, msg) {
2455
+ new Assertion(val, msg).to.not.exist;
2456
+ }
2457
+
2458
+ should['throw'] = should['Throw'];
2459
+ should.not['throw'] = should.not['Throw'];
2460
+
2461
+ return should;
2462
+ };
2463
+
2464
+ chai.should = loadShould;
2465
+ chai.Should = loadShould;
2466
+ };
2467
+
2468
+ }); // module: chai/interface/should.js
2469
+ require.register("chai/utils/addChainableMethod.js", function(module, exports, require) {
2470
+ /*!
2471
+ * Chai - addChainingMethod utility
2472
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2473
+ * MIT Licensed
2474
+ */
2475
+
2476
+ /*!
2477
+ * Module dependencies
2478
+ */
2479
+
2480
+ var transferFlags = require('./transferFlags');
2481
+
2482
+ /*!
2483
+ * Module variables
2484
+ */
2485
+
2486
+ // Check whether `__proto__` is supported
2487
+ var hasProtoSupport = '__proto__' in Object;
2488
+
2489
+ // Without `__proto__` support, this module will need to add properties to a function.
2490
+ // However, some Function.prototype methods cannot be overwritten,
2491
+ // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
2492
+ var excludeNames = /^(?:length|name|arguments|caller)$/;
2493
+
2494
+ /**
2495
+ * ### addChainableMethod (ctx, name, method, chainingBehavior)
2496
+ *
2497
+ * Adds a method to an object, such that the method can also be chained.
2498
+ *
2499
+ * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
2500
+ * var obj = utils.flag(this, 'object');
2501
+ * new chai.Assertion(obj).to.be.equal(str);
2502
+ * });
2503
+ *
2504
+ * Can also be accessed directly from `chai.Assertion`.
2505
+ *
2506
+ * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
2507
+ *
2508
+ * The result can then be used as both a method assertion, executing both `method` and
2509
+ * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
2510
+ *
2511
+ * expect(fooStr).to.be.foo('bar');
2512
+ * expect(fooStr).to.be.foo.equal('foo');
2513
+ *
2514
+ * @param {Object} ctx object to which the method is added
2515
+ * @param {String} name of method to add
2516
+ * @param {Function} method function to be used for `name`, when called
2517
+ * @param {Function} chainingBehavior function to be called every time the property is accessed
2518
+ * @name addChainableMethod
2519
+ * @api public
2520
+ */
2521
+
2522
+ module.exports = function(ctx, name, method, chainingBehavior) {
2523
+ if (typeof chainingBehavior !== 'function') chainingBehavior = function() {};
2524
+
2525
+ Object.defineProperty(ctx, name, {
2526
+ get: function() {
2527
+ chainingBehavior.call(this);
2528
+
2529
+ var assert = function() {
2530
+ var result = method.apply(this, arguments);
2531
+ return result === undefined ? this : result;
2532
+ };
2533
+
2534
+ // Use `__proto__` if available
2535
+ if (hasProtoSupport) {
2536
+ assert.__proto__ = this;
2537
+ }
2538
+ // Otherwise, redefine all properties (slow!)
2539
+ else {
2540
+ var asserterNames = Object.getOwnPropertyNames(ctx);
2541
+ asserterNames.forEach(function(asserterName) {
2542
+ if (!excludeNames.test(asserterName)) {
2543
+ var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
2544
+ Object.defineProperty(assert, asserterName, pd);
2545
+ }
2546
+ });
2547
+ }
2548
+
2549
+ transferFlags(this, assert);
2550
+ return assert;
2551
+ },
2552
+ configurable: true
2553
+ });
2554
+ };
2555
+
2556
+ }); // module: chai/utils/addChainableMethod.js
2557
+ require.register("chai/utils/addMethod.js", function(module, exports, require) {
2558
+ /*!
2559
+ * Chai - addMethod utility
2560
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2561
+ * MIT Licensed
2562
+ */
2563
+
2564
+ /**
2565
+ * ### .addMethod (ctx, name, method)
2566
+ *
2567
+ * Adds a method to the prototype of an object.
2568
+ *
2569
+ * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
2570
+ * var obj = utils.flag(this, 'object');
2571
+ * new chai.Assertion(obj).to.be.equal(str);
2572
+ * });
2573
+ *
2574
+ * Can also be accessed directly from `chai.Assertion`.
2575
+ *
2576
+ * chai.Assertion.addMethod('foo', fn);
2577
+ *
2578
+ * Then can be used as any other assertion.
2579
+ *
2580
+ * expect(fooStr).to.be.foo('bar');
2581
+ *
2582
+ * @param {Object} ctx object to which the method is added
2583
+ * @param {String} name of method to add
2584
+ * @param {Function} method function to be used for name
2585
+ * @name addMethod
2586
+ * @api public
2587
+ */
2588
+
2589
+ module.exports = function(ctx, name, method) {
2590
+ ctx[name] = function() {
2591
+ var result = method.apply(this, arguments);
2592
+ return result === undefined ? this : result;
2593
+ };
2594
+ };
2595
+
2596
+ }); // module: chai/utils/addMethod.js
2597
+ require.register("chai/utils/addProperty.js", function(module, exports, require) {
2598
+ /*!
2599
+ * Chai - addProperty utility
2600
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2601
+ * MIT Licensed
2602
+ */
2603
+
2604
+ /**
2605
+ * ### addProperty (ctx, name, getter)
2606
+ *
2607
+ * Adds a property to the prototype of an object.
2608
+ *
2609
+ * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
2610
+ * var obj = utils.flag(this, 'object');
2611
+ * new chai.Assertion(obj).to.be.instanceof(Foo);
2612
+ * });
2613
+ *
2614
+ * Can also be accessed directly from `chai.Assertion`.
2615
+ *
2616
+ * chai.Assertion.addProperty('foo', fn);
2617
+ *
2618
+ * Then can be used as any other assertion.
2619
+ *
2620
+ * expect(myFoo).to.be.foo;
2621
+ *
2622
+ * @param {Object} ctx object to which the property is added
2623
+ * @param {String} name of property to add
2624
+ * @param {Function} getter function to be used for name
2625
+ * @name addProperty
2626
+ * @api public
2627
+ */
2628
+
2629
+ module.exports = function(ctx, name, getter) {
2630
+ Object.defineProperty(ctx, name, {
2631
+ get: function() {
2632
+ var result = getter.call(this);
2633
+ return result === undefined ? this : result;
2634
+ },
2635
+ configurable: true
2636
+ });
2637
+ };
2638
+
2639
+ }); // module: chai/utils/addProperty.js
2640
+ require.register("chai/utils/eql.js", function(module, exports, require) {
2641
+ // This is (almost) directly from Node.js assert
2642
+ // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
2643
+ module.exports = _deepEqual;
2644
+
2645
+ var getEnumerableProperties = require('./getEnumerableProperties');
2646
+
2647
+ // for the browser
2648
+ var Buffer;
2649
+ try {
2650
+ Buffer = require('buffer').Buffer;
2651
+ } catch (ex) {
2652
+ Buffer = {
2653
+ isBuffer: function() {
2654
+ return false;
2655
+ }
2656
+ };
2657
+ }
2658
+
2659
+ function _deepEqual(actual, expected, memos) {
2660
+
2661
+ // 7.1. All identical values are equivalent, as determined by ===.
2662
+ if (actual === expected) {
2663
+ return true;
2664
+
2665
+ } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
2666
+ if (actual.length != expected.length) return false;
2667
+
2668
+ for (var i = 0; i < actual.length; i++) {
2669
+ if (actual[i] !== expected[i]) return false;
2670
+ }
2671
+
2672
+ return true;
2673
+
2674
+ // 7.2. If the expected value is a Date object, the actual value is
2675
+ // equivalent if it is also a Date object that refers to the same time.
2676
+ } else if (actual instanceof Date && expected instanceof Date) {
2677
+ return actual.getTime() === expected.getTime();
2678
+
2679
+ // 7.3. Other pairs that do not both pass typeof value == 'object',
2680
+ // equivalence is determined by ==.
2681
+ } else if (typeof actual != 'object' && typeof expected != 'object') {
2682
+ return actual === expected;
2683
+
2684
+ // 7.4. For all other Object pairs, including Array objects, equivalence is
2685
+ // determined by having the same number of owned properties (as verified
2686
+ // with Object.prototype.hasOwnProperty.call), the same set of keys
2687
+ // (although not necessarily the same order), equivalent values for every
2688
+ // corresponding key, and an identical 'prototype' property. Note: this
2689
+ // accounts for both named and indexed properties on Arrays.
2690
+ } else {
2691
+ return objEquiv(actual, expected, memos);
2692
+ }
2693
+ }
2694
+
2695
+ function isUndefinedOrNull(value) {
2696
+ return value === null || value === undefined;
2697
+ }
2698
+
2699
+ function isArguments(object) {
2700
+ return Object.prototype.toString.call(object) == '[object Arguments]';
2701
+ }
2702
+
2703
+ function objEquiv(a, b, memos) {
2704
+ if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return false;
2705
+
2706
+ // an identical 'prototype' property.
2707
+ if (a.prototype !== b.prototype) return false;
2708
+
2709
+ // check if we have already compared a and b
2710
+ var i;
2711
+ if (memos) {
2712
+ for (i = 0; i < memos.length; i++) {
2713
+ if ((memos[i][0] === a && memos[i][1] === b) || (memos[i][0] === b && memos[i][1] === a)) return true;
2714
+ }
2715
+ } else {
2716
+ memos = [];
2717
+ }
2718
+
2719
+ //~~~I've managed to break Object.keys through screwy arguments passing.
2720
+ // Converting to array solves the problem.
2721
+ if (isArguments(a)) {
2722
+ if (!isArguments(b)) {
2723
+ return false;
2724
+ }
2725
+ a = pSlice.call(a);
2726
+ b = pSlice.call(b);
2727
+ return _deepEqual(a, b, memos);
2728
+ }
2729
+ try {
2730
+ var ka = getEnumerableProperties(a),
2731
+ kb = getEnumerableProperties(b),
2732
+ key;
2733
+ } catch (e) { //happens when one is a string literal and the other isn't
2734
+ return false;
2735
+ }
2736
+
2737
+ // having the same number of owned properties (keys incorporates
2738
+ // hasOwnProperty)
2739
+ if (ka.length != kb.length) return false;
2740
+
2741
+ //the same set of keys (although not necessarily the same order),
2742
+ ka.sort();
2743
+ kb.sort();
2744
+ //~~~cheap key test
2745
+ for (i = ka.length - 1; i >= 0; i--) {
2746
+ if (ka[i] != kb[i]) return false;
2747
+ }
2748
+
2749
+ // remember objects we have compared to guard against circular references
2750
+ memos.push([a, b]);
2751
+
2752
+ //equivalent values for every corresponding key, and
2753
+ //~~~possibly expensive deep test
2754
+ for (i = ka.length - 1; i >= 0; i--) {
2755
+ key = ka[i];
2756
+ if (!_deepEqual(a[key], b[key], memos)) return false;
2757
+ }
2758
+
2759
+ return true;
2760
+ }
2761
+
2762
+ }); // module: chai/utils/eql.js
2763
+ require.register("chai/utils/flag.js", function(module, exports, require) {
2764
+ /*!
2765
+ * Chai - flag utility
2766
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2767
+ * MIT Licensed
2768
+ */
2769
+
2770
+ /**
2771
+ * ### flag(object ,key, [value])
2772
+ *
2773
+ * Get or set a flag value on an object. If a
2774
+ * value is provided it will be set, else it will
2775
+ * return the currently set value or `undefined` if
2776
+ * the value is not set.
2777
+ *
2778
+ * utils.flag(this, 'foo', 'bar'); // setter
2779
+ * utils.flag(this, 'foo'); // getter, returns `bar`
2780
+ *
2781
+ * @param {Object} object (constructed Assertion
2782
+ * @param {String} key
2783
+ * @param {Mixed} value (optional)
2784
+ * @name flag
2785
+ * @api private
2786
+ */
2787
+
2788
+ module.exports = function(obj, key, value) {
2789
+ var flags = obj.__flags || (obj.__flags = Object.create(null));
2790
+ if (arguments.length === 3) {
2791
+ flags[key] = value;
2792
+ } else {
2793
+ return flags[key];
2794
+ }
2795
+ };
2796
+
2797
+ }); // module: chai/utils/flag.js
2798
+ require.register("chai/utils/getActual.js", function(module, exports, require) {
2799
+ /*!
2800
+ * Chai - getActual utility
2801
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2802
+ * MIT Licensed
2803
+ */
2804
+
2805
+ /**
2806
+ * # getActual(object, [actual])
2807
+ *
2808
+ * Returns the `actual` value for an Assertion
2809
+ *
2810
+ * @param {Object} object (constructed Assertion)
2811
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
2812
+ */
2813
+
2814
+ module.exports = function(obj, args) {
2815
+ var actual = args[4];
2816
+ return 'undefined' !== typeof actual ? actual : obj._obj;
2817
+ };
2818
+
2819
+ }); // module: chai/utils/getActual.js
2820
+ require.register("chai/utils/getEnumerableProperties.js", function(module, exports, require) {
2821
+ /*!
2822
+ * Chai - getEnumerableProperties utility
2823
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2824
+ * MIT Licensed
2825
+ */
2826
+
2827
+ /**
2828
+ * ### .getEnumerableProperties(object)
2829
+ *
2830
+ * This allows the retrieval of enumerable property names of an object,
2831
+ * inherited or not.
2832
+ *
2833
+ * @param {Object} object
2834
+ * @returns {Array}
2835
+ * @name getEnumerableProperties
2836
+ * @api public
2837
+ */
2838
+
2839
+ module.exports = function getEnumerableProperties(object) {
2840
+ var result = [];
2841
+ for (var name in object) {
2842
+ result.push(name);
2843
+ }
2844
+ return result;
2845
+ };
2846
+
2847
+ }); // module: chai/utils/getEnumerableProperties.js
2848
+ require.register("chai/utils/getMessage.js", function(module, exports, require) {
2849
+ /*!
2850
+ * Chai - message composition utility
2851
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2852
+ * MIT Licensed
2853
+ */
2854
+
2855
+ /*!
2856
+ * Module dependancies
2857
+ */
2858
+
2859
+ var flag = require('./flag'),
2860
+ getActual = require('./getActual'),
2861
+ inspect = require('./inspect'),
2862
+ objDisplay = require('./objDisplay');
2863
+
2864
+ /**
2865
+ * ### .getMessage(object, message, negateMessage)
2866
+ *
2867
+ * Construct the error message based on flags
2868
+ * and template tags. Template tags will return
2869
+ * a stringified inspection of the object referenced.
2870
+ *
2871
+ * Messsage template tags:
2872
+ * - `#{this}` current asserted object
2873
+ * - `#{act}` actual value
2874
+ * - `#{exp}` expected value
2875
+ *
2876
+ * @param {Object} object (constructed Assertion)
2877
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
2878
+ * @name getMessage
2879
+ * @api public
2880
+ */
2881
+
2882
+ module.exports = function(obj, args) {
2883
+ var negate = flag(obj, 'negate'),
2884
+ val = flag(obj, 'object'),
2885
+ expected = args[3],
2886
+ actual = getActual(obj, args),
2887
+ msg = negate ? args[2] : args[1],
2888
+ flagMsg = flag(obj, 'message');
2889
+
2890
+ msg = msg || '';
2891
+ msg = msg.replace(/#{this}/g, objDisplay(val)).replace(/#{act}/g, objDisplay(actual)).replace(/#{exp}/g, objDisplay(expected));
2892
+
2893
+ return flagMsg ? flagMsg + ': ' + msg : msg;
2894
+ };
2895
+
2896
+ }); // module: chai/utils/getMessage.js
2897
+ require.register("chai/utils/getName.js", function(module, exports, require) {
2898
+ /*!
2899
+ * Chai - getName utility
2900
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2901
+ * MIT Licensed
2902
+ */
2903
+
2904
+ /**
2905
+ * # getName(func)
2906
+ *
2907
+ * Gets the name of a function, in a cross-browser way.
2908
+ *
2909
+ * @param {Function} a function (usually a constructor)
2910
+ */
2911
+
2912
+ module.exports = function(func) {
2913
+ if (func.name) return func.name;
2914
+
2915
+ var match = /^\s?function ([^(]*)\(/.exec(func);
2916
+ return match && match[1] ? match[1] : "";
2917
+ };
2918
+
2919
+ }); // module: chai/utils/getName.js
2920
+ require.register("chai/utils/getPathValue.js", function(module, exports, require) {
2921
+ /*!
2922
+ * Chai - getPathValue utility
2923
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2924
+ * @see https://github.com/logicalparadox/filtr
2925
+ * MIT Licensed
2926
+ */
2927
+
2928
+ /**
2929
+ * ### .getPathValue(path, object)
2930
+ *
2931
+ * This allows the retrieval of values in an
2932
+ * object given a string path.
2933
+ *
2934
+ * var obj = {
2935
+ * prop1: {
2936
+ * arr: ['a', 'b', 'c']
2937
+ * , str: 'Hello'
2938
+ * }
2939
+ * , prop2: {
2940
+ * arr: [ { nested: 'Universe' } ]
2941
+ * , str: 'Hello again!'
2942
+ * }
2943
+ * }
2944
+ *
2945
+ * The following would be the results.
2946
+ *
2947
+ * getPathValue('prop1.str', obj); // Hello
2948
+ * getPathValue('prop1.att[2]', obj); // b
2949
+ * getPathValue('prop2.arr[0].nested', obj); // Universe
2950
+ *
2951
+ * @param {String} path
2952
+ * @param {Object} object
2953
+ * @returns {Object} value or `undefined`
2954
+ * @name getPathValue
2955
+ * @api public
2956
+ */
2957
+
2958
+ var getPathValue = module.exports = function(path, obj) {
2959
+ var parsed = parsePath(path);
2960
+ return _getPathValue(parsed, obj);
2961
+ };
2962
+
2963
+ /*!
2964
+ * ## parsePath(path)
2965
+ *
2966
+ * Helper function used to parse string object
2967
+ * paths. Use in conjunction with `_getPathValue`.
2968
+ *
2969
+ * var parsed = parsePath('myobject.property.subprop');
2970
+ *
2971
+ * ### Paths:
2972
+ *
2973
+ * * Can be as near infinitely deep and nested
2974
+ * * Arrays are also valid using the formal `myobject.document[3].property`.
2975
+ *
2976
+ * @param {String} path
2977
+ * @returns {Object} parsed
2978
+ * @api private
2979
+ */
2980
+
2981
+ function parsePath(path) {
2982
+ var str = path.replace(/\[/g, '.['),
2983
+ parts = str.match(/(\\\.|[^.]+?)+/g);
2984
+ return parts.map(function(value) {
2985
+ var re = /\[(\d+)\]$/,
2986
+ mArr = re.exec(value)
2987
+ if (mArr) return {
2988
+ i: parseFloat(mArr[1])
2989
+ };
2990
+ else return {
2991
+ p: value
2992
+ };
2993
+ });
2994
+ };
2995
+
2996
+ /*!
2997
+ * ## _getPathValue(parsed, obj)
2998
+ *
2999
+ * Helper companion function for `.parsePath` that returns
3000
+ * the value located at the parsed address.
3001
+ *
3002
+ * var value = getPathValue(parsed, obj);
3003
+ *
3004
+ * @param {Object} parsed definition from `parsePath`.
3005
+ * @param {Object} object to search against
3006
+ * @returns {Object|Undefined} value
3007
+ * @api private
3008
+ */
3009
+
3010
+ function _getPathValue(parsed, obj) {
3011
+ var tmp = obj,
3012
+ res;
3013
+ for (var i = 0, l = parsed.length; i < l; i++) {
3014
+ var part = parsed[i];
3015
+ if (tmp) {
3016
+ if ('undefined' !== typeof part.p) tmp = tmp[part.p];
3017
+ else if ('undefined' !== typeof part.i) tmp = tmp[part.i];
3018
+ if (i == (l - 1)) res = tmp;
3019
+ } else {
3020
+ res = undefined;
3021
+ }
3022
+ }
3023
+ return res;
3024
+ };
3025
+
3026
+ }); // module: chai/utils/getPathValue.js
3027
+ require.register("chai/utils/getProperties.js", function(module, exports, require) {
3028
+ /*!
3029
+ * Chai - getProperties utility
3030
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3031
+ * MIT Licensed
3032
+ */
3033
+
3034
+ /**
3035
+ * ### .getProperties(object)
3036
+ *
3037
+ * This allows the retrieval of property names of an object, enumerable or not,
3038
+ * inherited or not.
3039
+ *
3040
+ * @param {Object} object
3041
+ * @returns {Array}
3042
+ * @name getProperties
3043
+ * @api public
3044
+ */
3045
+
3046
+ module.exports = function getProperties(object) {
3047
+ var result = Object.getOwnPropertyNames(subject);
3048
+
3049
+ function addProperty(property) {
3050
+ if (result.indexOf(property) === -1) {
3051
+ result.push(property);
3052
+ }
3053
+ }
3054
+
3055
+ var proto = Object.getPrototypeOf(subject);
3056
+ while (proto !== null) {
3057
+ Object.getOwnPropertyNames(proto).forEach(addProperty);
3058
+ proto = Object.getPrototypeOf(proto);
3059
+ }
3060
+
3061
+ return result;
3062
+ };
3063
+
3064
+ }); // module: chai/utils/getProperties.js
3065
+ require.register("chai/utils/index.js", function(module, exports, require) {
3066
+ /*!
3067
+ * chai
3068
+ * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
3069
+ * MIT Licensed
3070
+ */
3071
+
3072
+ /*!
3073
+ * Main exports
3074
+ */
3075
+
3076
+ var exports = module.exports = {};
3077
+
3078
+ /*!
3079
+ * test utility
3080
+ */
3081
+
3082
+ exports.test = require('./test');
3083
+
3084
+ /*!
3085
+ * type utility
3086
+ */
3087
+
3088
+ exports.type = require('./type');
3089
+
3090
+ /*!
3091
+ * message utility
3092
+ */
3093
+
3094
+ exports.getMessage = require('./getMessage');
3095
+
3096
+ /*!
3097
+ * actual utility
3098
+ */
3099
+
3100
+ exports.getActual = require('./getActual');
3101
+
3102
+ /*!
3103
+ * Inspect util
3104
+ */
3105
+
3106
+ exports.inspect = require('./inspect');
3107
+
3108
+ /*!
3109
+ * Object Display util
3110
+ */
3111
+
3112
+ exports.objDisplay = require('./objDisplay');
3113
+
3114
+ /*!
3115
+ * Flag utility
3116
+ */
3117
+
3118
+ exports.flag = require('./flag');
3119
+
3120
+ /*!
3121
+ * Flag transferring utility
3122
+ */
3123
+
3124
+ exports.transferFlags = require('./transferFlags');
3125
+
3126
+ /*!
3127
+ * Deep equal utility
3128
+ */
3129
+
3130
+ exports.eql = require('./eql');
3131
+
3132
+ /*!
3133
+ * Deep path value
3134
+ */
3135
+
3136
+ exports.getPathValue = require('./getPathValue');
3137
+
3138
+ /*!
3139
+ * Function name
3140
+ */
3141
+
3142
+ exports.getName = require('./getName');
3143
+
3144
+ /*!
3145
+ * add Property
3146
+ */
3147
+
3148
+ exports.addProperty = require('./addProperty');
3149
+
3150
+ /*!
3151
+ * add Method
3152
+ */
3153
+
3154
+ exports.addMethod = require('./addMethod');
3155
+
3156
+ /*!
3157
+ * overwrite Property
3158
+ */
3159
+
3160
+ exports.overwriteProperty = require('./overwriteProperty');
3161
+
3162
+ /*!
3163
+ * overwrite Method
3164
+ */
3165
+
3166
+ exports.overwriteMethod = require('./overwriteMethod');
3167
+
3168
+ /*!
3169
+ * Add a chainable method
3170
+ */
3171
+
3172
+ exports.addChainableMethod = require('./addChainableMethod');
3173
+
3174
+
3175
+ }); // module: chai/utils/index.js
3176
+ require.register("chai/utils/inspect.js", function(module, exports, require) {
3177
+ // This is (almost) directly from Node.js utils
3178
+ // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
3179
+ var getName = require('./getName');
3180
+ var getProperties = require('./getProperties');
3181
+ var getEnumerableProperties = require('./getEnumerableProperties');
3182
+
3183
+ module.exports = inspect;
3184
+
3185
+ /**
3186
+ * Echos the value of a value. Trys to print the value out
3187
+ * in the best way possible given the different types.
3188
+ *
3189
+ * @param {Object} obj The object to print out.
3190
+ * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
3191
+ * properties of objects.
3192
+ * @param {Number} depth Depth in which to descend in object. Default is 2.
3193
+ * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
3194
+ * output. Default is false (no coloring).
3195
+ */
3196
+ function inspect(obj, showHidden, depth, colors) {
3197
+ var ctx = {
3198
+ showHidden: showHidden,
3199
+ seen: [],
3200
+ stylize: function(str) {
3201
+ return str;
3202
+ }
3203
+ };
3204
+ return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
3205
+ }
3206
+
3207
+ // https://gist.github.com/1044128/
3208
+ var getOuterHTML = function(element) {
3209
+ if ('outerHTML' in element) return element.outerHTML;
3210
+ var ns = "http://www.w3.org/1999/xhtml";
3211
+ var container = document.createElementNS(ns, '_');
3212
+ var elemProto = (window.HTMLElement || window.Element).prototype;
3213
+ var xmlSerializer = new XMLSerializer();
3214
+ var html;
3215
+ if (document.xmlVersion) {
3216
+ return xmlSerializer.serializeToString(element);
3217
+ } else {
3218
+ container.appendChild(element.cloneNode(false));
3219
+ html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
3220
+ container.innerHTML = '';
3221
+ return html;
3222
+ }
3223
+ };
3224
+
3225
+ // Returns true if object is a DOM element.
3226
+ var isDOMElement = function(object) {
3227
+ if (typeof HTMLElement === 'object') {
3228
+ return object instanceof HTMLElement;
3229
+ } else {
3230
+ return object && typeof object === 'object' && object.nodeType === 1 && typeof object.nodeName === 'string';
3231
+ }
3232
+ };
3233
+
3234
+ function formatValue(ctx, value, recurseTimes) {
3235
+ // Provide a hook for user-specified inspect functions.
3236
+ // Check that value is an object with an inspect function on it
3237
+ if (value && typeof value.inspect === 'function' &&
3238
+ // Filter out the util module, it's inspect function is special
3239
+ value.inspect !== exports.inspect &&
3240
+ // Also filter out any prototype objects using the circular check.
3241
+ !(value.constructor && value.constructor.prototype === value)) {
3242
+ return value.inspect(recurseTimes);
3243
+ }
3244
+
3245
+ // Primitive types cannot have properties
3246
+ var primitive = formatPrimitive(ctx, value);
3247
+ if (primitive) {
3248
+ return primitive;
3249
+ }
3250
+
3251
+ // If it's DOM elem, get outer HTML.
3252
+ if (isDOMElement(value)) {
3253
+ return getOuterHTML(value);
3254
+ }
3255
+
3256
+ // Look up the keys of the object.
3257
+ var visibleKeys = getEnumerableProperties(value);
3258
+ var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
3259
+
3260
+ // Some type of object without properties can be shortcutted.
3261
+ // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
3262
+ // a `stack` plus `description` property; ignore those for consistency.
3263
+ if (keys.length === 0 || (isError(value) && (
3264
+ (keys.length === 1 && keys[0] === 'stack') || (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')))) {
3265
+ if (typeof value === 'function') {
3266
+ var name = getName(value);
3267
+ var nameSuffix = name ? ': ' + name : '';
3268
+ return ctx.stylize('[Function' + nameSuffix + ']', 'special');
3269
+ }
3270
+ if (isRegExp(value)) {
3271
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3272
+ }
3273
+ if (isDate(value)) {
3274
+ return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
3275
+ }
3276
+ if (isError(value)) {
3277
+ return formatError(value);
3278
+ }
3279
+ }
3280
+
3281
+ var base = '',
3282
+ array = false,
3283
+ braces = ['{', '}'];
3284
+
3285
+ // Make Array say that they are Array
3286
+ if (isArray(value)) {
3287
+ array = true;
3288
+ braces = ['[', ']'];
3289
+ }
3290
+
3291
+ // Make functions say that they are functions
3292
+ if (typeof value === 'function') {
3293
+ var name = getName(value);
3294
+ var nameSuffix = name ? ': ' + name : '';
3295
+ base = ' [Function' + nameSuffix + ']';
3296
+ }
3297
+
3298
+ // Make RegExps say that they are RegExps
3299
+ if (isRegExp(value)) {
3300
+ base = ' ' + RegExp.prototype.toString.call(value);
3301
+ }
3302
+
3303
+ // Make dates with properties first say the date
3304
+ if (isDate(value)) {
3305
+ base = ' ' + Date.prototype.toUTCString.call(value);
3306
+ }
3307
+
3308
+ // Make error with message first say the error
3309
+ if (isError(value)) {
3310
+ return formatError(value);
3311
+ }
3312
+
3313
+ if (keys.length === 0 && (!array || value.length == 0)) {
3314
+ return braces[0] + base + braces[1];
3315
+ }
3316
+
3317
+ if (recurseTimes < 0) {
3318
+ if (isRegExp(value)) {
3319
+ return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3320
+ } else {
3321
+ return ctx.stylize('[Object]', 'special');
3322
+ }
3323
+ }
3324
+
3325
+ ctx.seen.push(value);
3326
+
3327
+ var output;
3328
+ if (array) {
3329
+ output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
3330
+ } else {
3331
+ output = keys.map(function(key) {
3332
+ return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
3333
+ });
3334
+ }
3335
+
3336
+ ctx.seen.pop();
3337
+
3338
+ return reduceToSingleString(output, base, braces);
3339
+ }
3340
+
3341
+
3342
+ function formatPrimitive(ctx, value) {
3343
+ switch (typeof value) {
3344
+ case 'undefined':
3345
+ return ctx.stylize('undefined', 'undefined');
3346
+
3347
+ case 'string':
3348
+ var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
3349
+ return ctx.stylize(simple, 'string');
3350
+
3351
+ case 'number':
3352
+ return ctx.stylize('' + value, 'number');
3353
+
3354
+ case 'boolean':
3355
+ return ctx.stylize('' + value, 'boolean');
3356
+ }
3357
+ // For some reason typeof null is "object", so special case here.
3358
+ if (value === null) {
3359
+ return ctx.stylize('null', 'null');
3360
+ }
3361
+ }
3362
+
3363
+
3364
+ function formatError(value) {
3365
+ return '[' + Error.prototype.toString.call(value) + ']';
3366
+ }
3367
+
3368
+
3369
+ function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
3370
+ var output = [];
3371
+ for (var i = 0, l = value.length; i < l; ++i) {
3372
+ if (Object.prototype.hasOwnProperty.call(value, String(i))) {
3373
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
3374
+ } else {
3375
+ output.push('');
3376
+ }
3377
+ }
3378
+ keys.forEach(function(key) {
3379
+ if (!key.match(/^\d+$/)) {
3380
+ output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
3381
+ }
3382
+ });
3383
+ return output;
3384
+ }
3385
+
3386
+
3387
+ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3388
+ var name, str;
3389
+ if (value.__lookupGetter__) {
3390
+ if (value.__lookupGetter__(key)) {
3391
+ if (value.__lookupSetter__(key)) {
3392
+ str = ctx.stylize('[Getter/Setter]', 'special');
3393
+ } else {
3394
+ str = ctx.stylize('[Getter]', 'special');
3395
+ }
3396
+ } else {
3397
+ if (value.__lookupSetter__(key)) {
3398
+ str = ctx.stylize('[Setter]', 'special');
3399
+ }
3400
+ }
3401
+ }
3402
+ if (visibleKeys.indexOf(key) < 0) {
3403
+ name = '[' + key + ']';
3404
+ }
3405
+ if (!str) {
3406
+ if (ctx.seen.indexOf(value[key]) < 0) {
3407
+ if (recurseTimes === null) {
3408
+ str = formatValue(ctx, value[key], null);
3409
+ } else {
3410
+ str = formatValue(ctx, value[key], recurseTimes - 1);
3411
+ }
3412
+ if (str.indexOf('\n') > -1) {
3413
+ if (array) {
3414
+ str = str.split('\n').map(function(line) {
3415
+ return ' ' + line;
3416
+ }).join('\n').substr(2);
3417
+ } else {
3418
+ str = '\n' + str.split('\n').map(function(line) {
3419
+ return ' ' + line;
3420
+ }).join('\n');
3421
+ }
3422
+ }
3423
+ } else {
3424
+ str = ctx.stylize('[Circular]', 'special');
3425
+ }
3426
+ }
3427
+ if (typeof name === 'undefined') {
3428
+ if (array && key.match(/^\d+$/)) {
3429
+ return str;
3430
+ }
3431
+ name = JSON.stringify('' + key);
3432
+ if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
3433
+ name = name.substr(1, name.length - 2);
3434
+ name = ctx.stylize(name, 'name');
3435
+ } else {
3436
+ name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
3437
+ name = ctx.stylize(name, 'string');
3438
+ }
3439
+ }
3440
+
3441
+ return name + ': ' + str;
3442
+ }
3443
+
3444
+
3445
+ function reduceToSingleString(output, base, braces) {
3446
+ var numLinesEst = 0;
3447
+ var length = output.reduce(function(prev, cur) {
3448
+ numLinesEst++;
3449
+ if (cur.indexOf('\n') >= 0) numLinesEst++;
3450
+ return prev + cur.length + 1;
3451
+ }, 0);
3452
+
3453
+ if (length > 60) {
3454
+ return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
3455
+ }
3456
+
3457
+ return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
3458
+ }
3459
+
3460
+ function isArray(ar) {
3461
+ return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
3462
+ }
3463
+
3464
+ function isRegExp(re) {
3465
+ return typeof re === 'object' && objectToString(re) === '[object RegExp]';
3466
+ }
3467
+
3468
+ function isDate(d) {
3469
+ return typeof d === 'object' && objectToString(d) === '[object Date]';
3470
+ }
3471
+
3472
+ function isError(e) {
3473
+ return typeof e === 'object' && objectToString(e) === '[object Error]';
3474
+ }
3475
+
3476
+ function objectToString(o) {
3477
+ return Object.prototype.toString.call(o);
3478
+ }
3479
+
3480
+ }); // module: chai/utils/inspect.js
3481
+ require.register("chai/utils/objDisplay.js", function(module, exports, require) {
3482
+ /*!
3483
+ * Chai - flag utility
3484
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3485
+ * MIT Licensed
3486
+ */
3487
+
3488
+ /*!
3489
+ * Module dependancies
3490
+ */
3491
+
3492
+ var inspect = require('./inspect');
3493
+
3494
+ /**
3495
+ * ### .objDisplay (object)
3496
+ *
3497
+ * Determines if an object or an array matches
3498
+ * criteria to be inspected in-line for error
3499
+ * messages or should be truncated.
3500
+ *
3501
+ * @param {Mixed} javascript object to inspect
3502
+ * @name objDisplay
3503
+ * @api public
3504
+ */
3505
+
3506
+ module.exports = function(obj) {
3507
+ var str = inspect(obj),
3508
+ type = Object.prototype.toString.call(obj);
3509
+
3510
+ if (str.length >= 40) {
3511
+ if (type === '[object Function]') {
3512
+ return !obj.name || obj.name === '' ? '[Function]' : '[Function: ' + obj.name + ']';
3513
+ } else if (type === '[object Array]') {
3514
+ return '[ Array(' + obj.length + ') ]';
3515
+ } else if (type === '[object Object]') {
3516
+ var keys = Object.keys(obj),
3517
+ kstr = keys.length > 2 ? keys.splice(0, 2).join(', ') + ', ...' : keys.join(', ');
3518
+ return '{ Object (' + kstr + ') }';
3519
+ } else {
3520
+ return str;
3521
+ }
3522
+ } else {
3523
+ return str;
3524
+ }
3525
+ };
3526
+
3527
+ }); // module: chai/utils/objDisplay.js
3528
+ require.register("chai/utils/overwriteMethod.js", function(module, exports, require) {
3529
+ /*!
3530
+ * Chai - overwriteMethod utility
3531
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3532
+ * MIT Licensed
3533
+ */
3534
+
3535
+ /**
3536
+ * ### overwriteMethod (ctx, name, fn)
3537
+ *
3538
+ * Overwites an already existing method and provides
3539
+ * access to previous function. Must return function
3540
+ * to be used for name.
3541
+ *
3542
+ * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
3543
+ * return function (str) {
3544
+ * var obj = utils.flag(this, 'object');
3545
+ * if (obj instanceof Foo) {
3546
+ * new chai.Assertion(obj.value).to.equal(str);
3547
+ * } else {
3548
+ * _super.apply(this, arguments);
3549
+ * }
3550
+ * }
3551
+ * });
3552
+ *
3553
+ * Can also be accessed directly from `chai.Assertion`.
3554
+ *
3555
+ * chai.Assertion.overwriteMethod('foo', fn);
3556
+ *
3557
+ * Then can be used as any other assertion.
3558
+ *
3559
+ * expect(myFoo).to.equal('bar');
3560
+ *
3561
+ * @param {Object} ctx object whose method is to be overwritten
3562
+ * @param {String} name of method to overwrite
3563
+ * @param {Function} method function that returns a function to be used for name
3564
+ * @name overwriteMethod
3565
+ * @api public
3566
+ */
3567
+
3568
+ module.exports = function(ctx, name, method) {
3569
+ var _method = ctx[name],
3570
+ _super = function() {
3571
+ return this;
3572
+ };
3573
+
3574
+ if (_method && 'function' === typeof _method) _super = _method;
3575
+
3576
+ ctx[name] = function() {
3577
+ var result = method(_super).apply(this, arguments);
3578
+ return result === undefined ? this : result;
3579
+ }
3580
+ };
3581
+
3582
+ }); // module: chai/utils/overwriteMethod.js
3583
+ require.register("chai/utils/overwriteProperty.js", function(module, exports, require) {
3584
+ /*!
3585
+ * Chai - overwriteProperty utility
3586
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3587
+ * MIT Licensed
3588
+ */
3589
+
3590
+ /**
3591
+ * ### overwriteProperty (ctx, name, fn)
3592
+ *
3593
+ * Overwites an already existing property getter and provides
3594
+ * access to previous value. Must return function to use as getter.
3595
+ *
3596
+ * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
3597
+ * return function () {
3598
+ * var obj = utils.flag(this, 'object');
3599
+ * if (obj instanceof Foo) {
3600
+ * new chai.Assertion(obj.name).to.equal('bar');
3601
+ * } else {
3602
+ * _super.call(this);
3603
+ * }
3604
+ * }
3605
+ * });
3606
+ *
3607
+ *
3608
+ * Can also be accessed directly from `chai.Assertion`.
3609
+ *
3610
+ * chai.Assertion.overwriteProperty('foo', fn);
3611
+ *
3612
+ * Then can be used as any other assertion.
3613
+ *
3614
+ * expect(myFoo).to.be.ok;
3615
+ *
3616
+ * @param {Object} ctx object whose property is to be overwritten
3617
+ * @param {String} name of property to overwrite
3618
+ * @param {Function} getter function that returns a getter function to be used for name
3619
+ * @name overwriteProperty
3620
+ * @api public
3621
+ */
3622
+
3623
+ module.exports = function(ctx, name, getter) {
3624
+ var _get = Object.getOwnPropertyDescriptor(ctx, name),
3625
+ _super = function() {};
3626
+
3627
+ if (_get && 'function' === typeof _get.get) _super = _get.get
3628
+
3629
+ Object.defineProperty(ctx, name, {
3630
+ get: function() {
3631
+ var result = getter(_super).call(this);
3632
+ return result === undefined ? this : result;
3633
+ },
3634
+ configurable: true
3635
+ });
3636
+ };
3637
+
3638
+ }); // module: chai/utils/overwriteProperty.js
3639
+ require.register("chai/utils/test.js", function(module, exports, require) {
3640
+ /*!
3641
+ * Chai - test utility
3642
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3643
+ * MIT Licensed
3644
+ */
3645
+
3646
+ /*!
3647
+ * Module dependancies
3648
+ */
3649
+
3650
+ var flag = require('./flag');
3651
+
3652
+ /**
3653
+ * # test(object, expression)
3654
+ *
3655
+ * Test and object for expression.
3656
+ *
3657
+ * @param {Object} object (constructed Assertion)
3658
+ * @param {Arguments} chai.Assertion.prototype.assert arguments
3659
+ */
3660
+
3661
+ module.exports = function(obj, args) {
3662
+ var negate = flag(obj, 'negate'),
3663
+ expr = args[0];
3664
+ return negate ? !expr : expr;
3665
+ };
3666
+
3667
+ }); // module: chai/utils/test.js
3668
+ require.register("chai/utils/transferFlags.js", function(module, exports, require) {
3669
+ /*!
3670
+ * Chai - transferFlags utility
3671
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3672
+ * MIT Licensed
3673
+ */
3674
+
3675
+ /**
3676
+ * ### transferFlags(assertion, object, includeAll = true)
3677
+ *
3678
+ * Transfer all the flags for `assertion` to `object`. If
3679
+ * `includeAll` is set to `false`, then the base Chai
3680
+ * assertion flags (namely `object`, `ssfi`, and `message`)
3681
+ * will not be transferred.
3682
+ *
3683
+ *
3684
+ * var newAssertion = new Assertion();
3685
+ * utils.transferFlags(assertion, newAssertion);
3686
+ *
3687
+ * var anotherAsseriton = new Assertion(myObj);
3688
+ * utils.transferFlags(assertion, anotherAssertion, false);
3689
+ *
3690
+ * @param {Assertion} assertion the assertion to transfer the flags from
3691
+ * @param {Object} object the object to transfer the flags too; usually a new assertion
3692
+ * @param {Boolean} includeAll
3693
+ * @name getAllFlags
3694
+ * @api private
3695
+ */
3696
+
3697
+ module.exports = function(assertion, object, includeAll) {
3698
+ var flags = assertion.__flags || (assertion.__flags = Object.create(null));
3699
+
3700
+ if (!object.__flags) {
3701
+ object.__flags = Object.create(null);
3702
+ }
3703
+
3704
+ includeAll = arguments.length === 3 ? includeAll : true;
3705
+
3706
+ for (var flag in flags) {
3707
+ if (includeAll || (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
3708
+ object.__flags[flag] = flags[flag];
3709
+ }
3710
+ }
3711
+ };
3712
+
3713
+ }); // module: chai/utils/transferFlags.js
3714
+ require.register("chai/utils/type.js", function(module, exports, require) {
3715
+ /*!
3716
+ * Chai - type utility
3717
+ * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3718
+ * MIT Licensed
3719
+ */
3720
+
3721
+ /*!
3722
+ * Detectable javascript natives
3723
+ */
3724
+
3725
+ var natives = {
3726
+ '[object Arguments]': 'arguments',
3727
+ '[object Array]': 'array',
3728
+ '[object Date]': 'date',
3729
+ '[object Function]': 'function',
3730
+ '[object Number]': 'number',
3731
+ '[object RegExp]': 'regexp',
3732
+ '[object String]': 'string'
3733
+ };
3734
+
3735
+ /**
3736
+ * ### type(object)
3737
+ *
3738
+ * Better implementation of `typeof` detection that can
3739
+ * be used cross-browser. Handles the inconsistencies of
3740
+ * Array, `null`, and `undefined` detection.
3741
+ *
3742
+ * utils.type({}) // 'object'
3743
+ * utils.type(null) // `null'
3744
+ * utils.type(undefined) // `undefined`
3745
+ * utils.type([]) // `array`
3746
+ *
3747
+ * @param {Mixed} object to detect type of
3748
+ * @name type
3749
+ * @api private
3750
+ */
3751
+
3752
+ module.exports = function(obj) {
3753
+ var str = Object.prototype.toString.call(obj);
3754
+ if (natives[str]) return natives[str];
3755
+ if (obj === null) return 'null';
3756
+ if (obj === undefined) return 'undefined';
3757
+ if (obj === Object(obj)) return 'object';
3758
+ return typeof obj;
3759
+ };
3760
+
3761
+ }); // module: chai/utils/type.js
3762
+ require.alias("./chai.js", "chai");
3763
+
3764
+ return require('chai');
3765
+ });