konacha-chai-matchers 0.0.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.
- data/.gitignore +4 -0
- data/.gitmodules +36 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/konacha-chai-matchers.gemspec +21 -0
- data/lib/konacha-chai-matchers.rb +11 -0
- data/lib/konacha-chai-matchers/version.rb +7 -0
- data/tasks/update.rb +47 -0
- data/vendor/assets/javascripts/chai-as-promised.js +391 -0
- data/vendor/assets/javascripts/chai-backbone.js +101 -0
- data/vendor/assets/javascripts/chai-changes.js +173 -0
- data/vendor/assets/javascripts/chai-factories.js +166 -0
- data/vendor/assets/javascripts/chai-jquery.js +232 -0
- data/vendor/assets/javascripts/chai-null.js +136 -0
- data/vendor/assets/javascripts/chai-spies.js +372 -0
- data/vendor/assets/javascripts/chai-stats.js +286 -0
- data/vendor/assets/javascripts/chai-timers.js +174 -0
- data/vendor/assets/javascripts/js-factories.js +71 -0
- data/vendor/assets/javascripts/sinon-chai.js +106 -0
- data/vendor/assets/javascripts/sinon.js +3738 -0
- metadata +74 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
!function (name, definition) {
|
2
|
+
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
|
3
|
+
else this[name] = definition();
|
4
|
+
}('chai_null', function () {
|
5
|
+
// CommonJS require()
|
6
|
+
function require(p){
|
7
|
+
var path = require.resolve(p)
|
8
|
+
, mod = require.modules[path];
|
9
|
+
if (!mod) throw new Error('failed to require "' + p + '"');
|
10
|
+
if (!mod.exports) {
|
11
|
+
mod.exports = {};
|
12
|
+
mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
13
|
+
}
|
14
|
+
return mod.exports;
|
15
|
+
}
|
16
|
+
|
17
|
+
require.modules = {};
|
18
|
+
|
19
|
+
require.resolve = function (path){
|
20
|
+
var orig = path
|
21
|
+
, reg = path + '.js'
|
22
|
+
, index = path + '/index.js';
|
23
|
+
return require.modules[reg] && reg
|
24
|
+
|| require.modules[index] && index
|
25
|
+
|| orig;
|
26
|
+
};
|
27
|
+
|
28
|
+
require.register = function (path, fn){
|
29
|
+
require.modules[path] = fn;
|
30
|
+
};
|
31
|
+
|
32
|
+
require.relative = function (parent) {
|
33
|
+
return function(p){
|
34
|
+
if ('.' != p[0]) return require(p);
|
35
|
+
|
36
|
+
var path = parent.split('/')
|
37
|
+
, segs = p.split('/');
|
38
|
+
path.pop();
|
39
|
+
|
40
|
+
for (var i = 0; i < segs.length; i++) {
|
41
|
+
var seg = segs[i];
|
42
|
+
if ('..' == seg) path.pop();
|
43
|
+
else if ('.' != seg) path.push(seg);
|
44
|
+
}
|
45
|
+
|
46
|
+
return require(path.join('/'));
|
47
|
+
};
|
48
|
+
};
|
49
|
+
|
50
|
+
|
51
|
+
require.register("null", function (module, exports, require) {
|
52
|
+
/**
|
53
|
+
* Null Object builder.
|
54
|
+
*
|
55
|
+
* @param {Object|Function} [optional] subject
|
56
|
+
* @api public
|
57
|
+
*/
|
58
|
+
function NullObject(subject) {
|
59
|
+
this.object = Object.create(null);
|
60
|
+
this.handle(subject);
|
61
|
+
};
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Handle supplied subject.
|
65
|
+
*
|
66
|
+
* @param {Object|Function} subject
|
67
|
+
* @api private
|
68
|
+
*/
|
69
|
+
NullObject.prototype.handle = function(object) {
|
70
|
+
switch (typeof object) {
|
71
|
+
case 'object': this.object = new Objekt(object); break;
|
72
|
+
case 'function': this.object = new Klass(object); break;
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Builds a null method.
|
78
|
+
*
|
79
|
+
* @param {String} name.
|
80
|
+
* @returns `this`
|
81
|
+
* @api public
|
82
|
+
*/
|
83
|
+
NullObject.prototype.method = function(name) {
|
84
|
+
this.object[name] = function() { return null; };
|
85
|
+
return this;
|
86
|
+
};
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Returns the null object.
|
90
|
+
*
|
91
|
+
* @returns {Object}
|
92
|
+
*/
|
93
|
+
NullObject.prototype.create = function() {
|
94
|
+
return this.object;
|
95
|
+
};
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Null Object builder for objects.
|
99
|
+
*
|
100
|
+
* @param {Object} subject
|
101
|
+
* @api private
|
102
|
+
*/
|
103
|
+
function Objekt(subject) {
|
104
|
+
for (var property in subject) {
|
105
|
+
subject[property] = ('function' === typeof subject[property])
|
106
|
+
? function () { return null; }
|
107
|
+
: null;
|
108
|
+
}
|
109
|
+
|
110
|
+
return subject;
|
111
|
+
};
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Null Object builder for classes.
|
115
|
+
*
|
116
|
+
* @param {Object} subject
|
117
|
+
* @api private
|
118
|
+
*/
|
119
|
+
function Klass(subject) {
|
120
|
+
return new Objekt(new subject);
|
121
|
+
};
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Register `NullObject` as a chai plugin.
|
125
|
+
*/
|
126
|
+
module.exports = function(chai, _) {
|
127
|
+
chai.Null = function(subject) {
|
128
|
+
return new NullObject(subject);
|
129
|
+
};
|
130
|
+
};
|
131
|
+
|
132
|
+
}); // module null
|
133
|
+
return require('null');
|
134
|
+
});
|
135
|
+
|
136
|
+
chai.use(chai_null);
|
@@ -0,0 +1,372 @@
|
|
1
|
+
!function (context, definition) {
|
2
|
+
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
|
3
|
+
module.exports = definition(module, exports);
|
4
|
+
} else {
|
5
|
+
var mod = { exports: {} };
|
6
|
+
definition.call(mod.exports, mod, mod.exports);
|
7
|
+
if (typeof define === 'function' && typeof define.amd === 'object') {
|
8
|
+
define(function () { return mod.exports; });
|
9
|
+
} else {
|
10
|
+
if (!context.chai) throw new Error('Chai cannot be found in current scope.');
|
11
|
+
context.chai.use(mod.exports);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}(this, function (module, exports) {
|
15
|
+
|
16
|
+
|
17
|
+
/*!
|
18
|
+
* chai-spies :: a chai plugin
|
19
|
+
* Copyright (c) 2012 Jake Luer <jake@alogicalparadox.com>
|
20
|
+
* MIT Licensed
|
21
|
+
*/
|
22
|
+
|
23
|
+
/*!
|
24
|
+
* We are going to export a function that can be used through chai
|
25
|
+
*/
|
26
|
+
|
27
|
+
module.exports = function (chai, _) {
|
28
|
+
// Easy access
|
29
|
+
var Assertion = chai.Assertion
|
30
|
+
, flag = _.flag
|
31
|
+
, i = _.inspect
|
32
|
+
|
33
|
+
/**
|
34
|
+
* # chai.spy (function)
|
35
|
+
*
|
36
|
+
* Wraps a function in a proxy function. All calls will
|
37
|
+
* pass through to the original function.
|
38
|
+
*
|
39
|
+
* function original() {}
|
40
|
+
* var spy = chai.spy(original)
|
41
|
+
* , e_spy = chai.spy();
|
42
|
+
*
|
43
|
+
* @param {Function} function to spy on
|
44
|
+
* @returns function to actually call
|
45
|
+
* @api public
|
46
|
+
*/
|
47
|
+
|
48
|
+
chai.spy = function (name, fn) {
|
49
|
+
if (typeof name === 'function') {
|
50
|
+
fn = name;
|
51
|
+
name = undefined;
|
52
|
+
}
|
53
|
+
|
54
|
+
fn = fn || function () {};
|
55
|
+
|
56
|
+
function makeProxy (length, fn) {
|
57
|
+
switch (length) {
|
58
|
+
case 0 : return function () { return fn.apply(this, arguments); };
|
59
|
+
case 1 : return function (a) { return fn.apply(this, arguments); };
|
60
|
+
case 2 : return function (a,b) { return fn.apply(this, arguments); };
|
61
|
+
case 3 : return function (a,b,c) { return fn.apply(this, arguments); };
|
62
|
+
case 4 : return function (a,b,c,d) { return fn.apply(this, arguments); };
|
63
|
+
case 5 : return function (a,b,c,d,e) { return fn.apply(this, arguments); };
|
64
|
+
case 6 : return function (a,b,c,d,e,f) { return fn.apply(this, arguments); };
|
65
|
+
case 7 : return function (a,b,c,d,e,f,g) { return fn.apply(this, arguments); };
|
66
|
+
case 8 : return function (a,b,c,d,e,f,g,h) { return fn.apply(this, arguments); };
|
67
|
+
case 9 : return function (a,b,c,d,e,f,g,h,i) { return fn.apply(this, arguments); };
|
68
|
+
default : return function (a,b,c,d,e,f,g,h,i,j) { return fn.apply(this, arguments); };
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
var proxy = makeProxy(fn.length, function () {
|
73
|
+
var args = Array.prototype.slice.call(arguments);
|
74
|
+
proxy.__spy.calls.push(args);
|
75
|
+
proxy.__spy.called = true;
|
76
|
+
return fn.apply(this, args);
|
77
|
+
});
|
78
|
+
|
79
|
+
proxy.prototype = fn.prototype;
|
80
|
+
proxy.toString = function toString() {
|
81
|
+
var l = this.__spy.calls.length;
|
82
|
+
var s = "{ Spy";
|
83
|
+
if (this.__spy.name)
|
84
|
+
s += " '" + this.__spy.name + "'";
|
85
|
+
if (l > 0)
|
86
|
+
s += ", " + l + " call" + (l > 1 ? 's' : '');
|
87
|
+
s += " }";
|
88
|
+
return s;
|
89
|
+
};
|
90
|
+
proxy.__spy = {
|
91
|
+
calls: []
|
92
|
+
, called: false
|
93
|
+
, name: name
|
94
|
+
};
|
95
|
+
|
96
|
+
return proxy;
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* # spy
|
101
|
+
*
|
102
|
+
* Assert the the object in question is an chai.spy
|
103
|
+
* wrapped function by looking for internals.
|
104
|
+
*
|
105
|
+
* expect(spy).to.be.spy;
|
106
|
+
* spy.should.be.spy;
|
107
|
+
*
|
108
|
+
* @api public
|
109
|
+
*/
|
110
|
+
|
111
|
+
Assertion.addProperty('spy', function () {
|
112
|
+
this.assert(
|
113
|
+
'undefined' !== typeof this._obj.__spy
|
114
|
+
, 'expected ' + this._obj + ' to be a spy'
|
115
|
+
, 'expected ' + this._obj + ' to not be a spy');
|
116
|
+
return this;
|
117
|
+
});
|
118
|
+
|
119
|
+
/**
|
120
|
+
* # .called
|
121
|
+
*
|
122
|
+
* Assert that a spy has been called. Does not negate to allow for
|
123
|
+
* pass through language.
|
124
|
+
*
|
125
|
+
* @api public
|
126
|
+
*/
|
127
|
+
|
128
|
+
function assertCalled (n) {
|
129
|
+
new Assertion(this._obj).to.be.spy;
|
130
|
+
var spy = this._obj.__spy;
|
131
|
+
|
132
|
+
if (n) {
|
133
|
+
this.assert(
|
134
|
+
spy.calls.length === n
|
135
|
+
, 'expected ' + this._obj + ' to have been called #{exp} but got #{act}'
|
136
|
+
, 'expected ' + this._obj + ' to have not been called #{exp}'
|
137
|
+
, n
|
138
|
+
, spy.calls.length
|
139
|
+
);
|
140
|
+
} else {
|
141
|
+
this.assert(
|
142
|
+
spy.called === true
|
143
|
+
, 'expected ' + this._obj + ' to have been called'
|
144
|
+
, 'expected ' + this._ojb + ' to not have been called'
|
145
|
+
);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
function assertCalledChain () {
|
150
|
+
new Assertion(this._obj).to.be.spy;
|
151
|
+
}
|
152
|
+
|
153
|
+
Assertion.addChainableMethod('called', assertCalled, assertCalledChain);
|
154
|
+
|
155
|
+
/**
|
156
|
+
* # once
|
157
|
+
*
|
158
|
+
* Assert that a spy has been called exactly once
|
159
|
+
*
|
160
|
+
* @api public
|
161
|
+
*/
|
162
|
+
|
163
|
+
Assertion.addProperty('once', function () {
|
164
|
+
new Assertion(this._obj).to.be.spy;
|
165
|
+
this.assert(
|
166
|
+
this._obj.__spy.calls.length === 1
|
167
|
+
, 'expected ' + this._obj + ' to have been called once but got #{act}'
|
168
|
+
, 'expected ' + this._obj + ' to not have been called once'
|
169
|
+
, 1
|
170
|
+
, this._obj.__spy.calls.length );
|
171
|
+
});
|
172
|
+
|
173
|
+
/**
|
174
|
+
* # twice
|
175
|
+
*
|
176
|
+
* Assert that a spy has been called exactly twice.
|
177
|
+
*
|
178
|
+
* @api public
|
179
|
+
*/
|
180
|
+
|
181
|
+
Assertion.addProperty('twice', function () {
|
182
|
+
new Assertion(this._obj).to.be.spy;
|
183
|
+
this.assert(
|
184
|
+
this._obj.__spy.calls.length === 2
|
185
|
+
, 'expected ' + this._obj + ' to have been called once but got #{act}'
|
186
|
+
, 'expected ' + this._obj + ' to not have been called once'
|
187
|
+
, 2
|
188
|
+
, this._obj.__spy.calls.length
|
189
|
+
);
|
190
|
+
});
|
191
|
+
|
192
|
+
/**
|
193
|
+
* ### .with
|
194
|
+
*
|
195
|
+
*/
|
196
|
+
|
197
|
+
function assertWith () {
|
198
|
+
new Assertion(this._obj).to.be.spy;
|
199
|
+
var args = [].slice.call(arguments, 0)
|
200
|
+
, calls = this._obj.__spy.calls
|
201
|
+
, always = _.flag(this, 'spy always')
|
202
|
+
, passed;
|
203
|
+
|
204
|
+
if (always) {
|
205
|
+
passed = 0
|
206
|
+
calls.forEach(function (call) {
|
207
|
+
var found = 0;
|
208
|
+
args.forEach(function (arg) {
|
209
|
+
for (var i = 0; i < call.length; i++) {
|
210
|
+
if (_.eql(call[i], arg)) found++;
|
211
|
+
}
|
212
|
+
});
|
213
|
+
if (found === args.length) passed++;
|
214
|
+
});
|
215
|
+
|
216
|
+
this.assert(
|
217
|
+
passed === calls.length
|
218
|
+
, 'expected ' + this._obj + ' to have been always called with #{exp} but got ' + passed + ' out of ' + calls.length
|
219
|
+
, 'expected ' + this._his + ' to have not always been called with #{exp}'
|
220
|
+
, args
|
221
|
+
);
|
222
|
+
} else {
|
223
|
+
passed = 0;
|
224
|
+
calls.forEach(function (call) {
|
225
|
+
var found = 0;
|
226
|
+
args.forEach(function (arg) {
|
227
|
+
for (var i = 0; i < call.length; i++) {
|
228
|
+
if (_.eql(call[i], arg)) found++;
|
229
|
+
}
|
230
|
+
});
|
231
|
+
if (found === args.length) passed++;
|
232
|
+
});
|
233
|
+
|
234
|
+
this.assert(
|
235
|
+
passed > 0
|
236
|
+
, 'expected ' + this._obj + ' to have been called with #{exp}'
|
237
|
+
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
|
238
|
+
, args
|
239
|
+
);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
function assertWithChain () {
|
244
|
+
if ('undefined' !== this._obj.__spy) {
|
245
|
+
_.flag(this, 'spy with', true);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
|
249
|
+
Assertion.addChainableMethod('with', assertWith, assertWithChain);
|
250
|
+
|
251
|
+
Assertion.addProperty('always', function () {
|
252
|
+
if ('undefined' !== this._obj.__spy) {
|
253
|
+
_.flag(this, 'spy always', true);
|
254
|
+
}
|
255
|
+
});
|
256
|
+
|
257
|
+
/**
|
258
|
+
* # exactly (n)
|
259
|
+
*
|
260
|
+
* Assert that a spy has been called exactly `n` times.
|
261
|
+
*
|
262
|
+
* @param {Number} n times
|
263
|
+
* @api public
|
264
|
+
*/
|
265
|
+
|
266
|
+
Assertion.addMethod('exactly', function () {
|
267
|
+
new Assertion(this._obj).to.be.spy;
|
268
|
+
var always = _.flag(this, 'spy always')
|
269
|
+
, _with = _.flag(this, 'spy with')
|
270
|
+
, args = [].slice.call(arguments, 0)
|
271
|
+
, calls = this._obj.__spy.calls
|
272
|
+
, passed;
|
273
|
+
|
274
|
+
if (always && _with) {
|
275
|
+
passed = 0
|
276
|
+
calls.forEach(function (call) {
|
277
|
+
if (call.length !== args.length) return;
|
278
|
+
if (_.eql(call, args)) passed++;
|
279
|
+
});
|
280
|
+
|
281
|
+
this.assert(
|
282
|
+
passed === calls.length
|
283
|
+
, 'expected ' + this._obj + ' to have been always called with exactly #{exp} but got ' + passed + ' out of ' + calls.length
|
284
|
+
, 'expected ' + this._obj + ' to have not always been called with exactly #{exp}'
|
285
|
+
, args
|
286
|
+
);
|
287
|
+
} else if (_with) {
|
288
|
+
passed = 0;
|
289
|
+
calls.forEach(function (call) {
|
290
|
+
if (call.length !== args.length) return;
|
291
|
+
if (_.eql(call, args)) passed++;
|
292
|
+
});
|
293
|
+
|
294
|
+
this.assert(
|
295
|
+
passed > 0
|
296
|
+
, 'expected ' + this._obj + ' to have been called with exactly #{exp}'
|
297
|
+
, 'expected ' + this._obj + ' to not have been called with exactly #{exp} but got ' + passed + ' times'
|
298
|
+
, args
|
299
|
+
);
|
300
|
+
} else {
|
301
|
+
this.assert(
|
302
|
+
this._obj.__spy.calls.length === args[0]
|
303
|
+
, 'expected ' + this._obj + ' to have been called #{exp} times but got #{act}'
|
304
|
+
, 'expected ' + this._obj + ' to not have been called #{exp} times'
|
305
|
+
, args[0]
|
306
|
+
, this._obj.__spy.calls.length
|
307
|
+
);
|
308
|
+
}
|
309
|
+
});
|
310
|
+
|
311
|
+
/**
|
312
|
+
* # gt (n)
|
313
|
+
*
|
314
|
+
* Assert that a spy has been called more than `n` times.
|
315
|
+
*
|
316
|
+
* @param {Number} n times
|
317
|
+
* @api public
|
318
|
+
*/
|
319
|
+
|
320
|
+
function above (_super) {
|
321
|
+
return function (n) {
|
322
|
+
if ('undefined' !== typeof this._obj.__spy) {
|
323
|
+
new Assertion(this._obj).to.be.spy;
|
324
|
+
|
325
|
+
this.assert(
|
326
|
+
this._obj.__spy.calls.length > n
|
327
|
+
, 'expected ' + this._obj + ' to have been called more than #{exp} times but got #{act}'
|
328
|
+
, 'expected ' + this._obj + ' to have been called no more than than #{exp} times but got #{act}'
|
329
|
+
, n
|
330
|
+
, this._obj.__spy.calls.length
|
331
|
+
);
|
332
|
+
} else {
|
333
|
+
_super.apply(this, arguments);
|
334
|
+
}
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
338
|
+
Assertion.overwriteMethod('above', above);
|
339
|
+
Assertion.overwriteMethod('gt', above);
|
340
|
+
|
341
|
+
/**
|
342
|
+
* # lt (n)
|
343
|
+
*
|
344
|
+
* Assert that a spy has been called less than `n` times.
|
345
|
+
*
|
346
|
+
* @param {Number} n times
|
347
|
+
* @api public
|
348
|
+
*/
|
349
|
+
|
350
|
+
function below (_super) {
|
351
|
+
return function (n) {
|
352
|
+
if ('undefined' !== typeof this._obj.__spy) {
|
353
|
+
new Assertion(this._obj).to.be.spy;
|
354
|
+
|
355
|
+
this.assert(
|
356
|
+
this._obj.__spy.calls.length < n
|
357
|
+
, 'expected ' + this._obj + ' to have been called less than #{exp} times but got #{act}'
|
358
|
+
, 'expected ' + this._obj + ' to have been called at least #{exp} times but got #{act}'
|
359
|
+
, n
|
360
|
+
, this._obj.__spy.calls.length
|
361
|
+
);
|
362
|
+
} else {
|
363
|
+
_super.apply(this, arguments);
|
364
|
+
}
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
Assertion.overwriteMethod('below', below);
|
369
|
+
Assertion.overwriteMethod('lt', below);
|
370
|
+
};
|
371
|
+
|
372
|
+
});
|