chai-rails 1.9.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d12361819b7f275318c749284c1f66e3a237cae
4
- data.tar.gz: a48e2117f221a6968d11b8a0e7d5143929cdbb02
3
+ metadata.gz: 49ea46a5f87ec1f178a5f3fdaf800d4a430759b4
4
+ data.tar.gz: 3238d28742f6a5dc9d9497e87fff5ea536aed66a
5
5
  SHA512:
6
- metadata.gz: 8d3452104b0804af3db284396a673db00d42059e082aaf0095bb0921eb5a7fa5468420e0bdf189930ac394c65a76acdef99c352af5decdc5490c57139193002f
7
- data.tar.gz: f60d4ed212f5c1eb09548a3f3e6e1170351bdf78f570027aaf168e18e24061266ca5ba4d5c8bd00801e9b036cd2c7aaf5842ae148b50b320099431437b3072a4
6
+ metadata.gz: ccf336646a4a325c820d85488f227c5762f7f1b23de59d82d23f18255cc3047cade44ab700f60718d5df09c3e8ce05d8e625f513217bf6e1d8cabe29f9c8f502
7
+ data.tar.gz: b443f8afb78b75e7705f72c7435de87d60cf6e0285bafd58c02d54de0887f21e89e2e1993d29dbc2a2d2f709cb13718c1a685bcaed8a4a603fff328d2a6b51ad
@@ -736,7 +736,7 @@ var used = []
736
736
  * Chai version
737
737
  */
738
738
 
739
- exports.version = '1.8.1';
739
+ exports.version = '1.9.1';
740
740
 
741
741
  /*!
742
742
  * Assertion Error
@@ -769,6 +769,13 @@ exports.use = function (fn) {
769
769
  return this;
770
770
  };
771
771
 
772
+ /*!
773
+ * Configuration
774
+ */
775
+
776
+ var config = require('./chai/config');
777
+ exports.config = config;
778
+
772
779
  /*!
773
780
  * Primary `Assertion` prototype
774
781
  */
@@ -813,6 +820,8 @@ require.register("chai/lib/chai/assertion.js", function(exports, require, module
813
820
  * MIT Licensed
814
821
  */
815
822
 
823
+ var config = require('./config');
824
+
816
825
  module.exports = function (_chai, util) {
817
826
  /*!
818
827
  * Module dependencies.
@@ -841,33 +850,27 @@ module.exports = function (_chai, util) {
841
850
  flag(this, 'message', msg);
842
851
  }
843
852
 
844
- /*!
845
- * ### Assertion.includeStack
846
- *
847
- * User configurable property, influences whether stack trace
848
- * is included in Assertion error message. Default of false
849
- * suppresses stack trace in the error message
850
- *
851
- * Assertion.includeStack = true; // enable stack on error
852
- *
853
- * @api public
854
- */
855
-
856
- Assertion.includeStack = false;
857
-
858
- /*!
859
- * ### Assertion.showDiff
860
- *
861
- * User configurable property, influences whether or not
862
- * the `showDiff` flag should be included in the thrown
863
- * AssertionErrors. `false` will always be `false`; `true`
864
- * will be true when the assertion has requested a diff
865
- * be shown.
866
- *
867
- * @api public
868
- */
853
+ Object.defineProperty(Assertion, 'includeStack', {
854
+ get: function() {
855
+ console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
856
+ return config.includeStack;
857
+ },
858
+ set: function(value) {
859
+ console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
860
+ config.includeStack = value;
861
+ }
862
+ });
869
863
 
870
- Assertion.showDiff = true;
864
+ Object.defineProperty(Assertion, 'showDiff', {
865
+ get: function() {
866
+ console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
867
+ return config.showDiff;
868
+ },
869
+ set: function(value) {
870
+ console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
871
+ config.showDiff = value;
872
+ }
873
+ });
871
874
 
872
875
  Assertion.addProperty = function (name, fn) {
873
876
  util.addProperty(this.prototype, name, fn);
@@ -910,7 +913,7 @@ module.exports = function (_chai, util) {
910
913
  Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
911
914
  var ok = util.test(this, arguments);
912
915
  if (true !== showDiff) showDiff = false;
913
- if (true !== Assertion.showDiff) showDiff = false;
916
+ if (true !== config.showDiff) showDiff = false;
914
917
 
915
918
  if (!ok) {
916
919
  var msg = util.getMessage(this, arguments)
@@ -919,7 +922,7 @@ module.exports = function (_chai, util) {
919
922
  actual: actual
920
923
  , expected: expected
921
924
  , showDiff: showDiff
922
- }, (Assertion.includeStack) ? this.assert : flag(this, 'ssfi'));
925
+ }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
923
926
  }
924
927
  };
925
928
 
@@ -941,6 +944,59 @@ module.exports = function (_chai, util) {
941
944
  });
942
945
  };
943
946
 
947
+ });
948
+ require.register("chai/lib/chai/config.js", function(exports, require, module){
949
+ module.exports = {
950
+
951
+ /**
952
+ * ### config.includeStack
953
+ *
954
+ * User configurable property, influences whether stack trace
955
+ * is included in Assertion error message. Default of false
956
+ * suppresses stack trace in the error message.
957
+ *
958
+ * chai.config.includeStack = true; // enable stack on error
959
+ *
960
+ * @param {Boolean}
961
+ * @api public
962
+ */
963
+
964
+ includeStack: false,
965
+
966
+ /**
967
+ * ### config.showDiff
968
+ *
969
+ * User configurable property, influences whether or not
970
+ * the `showDiff` flag should be included in the thrown
971
+ * AssertionErrors. `false` will always be `false`; `true`
972
+ * will be true when the assertion has requested a diff
973
+ * be shown.
974
+ *
975
+ * @param {Boolean}
976
+ * @api public
977
+ */
978
+
979
+ showDiff: true,
980
+
981
+ /**
982
+ * ### config.truncateThreshold
983
+ *
984
+ * User configurable property, sets length threshold for actual and
985
+ * expected values in assertion errors. If this threshold is exceeded,
986
+ * the value is truncated.
987
+ *
988
+ * Set it to zero if you want to disable truncating altogether.
989
+ *
990
+ * chai.config.truncateThreshold = 0; // disable truncating
991
+ *
992
+ * @param {Number}
993
+ * @api public
994
+ */
995
+
996
+ truncateThreshold: 40
997
+
998
+ };
999
+
944
1000
  });
945
1001
  require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
946
1002
  /*!
@@ -960,7 +1016,7 @@ module.exports = function (chai, _) {
960
1016
  *
961
1017
  * The following are provided as chainable getters to
962
1018
  * improve the readability of your assertions. They
963
- * do not provide an testing capability unless they
1019
+ * do not provide testing capabilities unless they
964
1020
  * have been overwritten by a plugin.
965
1021
  *
966
1022
  * **Chains**
@@ -1092,17 +1148,24 @@ module.exports = function (chai, _) {
1092
1148
  function include (val, msg) {
1093
1149
  if (msg) flag(this, 'message', msg);
1094
1150
  var obj = flag(this, 'object');
1095
-
1096
- if (_.type(val) === 'object') {
1151
+ var expected = false;
1152
+ if (_.type(obj) === 'array' && _.type(val) === 'object') {
1153
+ for (var i in obj) {
1154
+ if (_.eql(obj[i], val)) {
1155
+ expected = true;
1156
+ break;
1157
+ }
1158
+ }
1159
+ } else if (_.type(val) === 'object') {
1097
1160
  if (!flag(this, 'negate')) {
1098
1161
  for (var k in val) new Assertion(obj).property(k, val[k]);
1099
1162
  return;
1100
1163
  }
1101
1164
  var subset = {}
1102
1165
  for (var k in val) subset[k] = obj[k]
1103
- var expected = _.eql(subset, val);
1166
+ expected = _.eql(subset, val);
1104
1167
  } else {
1105
- var expected = obj && ~obj.indexOf(val)
1168
+ expected = obj && ~obj.indexOf(val)
1106
1169
  }
1107
1170
  this.assert(
1108
1171
  expected
@@ -2190,9 +2253,13 @@ module.exports = function (chai, _) {
2190
2253
  );
2191
2254
  });
2192
2255
 
2193
- function isSubsetOf(subset, superset) {
2256
+ function isSubsetOf(subset, superset, cmp) {
2194
2257
  return subset.every(function(elem) {
2195
- return superset.indexOf(elem) !== -1;
2258
+ if (!cmp) return superset.indexOf(elem) !== -1;
2259
+
2260
+ return superset.some(function(elem2) {
2261
+ return cmp(elem, elem2);
2262
+ });
2196
2263
  })
2197
2264
  }
2198
2265
 
@@ -2200,7 +2267,9 @@ module.exports = function (chai, _) {
2200
2267
  * ### .members(set)
2201
2268
  *
2202
2269
  * Asserts that the target is a superset of `set`,
2203
- * or that the target and `set` have the same members.
2270
+ * or that the target and `set` have the same strictly-equal (===) members.
2271
+ * Alternately, if the `deep` flag is set, set members are compared for deep
2272
+ * equality.
2204
2273
  *
2205
2274
  * expect([1, 2, 3]).to.include.members([3, 2]);
2206
2275
  * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
@@ -2208,6 +2277,8 @@ module.exports = function (chai, _) {
2208
2277
  * expect([4, 2]).to.have.members([2, 4]);
2209
2278
  * expect([5, 2]).to.not.have.members([5, 2, 1]);
2210
2279
  *
2280
+ * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
2281
+ *
2211
2282
  * @name members
2212
2283
  * @param {Array} set
2213
2284
  * @param {String} message _optional_
@@ -2221,9 +2292,11 @@ module.exports = function (chai, _) {
2221
2292
  new Assertion(obj).to.be.an('array');
2222
2293
  new Assertion(subset).to.be.an('array');
2223
2294
 
2295
+ var cmp = flag(this, 'deep') ? _.eql : undefined;
2296
+
2224
2297
  if (flag(this, 'contains')) {
2225
2298
  return this.assert(
2226
- isSubsetOf(subset, obj)
2299
+ isSubsetOf(subset, obj, cmp)
2227
2300
  , 'expected #{this} to be a superset of #{act}'
2228
2301
  , 'expected #{this} to not be a superset of #{act}'
2229
2302
  , obj
@@ -2232,7 +2305,7 @@ module.exports = function (chai, _) {
2232
2305
  }
2233
2306
 
2234
2307
  this.assert(
2235
- isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
2308
+ isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
2236
2309
  , 'expected #{this} to have the same members as #{act}'
2237
2310
  , 'expected #{this} to not have the same members as #{act}'
2238
2311
  , obj
@@ -2278,7 +2351,7 @@ module.exports = function (chai, util) {
2278
2351
  */
2279
2352
 
2280
2353
  var assert = chai.assert = function (express, errmsg) {
2281
- var test = new Assertion(null);
2354
+ var test = new Assertion(null, null, chai.assert);
2282
2355
  test.assert(
2283
2356
  express
2284
2357
  , errmsg
@@ -2359,7 +2432,7 @@ module.exports = function (chai, util) {
2359
2432
  */
2360
2433
 
2361
2434
  assert.equal = function (act, exp, msg) {
2362
- var test = new Assertion(act, msg);
2435
+ var test = new Assertion(act, msg, assert.equal);
2363
2436
 
2364
2437
  test.assert(
2365
2438
  exp == flag(test, 'object')
@@ -2385,7 +2458,7 @@ module.exports = function (chai, util) {
2385
2458
  */
2386
2459
 
2387
2460
  assert.notEqual = function (act, exp, msg) {
2388
- var test = new Assertion(act, msg);
2461
+ var test = new Assertion(act, msg, assert.notEqual);
2389
2462
 
2390
2463
  test.assert(
2391
2464
  exp != flag(test, 'object')
@@ -2636,8 +2709,8 @@ module.exports = function (chai, util) {
2636
2709
  * Asserts that `value` is _not_ an object.
2637
2710
  *
2638
2711
  * var selection = 'chai'
2639
- * assert.isObject(selection, 'tea selection is not an object');
2640
- * assert.isObject(null, 'null is not an object');
2712
+ * assert.isNotObject(selection, 'tea selection is not an object');
2713
+ * assert.isNotObject(null, 'null is not an object');
2641
2714
  *
2642
2715
  * @name isNotObject
2643
2716
  * @param {Mixed} value
@@ -2901,7 +2974,7 @@ module.exports = function (chai, util) {
2901
2974
  */
2902
2975
 
2903
2976
  assert.include = function (exp, inc, msg) {
2904
- new Assertion(exp, msg).include(inc);
2977
+ new Assertion(exp, msg, assert.include).include(inc);
2905
2978
  };
2906
2979
 
2907
2980
  /**
@@ -2921,7 +2994,7 @@ module.exports = function (chai, util) {
2921
2994
  */
2922
2995
 
2923
2996
  assert.notInclude = function (exp, inc, msg) {
2924
- new Assertion(exp, msg).not.include(inc);
2997
+ new Assertion(exp, msg, assert.notInclude).not.include(inc);
2925
2998
  };
2926
2999
 
2927
3000
  /**
@@ -3327,31 +3400,33 @@ module.exports = function (chai, util) {
3327
3400
  var Assertion = chai.Assertion;
3328
3401
 
3329
3402
  function loadShould () {
3403
+ // explicitly define this method as function as to have it's name to include as `ssfi`
3404
+ function shouldGetter() {
3405
+ if (this instanceof String || this instanceof Number) {
3406
+ return new Assertion(this.constructor(this), null, shouldGetter);
3407
+ } else if (this instanceof Boolean) {
3408
+ return new Assertion(this == true, null, shouldGetter);
3409
+ }
3410
+ return new Assertion(this, null, shouldGetter);
3411
+ }
3412
+ function shouldSetter(value) {
3413
+ // See https://github.com/chaijs/chai/issues/86: this makes
3414
+ // `whatever.should = someValue` actually set `someValue`, which is
3415
+ // especially useful for `global.should = require('chai').should()`.
3416
+ //
3417
+ // Note that we have to use [[DefineProperty]] instead of [[Put]]
3418
+ // since otherwise we would trigger this very setter!
3419
+ Object.defineProperty(this, 'should', {
3420
+ value: value,
3421
+ enumerable: true,
3422
+ configurable: true,
3423
+ writable: true
3424
+ });
3425
+ }
3330
3426
  // modify Object.prototype to have `should`
3331
- Object.defineProperty(Object.prototype, 'should',
3332
- {
3333
- set: function (value) {
3334
- // See https://github.com/chaijs/chai/issues/86: this makes
3335
- // `whatever.should = someValue` actually set `someValue`, which is
3336
- // especially useful for `global.should = require('chai').should()`.
3337
- //
3338
- // Note that we have to use [[DefineProperty]] instead of [[Put]]
3339
- // since otherwise we would trigger this very setter!
3340
- Object.defineProperty(this, 'should', {
3341
- value: value,
3342
- enumerable: true,
3343
- configurable: true,
3344
- writable: true
3345
- });
3346
- }
3347
- , get: function(){
3348
- if (this instanceof String || this instanceof Number) {
3349
- return new Assertion(this.constructor(this));
3350
- } else if (this instanceof Boolean) {
3351
- return new Assertion(this == true);
3352
- }
3353
- return new Assertion(this);
3354
- }
3427
+ Object.defineProperty(Object.prototype, 'should', {
3428
+ set: shouldSetter
3429
+ , get: shouldGetter
3355
3430
  , configurable: true
3356
3431
  });
3357
3432
 
@@ -3407,6 +3482,8 @@ require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports,
3407
3482
  */
3408
3483
 
3409
3484
  var transferFlags = require('./transferFlags');
3485
+ var flag = require('./flag');
3486
+ var config = require('../config');
3410
3487
 
3411
3488
  /*!
3412
3489
  * Module variables
@@ -3472,7 +3549,10 @@ module.exports = function (ctx, name, method, chainingBehavior) {
3472
3549
  { get: function () {
3473
3550
  chainableBehavior.chainingBehavior.call(this);
3474
3551
 
3475
- var assert = function () {
3552
+ var assert = function assert() {
3553
+ var old_ssfi = flag(this, 'ssfi');
3554
+ if (old_ssfi && config.includeStack === false)
3555
+ flag(this, 'ssfi', assert);
3476
3556
  var result = chainableBehavior.method.apply(this, arguments);
3477
3557
  return result === undefined ? this : result;
3478
3558
  };
@@ -3511,6 +3591,8 @@ require.register("chai/lib/chai/utils/addMethod.js", function(exports, require,
3511
3591
  * MIT Licensed
3512
3592
  */
3513
3593
 
3594
+ var config = require('../config');
3595
+
3514
3596
  /**
3515
3597
  * ### .addMethod (ctx, name, method)
3516
3598
  *
@@ -3535,9 +3617,13 @@ require.register("chai/lib/chai/utils/addMethod.js", function(exports, require,
3535
3617
  * @name addMethod
3536
3618
  * @api public
3537
3619
  */
3620
+ var flag = require('./flag');
3538
3621
 
3539
3622
  module.exports = function (ctx, name, method) {
3540
3623
  ctx[name] = function () {
3624
+ var old_ssfi = flag(this, 'ssfi');
3625
+ if (old_ssfi && config.includeStack === false)
3626
+ flag(this, 'ssfi', ctx[name]);
3541
3627
  var result = method.apply(this, arguments);
3542
3628
  return result === undefined ? this : result;
3543
3629
  };
@@ -3639,8 +3725,7 @@ require.register("chai/lib/chai/utils/getActual.js", function(exports, require,
3639
3725
  */
3640
3726
 
3641
3727
  module.exports = function (obj, args) {
3642
- var actual = args[4];
3643
- return 'undefined' !== typeof actual ? actual : obj._obj;
3728
+ return args.length > 4 ? args[4] : obj._obj;
3644
3729
  };
3645
3730
 
3646
3731
  });
@@ -4342,6 +4427,7 @@ require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require,
4342
4427
  */
4343
4428
 
4344
4429
  var inspect = require('./inspect');
4430
+ var config = require('../config');
4345
4431
 
4346
4432
  /**
4347
4433
  * ### .objDisplay (object)
@@ -4359,7 +4445,7 @@ module.exports = function (obj) {
4359
4445
  var str = inspect(obj)
4360
4446
  , type = Object.prototype.toString.call(obj);
4361
4447
 
4362
- if (str.length >= 40) {
4448
+ if (config.truncateThreshold && str.length >= config.truncateThreshold) {
4363
4449
  if (type === '[object Function]') {
4364
4450
  return !obj.name || obj.name === ''
4365
4451
  ? '[Function]'
@@ -1,5 +1,5 @@
1
1
  module Chai
2
2
  module Rails
3
- VERSION = "1.9.0"
3
+ VERSION = "1.9.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chai-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Plutalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-10 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  description:
@@ -31,7 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - .gitignore
34
+ - ".gitignore"
35
35
  - Gemfile
36
36
  - LICENSE.txt
37
37
  - README.md
@@ -50,19 +50,18 @@ require_paths:
50
50
  - lib
51
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.2.0
63
+ rubygems_version: 2.2.2
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Chai via assets pipeline
67
67
  test_files: []
68
- has_rdoc: