konacha-chai-matchers 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +18 -0
- data/README.md +6 -0
- data/VERSIONS +11 -5
- data/lib/konacha-chai-matchers/version.rb +1 -1
- data/vendor/assets/javascripts/chai-colors.js +16 -0
- data/vendor/assets/javascripts/chai-datetime.js +6 -2
- data/vendor/assets/javascripts/chai-jq.js +13 -5
- data/vendor/assets/javascripts/chai-jquery.js +20 -53
- data/vendor/assets/javascripts/chai-param.js +161 -0
- data/vendor/assets/javascripts/chai-shallow-deep-equal.js +78 -0
- data/vendor/assets/javascripts/chai-string.js +194 -0
- data/vendor/assets/javascripts/chai-subset.js +47 -0
- data/vendor/assets/javascripts/chai-xml.js +83 -0
- data/vendor/assets/javascripts/sinon-chai.js +7 -2
- data/vendor/assets/javascripts/sinon.js +2792 -2596
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 626fca41336d274fa07caf9b97b4b859e33ba5d8
|
4
|
+
data.tar.gz: 8465e7f3959300e06e6458cd9be4cd3b4d5f9610
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d89068bc4e0b130b9c1aeaae79e2d95015f66dc2223cf858b38cbafa113036b05a27f4d22b1b39cdae119eb2aab871cd7c1d26b552e3a5fedf35a1ff7ee1430
|
7
|
+
data.tar.gz: 09d37ab3972082b1e7c771ac49102084eb55e2075305d058d0bd54119fabe14e6c7cbf71e4e8c12752fbc4d7c976bde0f2f9cfd95acddb3ae2171add79476e17
|
data/.gitmodules
CHANGED
@@ -61,3 +61,21 @@
|
|
61
61
|
[submodule "chai-change"]
|
62
62
|
path = chai-change
|
63
63
|
url = https://github.com/timruffles/chai-change.git
|
64
|
+
[submodule "chai-colors"]
|
65
|
+
path = chai-colors
|
66
|
+
url = git@github.com:hurrymaplelad/chai-colors.git
|
67
|
+
[submodule "chai-shallow-deep-equal"]
|
68
|
+
path = chai-shallow-deep-equal
|
69
|
+
url = git@github.com:michelsalib/chai-shallow-deep-equal.git
|
70
|
+
[submodule "chai-subset"]
|
71
|
+
path = chai-subset
|
72
|
+
url = git@github.com:e-conomic/chai-subset.git
|
73
|
+
[submodule "chai-string"]
|
74
|
+
path = chai-string
|
75
|
+
url = git@github.com:onechiporenko/chai-string.git
|
76
|
+
[submodule "chai-param"]
|
77
|
+
path = chai-param
|
78
|
+
url = git@github.com:theblacksmith/chai-param.git
|
79
|
+
[submodule "chai-xml"]
|
80
|
+
path = chai-xml
|
81
|
+
url = git@github.com:krampstudio/chai-xml.git
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Konacha Chai Matchers
|
|
4
4
|
[![Gem Version](https://fury-badge.herokuapp.com/rb/konacha-chai-matchers.png)](http://badge.fury.io/rb/konacha-chai-matchers)
|
5
5
|
|
6
6
|
This library contains all [Chai.js plugins](http://chaijs.com/plugins)
|
7
|
+
that have browser support.
|
7
8
|
|
8
9
|
Not all plugins are tested!
|
9
10
|
|
@@ -29,6 +30,11 @@ Example:
|
|
29
30
|
#= require chai-backbone
|
30
31
|
#= require chai-jquery
|
31
32
|
|
33
|
+
Included versions
|
34
|
+
-----------------
|
35
|
+
|
36
|
+
See `VERSIONS` for info
|
37
|
+
|
32
38
|
Contribution
|
33
39
|
------------
|
34
40
|
|
data/VERSIONS
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
chai-spies: 0.5.1
|
2
|
-
sinon-chai: 2.
|
2
|
+
sinon-chai: 2.6.0
|
3
3
|
chai-as-promised: 4.1.1
|
4
|
-
chai-jquery:
|
4
|
+
chai-jquery: 2.0.0
|
5
5
|
chai-timers: 0.2.0
|
6
6
|
chai-stats: 0.3.0
|
7
7
|
chai-null: 0.1.0
|
@@ -12,10 +12,16 @@ js-factories: 1.1.1
|
|
12
12
|
mocha-as-promised: 2.0.0
|
13
13
|
chai-things: 0.2.0
|
14
14
|
chai-fuzzy: 1.4.0
|
15
|
-
sinon: 1.
|
15
|
+
sinon: 1.12.2
|
16
16
|
memo-is: 0.0.2
|
17
|
-
chai-jq: 0.0.
|
17
|
+
chai-jq: 0.0.8
|
18
18
|
chai-js-factories: 0.1.3
|
19
19
|
chai-json-schema: 1.1.0
|
20
|
-
chai-datetime: 1.3.
|
20
|
+
chai-datetime: 1.3.1
|
21
21
|
chai-change: 1.0.0
|
22
|
+
chai-colors: 1.0.0
|
23
|
+
chai-shallow-deep-equal: 1.0.0
|
24
|
+
chai-subset: 0.3.0
|
25
|
+
chai-string: 1.1.0
|
26
|
+
chai-param: 0.1.0
|
27
|
+
chai-xml: 0.2.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
var color = require('onecolor');
|
2
|
+
|
3
|
+
module.exports = function (chai, utils) {
|
4
|
+
chai.Assertion.addMethod('colored', function (colorString) {
|
5
|
+
var expected = color(colorString),
|
6
|
+
actual = color(this._obj);
|
7
|
+
|
8
|
+
this.assert(
|
9
|
+
actual.equals(expected),
|
10
|
+
'expected #{act} to be the same color as #{exp}',
|
11
|
+
'expected #{act} to be a different color than #{exp}',
|
12
|
+
expected.hex(),
|
13
|
+
actual.hex()
|
14
|
+
);
|
15
|
+
});
|
16
|
+
};
|
@@ -37,12 +37,16 @@
|
|
37
37
|
return actual.toDateString() === expected.toDateString();
|
38
38
|
};
|
39
39
|
|
40
|
+
var dateWithoutTime = function(date) {
|
41
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
42
|
+
}
|
43
|
+
|
40
44
|
chai.datetime.beforeDate = function(actual, expected) {
|
41
|
-
return
|
45
|
+
return chai.datetime.beforeTime(dateWithoutTime(actual), dateWithoutTime(expected));
|
42
46
|
};
|
43
47
|
|
44
48
|
chai.datetime.afterDate = function(actual, expected) {
|
45
|
-
return
|
49
|
+
return chai.datetime.afterTime(dateWithoutTime(actual), dateWithoutTime(expected));
|
46
50
|
};
|
47
51
|
|
48
52
|
chai.datetime.beforeTime = function(actual, expected) {
|
@@ -25,6 +25,11 @@
|
|
25
25
|
* Give a more useful element name.
|
26
26
|
*/
|
27
27
|
var _elName = function ($el) {
|
28
|
+
// Detect if completely empty.
|
29
|
+
if (!$el || $el.length === 0) {
|
30
|
+
return "<EMPTY OBJECT>";
|
31
|
+
}
|
32
|
+
|
28
33
|
var name = "",
|
29
34
|
id = $el.attr("id"),
|
30
35
|
cls = $el.attr("class") || "";
|
@@ -128,7 +133,7 @@
|
|
128
133
|
*/
|
129
134
|
var _containMethod = function (jqMeth, opts) {
|
130
135
|
// Unpack options.
|
131
|
-
opts
|
136
|
+
opts = opts || /* istanbul ignore next */ {};
|
132
137
|
opts.hasArg = !!opts.hasArg;
|
133
138
|
opts.isProperty = !!opts.isProperty;
|
134
139
|
opts.hasContains = !!opts.hasContains;
|
@@ -246,7 +251,9 @@
|
|
246
251
|
* @api public
|
247
252
|
*/
|
248
253
|
var $val = _jqAssert(function (exp) {
|
249
|
-
|
254
|
+
// Manually check empty elements for `.val` call b/c ie9 can otherwise
|
255
|
+
// report `Unspecified error.` at least in Sauce Labs.
|
256
|
+
var act = this._$el && this._$el.length > 0 ? this._$el.val() : undefined,
|
250
257
|
comp = _isRegExp(exp) ? _regExpMatch : _equals;
|
251
258
|
|
252
259
|
this.assert(
|
@@ -327,8 +334,8 @@
|
|
327
334
|
chai.Assertion.addMethod("$attr", $attr);
|
328
335
|
|
329
336
|
/**
|
330
|
-
* Asserts that the target has exactly the given named
|
331
|
-
* data-attribute, or asserts the target contains a subset
|
337
|
+
* Asserts that the target has exactly the given named
|
338
|
+
* data-attribute, or asserts the target contains a subset
|
332
339
|
* of the data-attribute when using the
|
333
340
|
* `include` or `contain` modifiers.
|
334
341
|
*
|
@@ -338,7 +345,7 @@
|
|
338
345
|
* .to.contain.$data("foo", "bar");
|
339
346
|
* ```
|
340
347
|
*
|
341
|
-
* Changes context to data-attribute string *value* when no
|
348
|
+
* Changes context to data-attribute string *value* when no
|
342
349
|
* expected value is provided:
|
343
350
|
*
|
344
351
|
* ```js
|
@@ -486,6 +493,7 @@
|
|
486
493
|
chai.Assertion.addMethod("$css", $css);
|
487
494
|
}
|
488
495
|
|
496
|
+
/* istanbul ignore next */
|
489
497
|
/*!
|
490
498
|
* Wrap AMD, etc. using boilerplate.
|
491
499
|
*/
|
@@ -145,6 +145,15 @@
|
|
145
145
|
);
|
146
146
|
});
|
147
147
|
|
148
|
+
chai.Assertion.addMethod('descendants', function (selector) {
|
149
|
+
this.assert(
|
150
|
+
flag(this, 'object').has(selector).length > 0
|
151
|
+
, 'expected #{this} to have #{exp}'
|
152
|
+
, 'expected #{this} not to have #{exp}'
|
153
|
+
, selector
|
154
|
+
);
|
155
|
+
});
|
156
|
+
|
148
157
|
$.each(['visible', 'hidden', 'selected', 'checked', 'enabled', 'disabled'], function (i, attr) {
|
149
158
|
chai.Assertion.addProperty(attr, function () {
|
150
159
|
this.assert(
|
@@ -182,27 +191,6 @@
|
|
182
191
|
};
|
183
192
|
});
|
184
193
|
|
185
|
-
chai.Assertion.overwriteProperty('be', function (_super) {
|
186
|
-
return function () {
|
187
|
-
var obj = flag(this, 'object');
|
188
|
-
if (obj instanceof $) {
|
189
|
-
var be = function (selector) {
|
190
|
-
this.assert(
|
191
|
-
obj.is(selector)
|
192
|
-
, 'expected #{this} to be #{exp}'
|
193
|
-
, 'expected #{this} not to be #{exp}'
|
194
|
-
, selector
|
195
|
-
);
|
196
|
-
};
|
197
|
-
setPrototypeOf(be, this);
|
198
|
-
return be;
|
199
|
-
}
|
200
|
-
else {
|
201
|
-
_super.call(this);
|
202
|
-
}
|
203
|
-
}
|
204
|
-
});
|
205
|
-
|
206
194
|
chai.Assertion.overwriteMethod('match', function (_super) {
|
207
195
|
return function (selector) {
|
208
196
|
var obj = flag(this, 'object');
|
@@ -219,46 +207,25 @@
|
|
219
207
|
}
|
220
208
|
});
|
221
209
|
|
222
|
-
chai.Assertion.
|
223
|
-
|
224
|
-
|
225
|
-
var contain = function (text) {
|
210
|
+
chai.Assertion.overwriteChainableMethod('contain',
|
211
|
+
function (_super) {
|
212
|
+
return function (text) {
|
226
213
|
var obj = flag(this, 'object');
|
227
214
|
if (obj instanceof $) {
|
228
215
|
this.assert(
|
229
216
|
obj.is(':contains(\'' + text + '\')')
|
230
217
|
, 'expected #{this} to contain #{exp}'
|
231
218
|
, 'expected #{this} not to contain #{exp}'
|
232
|
-
, text
|
233
|
-
);
|
219
|
+
, text);
|
234
220
|
} else {
|
235
|
-
|
221
|
+
_super.apply(this, arguments);
|
236
222
|
}
|
237
|
-
};
|
238
|
-
setPrototypeOf(contain, this);
|
239
|
-
return contain;
|
240
|
-
}
|
241
|
-
});
|
242
|
-
|
243
|
-
chai.Assertion.overwriteProperty('have', function (_super) {
|
244
|
-
return function () {
|
245
|
-
var obj = flag(this, 'object');
|
246
|
-
if (obj instanceof $) {
|
247
|
-
var have = function (selector) {
|
248
|
-
this.assert(
|
249
|
-
// Using find() rather than has() to work around a jQuery bug:
|
250
|
-
// http://bugs.jquery.com/ticket/11706
|
251
|
-
obj.find(selector).length > 0
|
252
|
-
, 'expected #{this} to have #{exp}'
|
253
|
-
, 'expected #{this} not to have #{exp}'
|
254
|
-
, selector
|
255
|
-
);
|
256
|
-
};
|
257
|
-
setPrototypeOf(have, this);
|
258
|
-
return have;
|
259
|
-
} else {
|
260
|
-
_super.call(this);
|
261
223
|
}
|
224
|
+
},
|
225
|
+
function(_super) {
|
226
|
+
return function() {
|
227
|
+
_super.call(this);
|
228
|
+
};
|
262
229
|
}
|
263
|
-
|
230
|
+
);
|
264
231
|
}));
|
@@ -0,0 +1,161 @@
|
|
1
|
+
/*!
|
2
|
+
* chai-param
|
3
|
+
* Copyright(c) 2014 The Blacksmith (a.k.a. Saulo Vallory) <jake@alogicalparadox.com>
|
4
|
+
* MIT Licensed
|
5
|
+
*/
|
6
|
+
|
7
|
+
var path = require('path'),
|
8
|
+
chalk = require('chalk'),
|
9
|
+
stackTrace = require('stack-trace'),
|
10
|
+
chai = require('chai'),
|
11
|
+
utils = require('chai/lib/chai/utils');
|
12
|
+
|
13
|
+
var exports = module.exports = chaiParam;
|
14
|
+
|
15
|
+
chaiParam.config = require('./config');
|
16
|
+
|
17
|
+
// chalk wrapper for easy enabling and disabling colors
|
18
|
+
function c(color, text) {
|
19
|
+
if(chaiParam.config.disableColors)
|
20
|
+
return text;
|
21
|
+
|
22
|
+
return chalk[color](text);
|
23
|
+
}
|
24
|
+
|
25
|
+
function chaiParam(chai, utils) {
|
26
|
+
|
27
|
+
if(chaiParam._param)
|
28
|
+
// already initialized
|
29
|
+
return;
|
30
|
+
|
31
|
+
var flag = utils.flag
|
32
|
+
, objDisplay = utils.objDisplay;
|
33
|
+
|
34
|
+
chaiParam._param = function param(val, paramName, functionName, topic) {
|
35
|
+
var assertion = new chai.Assertion(val, functionName);
|
36
|
+
|
37
|
+
utils.flag(assertion, 'paramName', paramName);
|
38
|
+
|
39
|
+
if(functionName && functionName.trim && functionName.trim() != '')
|
40
|
+
utils.flag(assertion, 'functionName', functionName);
|
41
|
+
|
42
|
+
if(topic && topic.trim && topic.trim() != '')
|
43
|
+
utils.flag(assertion, 'message', topic);
|
44
|
+
|
45
|
+
return { should: assertion };
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* ### .param(paramName, functionName)
|
50
|
+
*
|
51
|
+
* The `param` chain allows you provide metadata about
|
52
|
+
* the parameter being validated.
|
53
|
+
*
|
54
|
+
* // examples
|
55
|
+
* expect(text).param('text', 'log').to.be.a('string');
|
56
|
+
* expect(user).param('user', 'register').to.have.length.below(16);
|
57
|
+
*
|
58
|
+
* @name param
|
59
|
+
* @param {String} paramName
|
60
|
+
* @param {String} functionName _optional_ Adding this allows chai-param to look for the caller
|
61
|
+
* @api public
|
62
|
+
*/
|
63
|
+
utils.addMethod(chai.Assertion.prototype, 'param', function(paramName, functionName) {
|
64
|
+
utils.flag(this, 'paramName', paramName);
|
65
|
+
|
66
|
+
if(functionName && functionName.trim && functionName.trim() != '')
|
67
|
+
utils.flag(this, 'functionName', functionName);
|
68
|
+
});
|
69
|
+
|
70
|
+
if(chaiParam.config.improveMessages) {
|
71
|
+
|
72
|
+
// Overwriting getMessages
|
73
|
+
var oldGetMessage = utils.getMessage;
|
74
|
+
utils.getMessage = getMessage;
|
75
|
+
|
76
|
+
function getMessage (obj, args) {
|
77
|
+
|
78
|
+
if(!chaiParam.config.improveMessages)
|
79
|
+
{
|
80
|
+
return oldGetMessage(obj, args);
|
81
|
+
}
|
82
|
+
|
83
|
+
var negate = utils.flag(obj, 'negate')
|
84
|
+
, val = utils.flag(obj, 'object')
|
85
|
+
, expected = args[3]
|
86
|
+
, actual = utils.getActual(obj, args)
|
87
|
+
, msg = negate ? args[2] : args[1]
|
88
|
+
, flagMsg = utils.flag(obj, 'message')
|
89
|
+
, flagParam = utils.flag(obj, 'paramName')
|
90
|
+
, fnTarget = utils.flag(obj, 'functionName');
|
91
|
+
|
92
|
+
msg = msg || '';
|
93
|
+
|
94
|
+
var hasActToken = msg.indexOf('#{act}') >= 0;
|
95
|
+
|
96
|
+
msg = msg
|
97
|
+
.replace(/#{this}/g, flagParam ? 'parameter ' + c('yellow', flagParam) + ' ('+objDisplay(val)+')': objDisplay(val))
|
98
|
+
.replace(/#{act}/g, c('red', objDisplay(actual)))
|
99
|
+
.replace(/#{exp}/g, c('green', objDisplay(expected)))
|
100
|
+
.replace(/(not) to/, c('green', 'not') + ' to').replace(/to not/, 'to ' + c('green', 'not'))
|
101
|
+
.replace(/(length )?(below|at least|above|at most|within)(\s*)([0-9]*)/, c('green', '$1$2$3$4'))
|
102
|
+
.replace(/(include|truthy|falsy|true|false|undefined|match|satisfy|same members as)/, c('green', '$1'))
|
103
|
+
.replace(/(exist|empty|arguments|equal|deeply equal|instance of|be a superset)/, c('green', '$1'));
|
104
|
+
|
105
|
+
if(flagParam && !hasActToken)
|
106
|
+
msg += ' but got ' + c('red', objDisplay(val)) + ' instead';
|
107
|
+
|
108
|
+
var isNode = (typeof window == 'undefined');
|
109
|
+
|
110
|
+
if(chaiParam.config.showCaller && isNode && fnTarget) // show Caller
|
111
|
+
{
|
112
|
+
var trace = stackTrace.get();
|
113
|
+
|
114
|
+
var i = 0;
|
115
|
+
|
116
|
+
if(fnTarget) {
|
117
|
+
while(i < trace.length && trace[i].getFunctionName() != fnTarget) {
|
118
|
+
i++;
|
119
|
+
}
|
120
|
+
|
121
|
+
if(++i < trace.length) {
|
122
|
+
var file = trace[i].getFileName();
|
123
|
+
var filePath = path.dirname(file) + path.sep + c('blue', path.basename(file));
|
124
|
+
|
125
|
+
var spaces = flagMsg ? flagMsg.replace(/./g, ' ') : '';
|
126
|
+
|
127
|
+
msg += '\n' + spaces + ' - Called at: ' + filePath + ':' + c('blue', trace[i].getLineNumber());
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
return flagMsg ? flagMsg + ': ' + msg : msg;
|
133
|
+
};
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* ### param(value, name, function)
|
139
|
+
*
|
140
|
+
* The `param` method allows you to use the should syntax
|
141
|
+
* and still provide metadata about the parameter being validated.
|
142
|
+
*
|
143
|
+
* // examples
|
144
|
+
* param(text, 'text', 'log').should.be.a('string');
|
145
|
+
* param(user, 'user', 'register').should.have.length.below(16);
|
146
|
+
*
|
147
|
+
* @name param
|
148
|
+
* @param {Mixed} value
|
149
|
+
* @param {String} paramName
|
150
|
+
* @param {String} functionName _optional_ Adding this allows chai-param to look for the caller
|
151
|
+
* @param {String} topic _optional_ A prefix for the message
|
152
|
+
* @api public
|
153
|
+
*/
|
154
|
+
chaiParam.param = function param(val, paramName, functionName, topic) {
|
155
|
+
|
156
|
+
if(!chaiParam._param) {
|
157
|
+
throw new Error("You need to add chai-param to chai through `chai.use()` method before using it")
|
158
|
+
}
|
159
|
+
|
160
|
+
return chaiParam._param(val, paramName, functionName, topic);
|
161
|
+
};
|