konacha 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,11 +79,19 @@ require.register("assertion.js", function(module, exports, require){
79
79
  * #### Differences
80
80
  *
81
81
  * The `expect` interface provides a function as a starting point for chaining
82
- * your language assertions. It works on both node.js and in the browser.
82
+ * your language assertions. It works on node.js and in all browsers.
83
83
  *
84
84
  * The `should` interface extends `Object.prototype` to provide a single getter as
85
- * the starting point for your language assertions. Most browser don't like
86
- * extensions to `Object.prototype` so it is not recommended for browser use.
85
+ * the starting point for your language assertions. It works on node.js and in
86
+ * all browsers except Internet Explorer.
87
+ *
88
+ * #### Configuration
89
+ *
90
+ * By default, Chai does not show stack traces upon an AssertionError. This can
91
+ * be changed by modifying the `includeStack` parameter for chai.Assertion. For example:
92
+ *
93
+ * var chai = require('chai');
94
+ * chai.Assertion.includeStack = true; // defaults to false
87
95
  */
88
96
 
89
97
  /*!
@@ -92,6 +100,7 @@ require.register("assertion.js", function(module, exports, require){
92
100
 
93
101
  var AssertionError = require('./error')
94
102
  , eql = require('./utils/eql')
103
+ , toString = Object.prototype.toString
95
104
  , inspect = require('./utils/inspect');
96
105
 
97
106
  /*!
@@ -100,6 +109,7 @@ var AssertionError = require('./error')
100
109
 
101
110
  module.exports = Assertion;
102
111
 
112
+
103
113
  /*!
104
114
  * # Assertion Constructor
105
115
  *
@@ -114,6 +124,21 @@ function Assertion (obj, msg, stack) {
114
124
  this.msg = msg;
115
125
  }
116
126
 
127
+ /*!
128
+ * ## Assertion.includeStack
129
+ * , toString = Object.prototype.toString
130
+ *
131
+ * User configurable property, influences whether stack trace
132
+ * is included in Assertion error message. Default of false
133
+ * suppresses stack trace in the error message
134
+ *
135
+ * Assertion.includeStack = true; // enable stack on error
136
+ *
137
+ * @api public
138
+ */
139
+
140
+ Assertion.includeStack = false;
141
+
117
142
  /*!
118
143
  * # .assert(expression, message, negateMessage)
119
144
  *
@@ -123,18 +148,22 @@ function Assertion (obj, msg, stack) {
123
148
  * @param {Philosophical} expression to be tested
124
149
  * @param {String} message to display if fails
125
150
  * @param {String} negatedMessage to display if negated expression fails
126
- * @api privage
151
+ * @api private
127
152
  */
128
153
 
129
- Assertion.prototype.assert = function (expr, msg, negateMsg) {
154
+ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, actual) {
155
+ actual = actual || this.obj;
130
156
  var msg = (this.negate ? negateMsg : msg)
131
- , ok = this.negate ? !expr : expr;
157
+ , ok = this.negate ? !expr : expr
158
+ , act = this.negate ? expected : actual
159
+ , exp = this.negate ? actual : expected;
132
160
 
133
161
  if (!ok) {
134
162
  throw new AssertionError({
135
- operator: this.msg,
136
- message: msg,
137
- stackStartFunction: this.ssfi
163
+ message: this.msg ? this.msg + ': ' + msg : msg // include custom message if available
164
+ , actual: act
165
+ , expected: exp
166
+ , stackStartFunction: (Assertion.includeStack) ? this.assert : this.ssfi
138
167
  });
139
168
  }
140
169
  };
@@ -151,8 +180,8 @@ Assertion.prototype.assert = function (expr, msg, negateMsg) {
151
180
  Object.defineProperty(Assertion.prototype, 'inspect',
152
181
  { get: function () {
153
182
  return inspect(this.obj);
154
- },
155
- configurable: true
183
+ }
184
+ , configurable: true
156
185
  });
157
186
 
158
187
  /**
@@ -167,8 +196,8 @@ Object.defineProperty(Assertion.prototype, 'inspect',
167
196
  Object.defineProperty(Assertion.prototype, 'to',
168
197
  { get: function () {
169
198
  return this;
170
- },
171
- configurable: true
199
+ }
200
+ , configurable: true
172
201
  });
173
202
 
174
203
  /**
@@ -183,8 +212,8 @@ Object.defineProperty(Assertion.prototype, 'to',
183
212
  Object.defineProperty(Assertion.prototype, 'be',
184
213
  { get: function () {
185
214
  return this;
186
- },
187
- configurable: true
215
+ }
216
+ , configurable: true
188
217
  });
189
218
 
190
219
  /**
@@ -201,8 +230,8 @@ Object.defineProperty(Assertion.prototype, 'been',
201
230
  { get: function () {
202
231
  this.tense = 'past';
203
232
  return this;
204
- },
205
- configurable: true
233
+ }
234
+ , configurable: true
206
235
  });
207
236
 
208
237
  /**
@@ -217,8 +246,8 @@ Object.defineProperty(Assertion.prototype, 'been',
217
246
  Object.defineProperty(Assertion.prototype, 'an',
218
247
  { get: function () {
219
248
  return this;
220
- },
221
- configurable: true
249
+ }
250
+ , configurable: true
222
251
  });
223
252
  /**
224
253
  * # is
@@ -232,8 +261,8 @@ Object.defineProperty(Assertion.prototype, 'an',
232
261
  Object.defineProperty(Assertion.prototype, 'is',
233
262
  { get: function () {
234
263
  return this;
235
- },
236
- configurable: true
264
+ }
265
+ , configurable: true
237
266
  });
238
267
 
239
268
  /**
@@ -248,8 +277,8 @@ Object.defineProperty(Assertion.prototype, 'is',
248
277
  Object.defineProperty(Assertion.prototype, 'and',
249
278
  { get: function () {
250
279
  return this;
251
- },
252
- configurable: true
280
+ }
281
+ , configurable: true
253
282
  });
254
283
 
255
284
  /**
@@ -264,8 +293,8 @@ Object.defineProperty(Assertion.prototype, 'and',
264
293
  Object.defineProperty(Assertion.prototype, 'have',
265
294
  { get: function () {
266
295
  return this;
267
- },
268
- configurable: true
296
+ }
297
+ , configurable: true
269
298
  });
270
299
 
271
300
  /**
@@ -280,8 +309,8 @@ Object.defineProperty(Assertion.prototype, 'have',
280
309
  Object.defineProperty(Assertion.prototype, 'with',
281
310
  { get: function () {
282
311
  return this;
283
- },
284
- configurable: true
312
+ }
313
+ , configurable: true
285
314
  });
286
315
 
287
316
  /**
@@ -297,8 +326,8 @@ Object.defineProperty(Assertion.prototype, 'not',
297
326
  { get: function () {
298
327
  this.negate = true;
299
328
  return this;
300
- },
301
- configurable: true
329
+ }
330
+ , configurable: true
302
331
  });
303
332
 
304
333
  /**
@@ -320,11 +349,11 @@ Object.defineProperty(Assertion.prototype, 'ok',
320
349
  this.assert(
321
350
  this.obj
322
351
  , 'expected ' + this.inspect + ' to be truthy'
323
- , 'expected ' + this.inspect + ' to be falsey');
352
+ , 'expected ' + this.inspect + ' to be falsy');
324
353
 
325
354
  return this;
326
- },
327
- configurable: true
355
+ }
356
+ , configurable: true
328
357
  });
329
358
 
330
359
  /**
@@ -341,11 +370,13 @@ Object.defineProperty(Assertion.prototype, 'true',
341
370
  this.assert(
342
371
  true === this.obj
343
372
  , 'expected ' + this.inspect + ' to be true'
344
- , 'expected ' + this.inspect + ' to be false');
373
+ , 'expected ' + this.inspect + ' to be false'
374
+ , this.negate ? false : true
375
+ );
345
376
 
346
377
  return this;
347
- },
348
- configurable: true
378
+ }
379
+ , configurable: true
349
380
  });
350
381
 
351
382
  /**
@@ -362,11 +393,13 @@ Object.defineProperty(Assertion.prototype, 'false',
362
393
  this.assert(
363
394
  false === this.obj
364
395
  , 'expected ' + this.inspect + ' to be false'
365
- , 'expected ' + this.inspect + ' to be true');
396
+ , 'expected ' + this.inspect + ' to be true'
397
+ , this.negate ? true : false
398
+ );
366
399
 
367
400
  return this;
368
- },
369
- configurable: true
401
+ }
402
+ , configurable: true
370
403
  });
371
404
 
372
405
  /**
@@ -388,11 +421,12 @@ Object.defineProperty(Assertion.prototype, 'exist',
388
421
  this.assert(
389
422
  null != this.obj
390
423
  , 'expected ' + this.inspect + ' to exist'
391
- , 'expected ' + this.inspect + ' to not exist');
424
+ , 'expected ' + this.inspect + ' to not exist'
425
+ );
392
426
 
393
427
  return this;
394
- },
395
- configurable: true
428
+ }
429
+ , configurable: true
396
430
  });
397
431
 
398
432
  /**
@@ -416,8 +450,8 @@ Object.defineProperty(Assertion.prototype, 'empty',
416
450
  , 'expected ' + this.inspect + ' not to be empty');
417
451
 
418
452
  return this;
419
- },
420
- configurable: true
453
+ }
454
+ , configurable: true
421
455
  });
422
456
 
423
457
  /**
@@ -438,11 +472,14 @@ Object.defineProperty(Assertion.prototype, 'arguments',
438
472
  this.assert(
439
473
  '[object Arguments]' == Object.prototype.toString.call(this.obj)
440
474
  , 'expected ' + this.inspect + ' to be arguments'
441
- , 'expected ' + this.inspect + ' to not be arguments');
475
+ , 'expected ' + this.inspect + ' to not be arguments'
476
+ , '[object Arguments]'
477
+ , Object.prototype.toString.call(this.obj)
478
+ );
442
479
 
443
480
  return this;
444
- },
445
- configurable: true
481
+ }
482
+ , configurable: true
446
483
  });
447
484
 
448
485
  /**
@@ -461,7 +498,8 @@ Assertion.prototype.equal = function (val) {
461
498
  this.assert(
462
499
  val === this.obj
463
500
  , 'expected ' + this.inspect + ' to equal ' + inspect(val)
464
- , 'expected ' + this.inspect + ' to not equal ' + inspect(val));
501
+ , 'expected ' + this.inspect + ' to not equal ' + inspect(val)
502
+ , val );
465
503
 
466
504
  return this;
467
505
  };
@@ -482,7 +520,9 @@ Assertion.prototype.eql = function (obj) {
482
520
  this.assert(
483
521
  eql(obj, this.obj)
484
522
  , 'expected ' + this.inspect + ' to equal ' + inspect(obj)
485
- , 'expected ' + this.inspect + ' to not equal ' + inspect(obj));
523
+ , 'expected ' + this.inspect + ' to not equal ' + inspect(obj)
524
+ , obj );
525
+
486
526
  return this;
487
527
  };
488
528
 
@@ -565,10 +605,15 @@ Assertion.prototype.within = function (start, finish) {
565
605
  */
566
606
 
567
607
  Assertion.prototype.a = function (type) {
608
+ var klass = type.charAt(0).toUpperCase() + type.slice(1);
609
+
568
610
  this.assert(
569
- type == typeof this.obj
611
+ '[object ' + klass + ']' === toString.call(this.obj)
570
612
  , 'expected ' + this.inspect + ' to be a ' + type
571
- , 'expected ' + this.inspect + ' not to be a ' + type);
613
+ , 'expected ' + this.inspect + ' not to be a ' + type
614
+ , '[object ' + klass + ']'
615
+ , toString.call(this.obj)
616
+ );
572
617
 
573
618
  return this;
574
619
  };
@@ -633,7 +678,10 @@ Assertion.prototype.property = function (name, val) {
633
678
  val === this.obj[name]
634
679
  , 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
635
680
  inspect(val) + ', but got ' + inspect(this.obj[name])
636
- , 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val));
681
+ , 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val)
682
+ , val
683
+ , this.obj[val]
684
+ );
637
685
  }
638
686
 
639
687
  this.obj = this.obj[name];
@@ -682,7 +730,10 @@ Assertion.prototype.length = function (n) {
682
730
  this.assert(
683
731
  len == n
684
732
  , 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
685
- , 'expected ' + this.inspect + ' to not have a length of ' + len);
733
+ , 'expected ' + this.inspect + ' to not have a length of ' + len
734
+ , n
735
+ , len
736
+ );
686
737
 
687
738
  return this;
688
739
  };
@@ -713,7 +764,7 @@ Assertion.prototype.match = function (re) {
713
764
  *
714
765
  * Assert the inclusion of an object in an Array or substring in string.
715
766
  *
716
- * expect([1,2,3]).to.contain(2);
767
+ * expect([1,2,3]).to.include(2);
717
768
  *
718
769
  * @name include
719
770
  * @param {Object|String|Number} obj
@@ -734,7 +785,7 @@ Assertion.prototype.include = function (obj) {
734
785
  *
735
786
  * Assert inclusion of string in string.
736
787
  *
737
- * expect('foobar').to.include.string('bar');
788
+ * expect('foobar').to.have.string('bar');
738
789
  *
739
790
  * @name string
740
791
  * @param {String} string
@@ -829,7 +880,10 @@ Assertion.prototype.keys = function(keys) {
829
880
  this.assert(
830
881
  ok
831
882
  , 'expected ' + this.inspect + ' to ' + str
832
- , 'expected ' + this.inspect + ' to not ' + str);
883
+ , 'expected ' + this.inspect + ' to not ' + str
884
+ , keys
885
+ , Object.keys(this.obj)
886
+ );
833
887
 
834
888
  return this;
835
889
  }
@@ -885,6 +939,81 @@ Assertion.prototype.throw = function (constructor) {
885
939
  return this;
886
940
  };
887
941
 
942
+ /**
943
+ * # .respondTo(method)
944
+ *
945
+ * Assert that object/class will respond to a method.
946
+ *
947
+ * expect(Klass).to.respondTo('bar');
948
+ * expect(obj).to.respondTo('bar');
949
+ *
950
+ * @name respondTo
951
+ * @param {String} method
952
+ * @api public
953
+ */
954
+
955
+ Assertion.prototype.respondTo = function (method) {
956
+ var context = ('function' === typeof this.obj)
957
+ ? this.obj.prototype[method]
958
+ : this.obj[method];
959
+
960
+ this.assert(
961
+ 'function' === typeof context
962
+ , 'expected ' + this.inspect + ' to respond to ' + inspect(method)
963
+ , 'expected ' + this.inspect + ' to not respond to ' + inspect(method)
964
+ , 'function'
965
+ , typeof context
966
+ );
967
+
968
+ return this;
969
+ };
970
+
971
+ /**
972
+ * # .satisfy(method)
973
+ *
974
+ * Assert that passes a truth test.
975
+ *
976
+ * expect(1).to.satisfy(function(num) { return num > 0; });
977
+ *
978
+ * @name satisfy
979
+ * @param {Function} matcher
980
+ * @api public
981
+ */
982
+
983
+ Assertion.prototype.satisfy = function (matcher) {
984
+ this.assert(
985
+ matcher(this.obj)
986
+ , 'expected ' + this.inspect + ' to satisfy ' + inspect(matcher)
987
+ , 'expected ' + this.inspect + ' to not satisfy' + inspect(matcher)
988
+ , this.negate ? false : true
989
+ , matcher(this.obj)
990
+ );
991
+
992
+ return this;
993
+ };
994
+
995
+ /**
996
+ * # .closeTo(expected, delta)
997
+ *
998
+ * Assert that actual is equal to +/- delta.
999
+ *
1000
+ * expect(1.5).to.be.closeTo(1, 0.5);
1001
+ *
1002
+ * @name closeTo
1003
+ * @param {Number} expected
1004
+ * @param {Number} delta
1005
+ * @api public
1006
+ */
1007
+
1008
+ Assertion.prototype.closeTo = function (expected, delta) {
1009
+ this.assert(
1010
+ (this.obj - delta === expected) || (this.obj + delta === expected)
1011
+ , 'expected ' + this.inspect + ' to be close to ' + expected + ' +/- ' + delta
1012
+ , 'expected ' + this.inspect + ' not to be close to ' + expected + ' +/- ' + delta);
1013
+
1014
+ return this;
1015
+ };
1016
+
888
1017
  /*!
889
1018
  * Aliases.
890
1019
  */
@@ -914,7 +1043,7 @@ require.register("chai.js", function(module, exports, require){
914
1043
  var used = [];
915
1044
  var exports = module.exports = {};
916
1045
 
917
- exports.version = '0.3.3';
1046
+ exports.version = '0.4.2';
918
1047
 
919
1048
  exports.Assertion = require('./assertion');
920
1049
  exports.AssertionError = require('./error');
@@ -930,16 +1059,6 @@ exports.use = function (fn) {
930
1059
  return this;
931
1060
  };
932
1061
 
933
- exports.fail = function (actual, expected, message, operator, stackStartFunction) {
934
- throw new exports.AssertionError({
935
- message: message,
936
- actual: actual,
937
- expected: expected,
938
- operator: operator,
939
- stackStartFunction: stackStartFunction
940
- });
941
- };
942
-
943
1062
  var expect = require('./interface/expect');
944
1063
  exports.use(expect);
945
1064
 
@@ -982,25 +1101,10 @@ function AssertionError (options) {
982
1101
 
983
1102
  AssertionError.prototype.__proto__ = Error.prototype;
984
1103
 
985
- AssertionError.prototype.summary = function() {
986
- var str = '';
987
-
988
- if (this.operator) {
989
- str += 'In: \'' + this.operator + '\'\n\t';
990
- }
991
-
992
- str += '' + this.name + (this.message ? ': ' + this.message : '');
993
-
994
- return str;
995
- };
996
-
997
- AssertionError.prototype.details = function() {
998
- return this.summary();
999
- };
1000
-
1001
1104
  AssertionError.prototype.toString = function() {
1002
- return this.summary();
1105
+ return this.message;
1003
1106
  };
1107
+
1004
1108
  }); // module: error.js
1005
1109
 
1006
1110
  require.register("interface/assert.js", function(module, exports, require){
@@ -1024,6 +1128,14 @@ require.register("interface/assert.js", function(module, exports, require){
1024
1128
  *
1025
1129
  * assert.typeOf(foo, 'string');
1026
1130
  * assert.equal(foo, 'bar');
1131
+ *
1132
+ * #### Configuration
1133
+ *
1134
+ * By default, Chai does not show stack traces upon an AssertionError. This can
1135
+ * be changed by modifying the `includeStack` parameter for chai.Assertion. For example:
1136
+ *
1137
+ * var chai = require('chai');
1138
+ * chai.Assertion.includeStack = true; // defaults to false
1027
1139
  */
1028
1140
 
1029
1141
  module.exports = function (chai) {
@@ -1225,7 +1337,7 @@ module.exports = function (chai) {
1225
1337
  */
1226
1338
 
1227
1339
  assert.isNull = function (val, msg) {
1228
- new Assertion(val, msg).to.not.exist;
1340
+ new Assertion(val, msg).to.equal(null);
1229
1341
  };
1230
1342
 
1231
1343
  /**
@@ -1243,7 +1355,7 @@ module.exports = function (chai) {
1243
1355
  */
1244
1356
 
1245
1357
  assert.isNotNull = function (val, msg) {
1246
- new Assertion(val, msg).to.exist;
1358
+ new Assertion(val, msg).to.not.equal(null);
1247
1359
  };
1248
1360
 
1249
1361
  /**
@@ -1350,7 +1462,7 @@ module.exports = function (chai) {
1350
1462
  */
1351
1463
 
1352
1464
  assert.isNumber = function (val, msg) {
1353
- new Assertion(val, msg).to.be.instanceof(Number);
1465
+ new Assertion(val, msg).to.be.a('number');
1354
1466
  };
1355
1467
 
1356
1468
  /**
@@ -1528,6 +1640,29 @@ module.exports = function (chai) {
1528
1640
  new Assertion(fn, msg).to.not.throw(type);
1529
1641
  };
1530
1642
 
1643
+ /**
1644
+ * # .operator(val, operator, val2, [message])
1645
+ *
1646
+ * Compare two values using operator.
1647
+ *
1648
+ * assert.operator(1, '<', 2, 'everything is ok');
1649
+ * assert.operator(1, '>', 2, 'this will fail');
1650
+ *
1651
+ * @name operator
1652
+ * @param {*} object to test
1653
+ * @param {String} operator
1654
+ * @param {*} second object
1655
+ * @param {String} message
1656
+ * @api public
1657
+ */
1658
+
1659
+ assert.operator = function (val, operator, val2, msg) {
1660
+ if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
1661
+ throw new Error('Invalid operator "' + operator + '"');
1662
+ }
1663
+ new Assertion(eval(val + operator + val2), msg).to.be.true;
1664
+ };
1665
+
1531
1666
  /*!
1532
1667
  * Undocumented / untested
1533
1668
  */