konacha 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -3
- data/.gitmodules +1 -1
- data/.rspec +1 -0
- data/.travis.yml +9 -0
- data/History.md +8 -2
- data/LICENSE +1 -1
- data/README.md +8 -4
- data/Rakefile +3 -3
- data/konacha.gemspec +2 -5
- data/lib/konacha.rb +1 -1
- data/spec/dummy/spec/javascripts/file_ending_in_test.js +0 -0
- data/spec/konacha_spec.rb +4 -0
- data/vendor/assets/javascripts/chai.js +3120 -0
- data/vendor/assets/javascripts/mocha.js +4139 -0
- data/vendor/assets/stylesheets/mocha.css +163 -0
- metadata +15 -6
- data/Vendorfile +0 -5
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/History.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
# 1.2.0
|
4
|
+
|
5
|
+
* Update mocha (1.0.3) and chai (1.0.0)
|
6
|
+
* Find files ending in `_test.*` as well as `_spec.*`
|
7
|
+
* Fix vendor files for adding konacha through git with bundler
|
8
|
+
|
3
9
|
# 1.1.3
|
4
10
|
|
5
|
-
Update mocha (1.0.1) and chai (0.5.3)
|
11
|
+
* Update mocha (1.0.1) and chai (0.5.3)
|
6
12
|
|
7
13
|
# 1.1.2
|
8
14
|
|
9
|
-
Fix asset deduplication on sprockets < 2.1
|
15
|
+
* Fix asset deduplication on sprockets < 2.1
|
10
16
|
|
11
17
|
# 1.1.1
|
12
18
|
|
data/LICENSE
CHANGED
@@ -67,7 +67,7 @@ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
67
67
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
68
68
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
69
69
|
|
70
|
-
Portions derived from Chai (https://github.com/
|
70
|
+
Portions derived from Chai (https://github.com/chaijs/chai)
|
71
71
|
|
72
72
|
Copyright (c) 2011 Jake Luer <jake@alogicalparadox.com>
|
73
73
|
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Konacha
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/jfirebaugh/konacha.png?branch=master)](http://travis-ci.org/jfirebaugh/konacha)
|
4
|
+
[![Dependency Status](https://gemnasium.com/jfirebaugh/konacha.png)](https://gemnasium.com/jfirebaugh/konacha)
|
5
|
+
|
3
6
|
Konacha is a Rails engine that allows you to test your JavaScript with the
|
4
7
|
[mocha](http://visionmedia.github.com/mocha/) test framework and [chai](http://chaijs.com/)
|
5
8
|
assertion library.
|
@@ -28,9 +31,10 @@ end
|
|
28
31
|
|
29
32
|
## Usage
|
30
33
|
|
31
|
-
Create a `spec/javascripts` directory and name the files in it with a `_spec`
|
32
|
-
You can write the specs in either JavaScript or
|
33
|
-
`.js.coffee` extension respectively, like you
|
34
|
+
Create a `spec/javascripts` directory and name the files in it with a `_spec`
|
35
|
+
(or `_test`) suffix. You can write the specs in either JavaScript or
|
36
|
+
CoffeeScript, using a `.js` or `.js.coffee` extension respectively, like you
|
37
|
+
would any other script asset.
|
34
38
|
|
35
39
|
Require the assets under test and any other dependencies using Sprockets directives.
|
36
40
|
For example, suppose you wanted to test your cool JavaScript `Array#sum` method, which
|
@@ -211,7 +215,7 @@ Run `bundle exec rake` to run the test suite.
|
|
211
215
|
|
212
216
|
The Konacha repository includes the
|
213
217
|
[Mocha](https://github.com/visionmedia/mocha) and
|
214
|
-
[Chai](https://github.com/
|
218
|
+
[Chai](https://github.com/chaijs/chai) repositories as submodules, so
|
215
219
|
you can hack on them directly:
|
216
220
|
|
217
221
|
```bash
|
data/Rakefile
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rspec/core/rake_task"
|
5
5
|
|
6
|
-
RSpec::Core::RakeTask.new :spec
|
6
|
+
RSpec::Core::RakeTask.new :spec
|
7
7
|
|
8
8
|
desc 'Build and copy Mocha and Chai assets from submodules into vendor/assets'
|
9
9
|
task :assets do
|
10
10
|
sh 'git submodule update --init' unless File.exist?('mocha/Makefile') || File.exist?('chai/Makefile')
|
11
|
-
sh 'cd mocha && make
|
12
|
-
sh 'cd chai && make
|
11
|
+
sh 'cd mocha && make clean && make'
|
12
|
+
sh 'cd chai && make clean && make'
|
13
13
|
mkdir_p 'vendor/assets/javascripts'
|
14
14
|
mkdir_p 'vendor/assets/stylesheets'
|
15
15
|
cp 'mocha/mocha.js', 'vendor/assets/javascripts/'
|
data/konacha.gemspec
CHANGED
@@ -13,14 +13,11 @@ the asset pipeline and engines.}
|
|
13
13
|
gem.homepage = "http://github.com/jfirebaugh/konacha"
|
14
14
|
|
15
15
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
-
gem.files = `git ls-files`.split("\n")
|
17
|
-
['vendor/assets/javascripts/mocha.js',
|
18
|
-
'vendor/assets/stylesheets/mocha.css',
|
19
|
-
'vendor/assets/javascripts/chai.js']
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
20
17
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
18
|
gem.name = "konacha"
|
22
19
|
gem.require_paths = ["lib"]
|
23
|
-
gem.version = "1.
|
20
|
+
gem.version = "1.2.0"
|
24
21
|
|
25
22
|
gem.add_dependency "rails", "~> 3.1"
|
26
23
|
gem.add_dependency "capybara"
|
data/lib/konacha.rb
CHANGED
File without changes
|
data/spec/konacha_spec.rb
CHANGED
@@ -26,6 +26,10 @@ describe Konacha do
|
|
26
26
|
it "does not include spec_helper" do
|
27
27
|
subject.should_not include("spec_helper.js")
|
28
28
|
end
|
29
|
+
|
30
|
+
it "includes *_test.* files" do
|
31
|
+
subject.should include("file_ending_in_test.js")
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
it "can be configured in an initializer" do
|
@@ -0,0 +1,3120 @@
|
|
1
|
+
!function (name, definition) {
|
2
|
+
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
|
3
|
+
else this[name] = definition();
|
4
|
+
}('chai', function () {
|
5
|
+
|
6
|
+
// CommonJS require()
|
7
|
+
|
8
|
+
function require(p){
|
9
|
+
var path = require.resolve(p)
|
10
|
+
, mod = require.modules[path];
|
11
|
+
if (!mod) throw new Error('failed to require "' + p + '"');
|
12
|
+
if (!mod.exports) {
|
13
|
+
mod.exports = {};
|
14
|
+
mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
15
|
+
}
|
16
|
+
return mod.exports;
|
17
|
+
}
|
18
|
+
|
19
|
+
require.modules = {};
|
20
|
+
|
21
|
+
require.resolve = function (path){
|
22
|
+
var orig = path
|
23
|
+
, reg = path + '.js'
|
24
|
+
, index = path + '/index.js';
|
25
|
+
return require.modules[reg] && reg
|
26
|
+
|| require.modules[index] && index
|
27
|
+
|| orig;
|
28
|
+
};
|
29
|
+
|
30
|
+
require.register = function (path, fn){
|
31
|
+
require.modules[path] = fn;
|
32
|
+
};
|
33
|
+
|
34
|
+
require.relative = function (parent) {
|
35
|
+
return function(p){
|
36
|
+
if ('.' != p[0]) return require(p);
|
37
|
+
|
38
|
+
var path = parent.split('/')
|
39
|
+
, segs = p.split('/');
|
40
|
+
path.pop();
|
41
|
+
|
42
|
+
for (var i = 0; i < segs.length; i++) {
|
43
|
+
var seg = segs[i];
|
44
|
+
if ('..' == seg) path.pop();
|
45
|
+
else if ('.' != seg) path.push(seg);
|
46
|
+
}
|
47
|
+
|
48
|
+
return require(path.join('/'));
|
49
|
+
};
|
50
|
+
};
|
51
|
+
|
52
|
+
|
53
|
+
require.register("assertion.js", function(module, exports, require){
|
54
|
+
/*!
|
55
|
+
* chai
|
56
|
+
* http://chaijs.com
|
57
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
58
|
+
* MIT Licensed
|
59
|
+
*/
|
60
|
+
|
61
|
+
|
62
|
+
/*!
|
63
|
+
* Module dependencies.
|
64
|
+
*/
|
65
|
+
|
66
|
+
var AssertionError = require('./browser/error')
|
67
|
+
, toString = Object.prototype.toString
|
68
|
+
, util = require('./utils')
|
69
|
+
, flag = util.flag;
|
70
|
+
|
71
|
+
/*!
|
72
|
+
* Module export.
|
73
|
+
*/
|
74
|
+
|
75
|
+
module.exports = Assertion;
|
76
|
+
|
77
|
+
|
78
|
+
/*!
|
79
|
+
* Assertion Constructor
|
80
|
+
*
|
81
|
+
* Creates object for chaining.
|
82
|
+
*
|
83
|
+
* @api private
|
84
|
+
*/
|
85
|
+
|
86
|
+
function Assertion (obj, msg, stack) {
|
87
|
+
flag(this, 'ssfi', stack || arguments.callee);
|
88
|
+
flag(this, 'object', obj);
|
89
|
+
flag(this, 'message', msg);
|
90
|
+
}
|
91
|
+
|
92
|
+
/*!
|
93
|
+
* ### Assertion.includeStack
|
94
|
+
*
|
95
|
+
* User configurable property, influences whether stack trace
|
96
|
+
* is included in Assertion error message. Default of false
|
97
|
+
* suppresses stack trace in the error message
|
98
|
+
*
|
99
|
+
* Assertion.includeStack = true; // enable stack on error
|
100
|
+
*
|
101
|
+
* @api public
|
102
|
+
*/
|
103
|
+
|
104
|
+
Assertion.includeStack = false;
|
105
|
+
|
106
|
+
Assertion.addProperty = function (name, fn) {
|
107
|
+
util.addProperty(this.prototype, name, fn);
|
108
|
+
};
|
109
|
+
|
110
|
+
Assertion.addMethod = function (name, fn) {
|
111
|
+
util.addMethod(this.prototype, name, fn);
|
112
|
+
};
|
113
|
+
|
114
|
+
Assertion.overwriteProperty = function (name, fn) {
|
115
|
+
util.overwriteProperty(this.prototype, name, fn);
|
116
|
+
};
|
117
|
+
|
118
|
+
Assertion.overwriteMethod = function (name, fn) {
|
119
|
+
util.overwriteMethod(this.prototype, name, fn);
|
120
|
+
};
|
121
|
+
|
122
|
+
/*!
|
123
|
+
* ### .assert(expression, message, negateMessage, expected, actual)
|
124
|
+
*
|
125
|
+
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
126
|
+
*
|
127
|
+
* @name assert
|
128
|
+
* @param {Philosophical} expression to be tested
|
129
|
+
* @param {String} message to display if fails
|
130
|
+
* @param {String} negatedMessage to display if negated expression fails
|
131
|
+
* @param {Mixed} expected value (remember to check for negation)
|
132
|
+
* @param {Mixed} actual (optional) will default to `this.obj`
|
133
|
+
* @api private
|
134
|
+
*/
|
135
|
+
|
136
|
+
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual) {
|
137
|
+
var msg = util.getMessage(this, arguments)
|
138
|
+
, actual = util.getActual(this, arguments)
|
139
|
+
, ok = util.test(this, arguments);
|
140
|
+
|
141
|
+
if (!ok) {
|
142
|
+
throw new AssertionError({
|
143
|
+
message: msg
|
144
|
+
, actual: actual
|
145
|
+
, expected: expected
|
146
|
+
, stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
|
147
|
+
});
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
151
|
+
/*!
|
152
|
+
*
|
153
|
+
* ### ._obj
|
154
|
+
*
|
155
|
+
* Quick reference to stored `actual` value for plugin developers.
|
156
|
+
*
|
157
|
+
* @api private
|
158
|
+
*/
|
159
|
+
|
160
|
+
Object.defineProperty(Assertion.prototype, '_obj',
|
161
|
+
{ get: function () {
|
162
|
+
return flag(this, 'object');
|
163
|
+
}
|
164
|
+
, set: function (val) {
|
165
|
+
flag(this, 'object', val);
|
166
|
+
}
|
167
|
+
});
|
168
|
+
|
169
|
+
/**
|
170
|
+
* ### Language Chains
|
171
|
+
*
|
172
|
+
* The following are provide as chainable getters to
|
173
|
+
* improve the readability of your assertions. They
|
174
|
+
* do not provide an testing capability unless they
|
175
|
+
* have been overwritten by a plugin.
|
176
|
+
*
|
177
|
+
* **Chains**
|
178
|
+
*
|
179
|
+
* - to
|
180
|
+
* - be
|
181
|
+
* - been
|
182
|
+
* - is
|
183
|
+
* - and
|
184
|
+
* - have
|
185
|
+
* - with
|
186
|
+
*
|
187
|
+
* @name language chains
|
188
|
+
* @api public
|
189
|
+
*/
|
190
|
+
|
191
|
+
[ 'to', 'be', 'been'
|
192
|
+
, 'is', 'and', 'have'
|
193
|
+
, 'with' ].forEach(function (chain) {
|
194
|
+
Object.defineProperty(Assertion.prototype, chain,
|
195
|
+
{ get: function () {
|
196
|
+
return this;
|
197
|
+
}
|
198
|
+
, configurable: true
|
199
|
+
});
|
200
|
+
});
|
201
|
+
|
202
|
+
/**
|
203
|
+
* ### .not
|
204
|
+
*
|
205
|
+
* Negates any of assertions following in the chain.
|
206
|
+
*
|
207
|
+
* expect(foo).to.not.equal('bar');
|
208
|
+
* expect(goodFn).to.not.throw(Error);
|
209
|
+
* expect({ foo: 'baz' }).to.have.property('foo')
|
210
|
+
* .and.not.equal('bar');
|
211
|
+
*
|
212
|
+
* @name not
|
213
|
+
* @api public
|
214
|
+
*/
|
215
|
+
|
216
|
+
Object.defineProperty(Assertion.prototype, 'not',
|
217
|
+
{ get: function () {
|
218
|
+
flag(this, 'negate', true);
|
219
|
+
return this;
|
220
|
+
}
|
221
|
+
, configurable: true
|
222
|
+
});
|
223
|
+
|
224
|
+
/**
|
225
|
+
* ### .a(type)
|
226
|
+
*
|
227
|
+
* The `a` and `an` assertions are aliases that can be
|
228
|
+
* used either as property languague chains or to assert
|
229
|
+
* typeof.
|
230
|
+
*
|
231
|
+
* // typeof
|
232
|
+
* expect('test').to.be.a('string');
|
233
|
+
* expect({ foo: 'bar' }).to.be.an('object');
|
234
|
+
*
|
235
|
+
* // language chain
|
236
|
+
* expect(foo).to.be.an.instanceof(Foo);
|
237
|
+
*
|
238
|
+
* @name a
|
239
|
+
* @alias an
|
240
|
+
* @param {String} type
|
241
|
+
* @api public
|
242
|
+
*/
|
243
|
+
|
244
|
+
var an = function () {
|
245
|
+
var assert = function(type) {
|
246
|
+
var obj = flag(this, 'object')
|
247
|
+
, klass = type.charAt(0).toUpperCase() + type.slice(1);
|
248
|
+
|
249
|
+
this.assert(
|
250
|
+
'[object ' + klass + ']' === toString.call(obj)
|
251
|
+
, 'expected #{this} to be a ' + type
|
252
|
+
, 'expected #{this} not to be a ' + type
|
253
|
+
, '[object ' + klass + ']'
|
254
|
+
, toString.call(obj)
|
255
|
+
);
|
256
|
+
|
257
|
+
return this;
|
258
|
+
};
|
259
|
+
|
260
|
+
assert.__proto__ = this;
|
261
|
+
return assert;
|
262
|
+
};
|
263
|
+
|
264
|
+
Object.defineProperty(Assertion.prototype, 'an',
|
265
|
+
{ get: an
|
266
|
+
, configurable: true
|
267
|
+
});
|
268
|
+
|
269
|
+
Object.defineProperty(Assertion.prototype, 'a',
|
270
|
+
{ get: an
|
271
|
+
, configurable: true
|
272
|
+
});
|
273
|
+
|
274
|
+
/**
|
275
|
+
* ### .include(value)
|
276
|
+
*
|
277
|
+
* The `include` and `contain` assertions can be used as either a property
|
278
|
+
* based language chain or as a method to assert the inclusion of an object
|
279
|
+
* in an Array or substring in string. When used as a property langugae chain,
|
280
|
+
* it toggles the `contain` flag for the `keys` assertion.
|
281
|
+
*
|
282
|
+
* expect([1,2,3]).to.include(2);
|
283
|
+
* expect('foobar').to.contain('foo');
|
284
|
+
* expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
|
285
|
+
*
|
286
|
+
* @name include
|
287
|
+
* @alias contain
|
288
|
+
* @param {Object|String|Number} obj
|
289
|
+
* @api public
|
290
|
+
*/
|
291
|
+
|
292
|
+
var include = function () {
|
293
|
+
flag(this, 'contains', true);
|
294
|
+
|
295
|
+
var assert = function(val) {
|
296
|
+
var obj = flag(this, 'object')
|
297
|
+
this.assert(
|
298
|
+
~obj.indexOf(val)
|
299
|
+
, 'expected #{this} to include ' + util.inspect(val)
|
300
|
+
, 'expected #{this} to not include ' + util.inspect(val));
|
301
|
+
|
302
|
+
return this;
|
303
|
+
};
|
304
|
+
|
305
|
+
assert.__proto__ = this;
|
306
|
+
return assert;
|
307
|
+
};
|
308
|
+
|
309
|
+
Object.defineProperty(Assertion.prototype, 'contain',
|
310
|
+
{ get: include
|
311
|
+
, configurable: true
|
312
|
+
});
|
313
|
+
|
314
|
+
Object.defineProperty(Assertion.prototype, 'include',
|
315
|
+
{ get: include
|
316
|
+
, configurable: true
|
317
|
+
});
|
318
|
+
|
319
|
+
/**
|
320
|
+
* ### .ok
|
321
|
+
*
|
322
|
+
* Assert object truthiness.
|
323
|
+
*
|
324
|
+
* expect('everthing').to.be.ok;
|
325
|
+
* expect(1).to.be.ok;
|
326
|
+
* expect(false).to.not.be.ok;
|
327
|
+
* expect(undefined).to.not.be.ok;
|
328
|
+
* expect(null).to.not.be.ok;
|
329
|
+
*
|
330
|
+
* @name ok
|
331
|
+
* @api public
|
332
|
+
*/
|
333
|
+
|
334
|
+
Object.defineProperty(Assertion.prototype, 'ok',
|
335
|
+
{ get: function () {
|
336
|
+
this.assert(
|
337
|
+
flag(this, 'object')
|
338
|
+
, 'expected #{this} to be truthy'
|
339
|
+
, 'expected #{this} to be falsy');
|
340
|
+
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
, configurable: true
|
344
|
+
});
|
345
|
+
|
346
|
+
/**
|
347
|
+
* ### .true
|
348
|
+
*
|
349
|
+
* Assert object is true
|
350
|
+
*
|
351
|
+
* expect(true).to.be.true;
|
352
|
+
* expect(1).to.not.be.true;
|
353
|
+
*
|
354
|
+
* @name true
|
355
|
+
* @api public
|
356
|
+
*/
|
357
|
+
|
358
|
+
Object.defineProperty(Assertion.prototype, 'true',
|
359
|
+
{ get: function () {
|
360
|
+
this.assert(
|
361
|
+
true === flag(this, 'object')
|
362
|
+
, 'expected #{this} to be true'
|
363
|
+
, 'expected #{this} to be false'
|
364
|
+
, this.negate ? false : true
|
365
|
+
);
|
366
|
+
|
367
|
+
return this;
|
368
|
+
}
|
369
|
+
, configurable: true
|
370
|
+
});
|
371
|
+
|
372
|
+
/**
|
373
|
+
* ### .false
|
374
|
+
*
|
375
|
+
* Assert object is false
|
376
|
+
*
|
377
|
+
* expect(false).to.be.false;
|
378
|
+
* expect(0).to.not.be.false;
|
379
|
+
*
|
380
|
+
* @name false
|
381
|
+
* @api public
|
382
|
+
*/
|
383
|
+
|
384
|
+
Object.defineProperty(Assertion.prototype, 'false',
|
385
|
+
{ get: function () {
|
386
|
+
this.assert(
|
387
|
+
false === flag(this, 'object')
|
388
|
+
, 'expected #{this} to be false'
|
389
|
+
, 'expected #{this} to be true'
|
390
|
+
, this.negate ? true : false
|
391
|
+
);
|
392
|
+
|
393
|
+
return this;
|
394
|
+
}
|
395
|
+
, configurable: true
|
396
|
+
});
|
397
|
+
|
398
|
+
/**
|
399
|
+
* ### .null
|
400
|
+
*
|
401
|
+
* Assert object is null
|
402
|
+
*
|
403
|
+
* expect(null).to.be.null;
|
404
|
+
* expect(undefined).not.to.be.null;
|
405
|
+
*
|
406
|
+
* @name null
|
407
|
+
* @api public
|
408
|
+
*/
|
409
|
+
|
410
|
+
Object.defineProperty(Assertion.prototype, 'null',
|
411
|
+
{ get: function () {
|
412
|
+
this.assert(
|
413
|
+
null === flag(this, 'object')
|
414
|
+
, 'expected #{this} to be null'
|
415
|
+
, 'expected #{this} not to be null'
|
416
|
+
, this.negate ? false : true
|
417
|
+
);
|
418
|
+
|
419
|
+
return this;
|
420
|
+
}
|
421
|
+
, configurable: true
|
422
|
+
});
|
423
|
+
|
424
|
+
/**
|
425
|
+
* ### .undefined
|
426
|
+
*
|
427
|
+
* Assert object is undefined
|
428
|
+
*
|
429
|
+
* expect(undefined).to.be.undefined;
|
430
|
+
* expect(null).to.not.be.undefined;
|
431
|
+
*
|
432
|
+
* @name undefined
|
433
|
+
* @api public
|
434
|
+
*/
|
435
|
+
|
436
|
+
Object.defineProperty(Assertion.prototype, 'undefined',
|
437
|
+
{ get: function () {
|
438
|
+
this.assert(
|
439
|
+
undefined === flag(this, 'object')
|
440
|
+
, 'expected #{this} to be undefined'
|
441
|
+
, 'expected #{this} not to be undefined'
|
442
|
+
, this.negate ? false : true
|
443
|
+
);
|
444
|
+
|
445
|
+
return this;
|
446
|
+
}
|
447
|
+
, configurable: true
|
448
|
+
});
|
449
|
+
|
450
|
+
/**
|
451
|
+
* ### .exist
|
452
|
+
*
|
453
|
+
* Assert object exists (null).
|
454
|
+
*
|
455
|
+
* var foo = 'hi'
|
456
|
+
* , bar;
|
457
|
+
*
|
458
|
+
* expect(foo).to.exist;
|
459
|
+
* expect(bar).to.not.exist;
|
460
|
+
*
|
461
|
+
* @name exist
|
462
|
+
* @api public
|
463
|
+
*/
|
464
|
+
|
465
|
+
Object.defineProperty(Assertion.prototype, 'exist',
|
466
|
+
{ get: function () {
|
467
|
+
this.assert(
|
468
|
+
null != flag(this, 'object')
|
469
|
+
, 'expected #{this} to exist'
|
470
|
+
, 'expected #{this} to not exist'
|
471
|
+
);
|
472
|
+
|
473
|
+
return this;
|
474
|
+
}
|
475
|
+
, configurable: true
|
476
|
+
});
|
477
|
+
|
478
|
+
/**
|
479
|
+
* ### .empty
|
480
|
+
*
|
481
|
+
* Assert object's length to be `0`. For arrays, it check
|
482
|
+
* the length property. For objects it gets the count of
|
483
|
+
* enumerable keys.
|
484
|
+
*
|
485
|
+
* expect([]).to.be.empty;
|
486
|
+
* expect('').to.be.empty;
|
487
|
+
* expect({}).to.be.empty;
|
488
|
+
*
|
489
|
+
* @name empty
|
490
|
+
* @api public
|
491
|
+
*/
|
492
|
+
|
493
|
+
Object.defineProperty(Assertion.prototype, 'empty',
|
494
|
+
{ get: function () {
|
495
|
+
var obj = flag(this, 'object')
|
496
|
+
, expected = obj;
|
497
|
+
|
498
|
+
if (Array.isArray(obj) || 'string' === typeof object) {
|
499
|
+
expected = obj.length;
|
500
|
+
} else if (typeof obj === 'object') {
|
501
|
+
expected = Object.keys(obj).length;
|
502
|
+
}
|
503
|
+
|
504
|
+
this.assert(
|
505
|
+
!expected
|
506
|
+
, 'expected #{this} to be empty'
|
507
|
+
, 'expected #{this} not to be empty');
|
508
|
+
|
509
|
+
return this;
|
510
|
+
}
|
511
|
+
, configurable: true
|
512
|
+
});
|
513
|
+
|
514
|
+
/**
|
515
|
+
* ### .arguments
|
516
|
+
*
|
517
|
+
* Assert object is an instanceof arguments.
|
518
|
+
*
|
519
|
+
* function test () {
|
520
|
+
* expect(arguments).to.be.arguments;
|
521
|
+
* }
|
522
|
+
*
|
523
|
+
* @name arguments
|
524
|
+
* @api public
|
525
|
+
*/
|
526
|
+
|
527
|
+
Object.defineProperty(Assertion.prototype, 'arguments',
|
528
|
+
{ get: function () {
|
529
|
+
var obj = flag(this, 'object');
|
530
|
+
this.assert(
|
531
|
+
'[object Arguments]' == Object.prototype.toString.call(obj)
|
532
|
+
, 'expected #{this} to be arguments'
|
533
|
+
, 'expected #{this} to not be arguments'
|
534
|
+
, '[object Arguments]'
|
535
|
+
, Object.prototype.toString.call(obj)
|
536
|
+
);
|
537
|
+
|
538
|
+
return this;
|
539
|
+
}
|
540
|
+
, configurable: true
|
541
|
+
});
|
542
|
+
|
543
|
+
/**
|
544
|
+
* ### .equal(value)
|
545
|
+
*
|
546
|
+
* Assert strict equality (===).
|
547
|
+
*
|
548
|
+
* expect('hello').to.equal('hello');
|
549
|
+
* expect(42).to.equal(42);
|
550
|
+
* expect(1).to.not.equal(true);
|
551
|
+
*
|
552
|
+
* @name equal
|
553
|
+
* @param {Mixed} value
|
554
|
+
* @api public
|
555
|
+
*/
|
556
|
+
|
557
|
+
Assertion.prototype.equal = function (val) {
|
558
|
+
this.assert(
|
559
|
+
val === flag(this, 'object')
|
560
|
+
, 'expected #{this} to equal #{exp}'
|
561
|
+
, 'expected #{this} to not equal #{exp}'
|
562
|
+
, val );
|
563
|
+
|
564
|
+
return this;
|
565
|
+
};
|
566
|
+
|
567
|
+
/**
|
568
|
+
* ### .eql(value)
|
569
|
+
*
|
570
|
+
* Assert deep equality.
|
571
|
+
*
|
572
|
+
* expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
|
573
|
+
* expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
|
574
|
+
*
|
575
|
+
* @name eql
|
576
|
+
* @param {*} value
|
577
|
+
* @api public
|
578
|
+
*/
|
579
|
+
|
580
|
+
Assertion.prototype.eql = function (obj) {
|
581
|
+
this.assert(
|
582
|
+
util.eql(obj, flag(this, 'object'))
|
583
|
+
, 'expected #{this} to equal #{exp}'
|
584
|
+
, 'expected #{this} to not equal #{exp}'
|
585
|
+
, obj );
|
586
|
+
|
587
|
+
return this;
|
588
|
+
};
|
589
|
+
|
590
|
+
/**
|
591
|
+
* ### .above(value)
|
592
|
+
*
|
593
|
+
* Assert greater than `value`.
|
594
|
+
*
|
595
|
+
* expect(10).to.be.above(5);
|
596
|
+
*
|
597
|
+
* @name above
|
598
|
+
* @alias gt
|
599
|
+
* @param {Number} value
|
600
|
+
* @api public
|
601
|
+
*/
|
602
|
+
|
603
|
+
Assertion.prototype.above = function (val) {
|
604
|
+
this.assert(
|
605
|
+
flag(this, 'object') > val
|
606
|
+
, 'expected #{this} to be above ' + val
|
607
|
+
, 'expected #{this} to be below ' + val);
|
608
|
+
|
609
|
+
return this;
|
610
|
+
};
|
611
|
+
|
612
|
+
/**
|
613
|
+
* ### .below(value)
|
614
|
+
*
|
615
|
+
* Assert less than `value`.
|
616
|
+
*
|
617
|
+
* expect(5).to.be.below(10);
|
618
|
+
*
|
619
|
+
* @name below
|
620
|
+
* @alias lt
|
621
|
+
* @param {Number} value
|
622
|
+
* @api public
|
623
|
+
*/
|
624
|
+
|
625
|
+
Assertion.prototype.below = function (val) {
|
626
|
+
this.assert(
|
627
|
+
flag(this, 'object') < val
|
628
|
+
, 'expected #{this} to be below ' + val
|
629
|
+
, 'expected #{this} to be above ' + val);
|
630
|
+
|
631
|
+
return this;
|
632
|
+
};
|
633
|
+
|
634
|
+
/**
|
635
|
+
* ### .within(start, finish)
|
636
|
+
*
|
637
|
+
* Assert that a number is within a range.
|
638
|
+
*
|
639
|
+
* expect(7).to.be.within(5,10);
|
640
|
+
*
|
641
|
+
* @name within
|
642
|
+
* @param {Number} start lowerbound inclusive
|
643
|
+
* @param {Number} finish upperbound inclusive
|
644
|
+
* @api public
|
645
|
+
*/
|
646
|
+
|
647
|
+
Assertion.prototype.within = function (start, finish) {
|
648
|
+
var obj = flag(this, 'object')
|
649
|
+
, range = start + '..' + finish;
|
650
|
+
|
651
|
+
this.assert(
|
652
|
+
obj >= start && obj <= finish
|
653
|
+
, 'expected #{this} to be within ' + range
|
654
|
+
, 'expected #{this} to not be within ' + range);
|
655
|
+
|
656
|
+
return this;
|
657
|
+
};
|
658
|
+
|
659
|
+
/**
|
660
|
+
* ### .instanceof(constructor)
|
661
|
+
*
|
662
|
+
* Assert instanceof.
|
663
|
+
*
|
664
|
+
* var Tea = function (name) { this.name = name; }
|
665
|
+
* , Chai = new Tea('chai');
|
666
|
+
*
|
667
|
+
* expect(Chai).to.be.an.instanceof(Tea);
|
668
|
+
* expect([ 1, 2, 3 ]).to.be.instanceof(Array);
|
669
|
+
*
|
670
|
+
* @name instanceof
|
671
|
+
* @param {Constructor}
|
672
|
+
* @alias instanceOf
|
673
|
+
* @api public
|
674
|
+
*/
|
675
|
+
|
676
|
+
Assertion.prototype.instanceOf = function (constructor) {
|
677
|
+
var name = util.getName(constructor);
|
678
|
+
this.assert(
|
679
|
+
flag(this, 'object') instanceof constructor
|
680
|
+
, 'expected #{this} to be an instance of ' + name
|
681
|
+
, 'expected #{this} to not be an instance of ' + name);
|
682
|
+
|
683
|
+
return this;
|
684
|
+
};
|
685
|
+
|
686
|
+
/**
|
687
|
+
* ### .property(name, [value])
|
688
|
+
*
|
689
|
+
* Assert that property of `name` exists, optionally with `value`.
|
690
|
+
* Can use dot-notation for deep reference.
|
691
|
+
*
|
692
|
+
* // legacy / simple referencing
|
693
|
+
* var obj = { foo: 'bar' }
|
694
|
+
* expect(obj).to.have.property('foo');
|
695
|
+
* expect(obj).to.have.property('foo', 'bar');
|
696
|
+
* expect(obj).to.have.property('foo').to.be.a('string');
|
697
|
+
*
|
698
|
+
* // deep referencing
|
699
|
+
* var deepObj = {
|
700
|
+
* green: { tea: 'matcha' }
|
701
|
+
* , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
|
702
|
+
* };
|
703
|
+
|
704
|
+
* expect(deepObj).to.have.property('green.tea', 'matcha');
|
705
|
+
* expect(deepObj).to.have.property('teas[1]', 'matcha');
|
706
|
+
* expect(deepObj).to.have.property('teas[2].tea', 'konacha');
|
707
|
+
*
|
708
|
+
* @name property
|
709
|
+
* @param {String} name
|
710
|
+
* @param {Mixed} value (optional)
|
711
|
+
* @returns value of property for chaining
|
712
|
+
* @api public
|
713
|
+
*/
|
714
|
+
|
715
|
+
Assertion.prototype.property = function (name, val) {
|
716
|
+
var obj = flag(this, 'object')
|
717
|
+
, value = util.getPathValue(name, obj)
|
718
|
+
, negate = flag(this, 'negate');
|
719
|
+
|
720
|
+
if (negate && undefined !== val) {
|
721
|
+
if (undefined === value) {
|
722
|
+
throw new Error(util.inspect(obj) + ' has no property ' + util.inspect(name));
|
723
|
+
}
|
724
|
+
} else {
|
725
|
+
this.assert(
|
726
|
+
undefined !== value
|
727
|
+
, 'expected #{this} to have a property ' + util.inspect(name)
|
728
|
+
, 'expected #{this} to not have property ' + util.inspect(name));
|
729
|
+
}
|
730
|
+
|
731
|
+
if (undefined !== val) {
|
732
|
+
this.assert(
|
733
|
+
val === value
|
734
|
+
, 'expected #{this} to have a property ' + util.inspect(name) + ' of #{exp}, but got #{act}'
|
735
|
+
, 'expected #{this} to not have a property ' + util.inspect(name) + ' of #{act}'
|
736
|
+
, val
|
737
|
+
, value
|
738
|
+
);
|
739
|
+
}
|
740
|
+
|
741
|
+
flag(this, 'object', value);
|
742
|
+
return this;
|
743
|
+
};
|
744
|
+
|
745
|
+
/**
|
746
|
+
* ### .ownProperty(name)
|
747
|
+
*
|
748
|
+
* Assert that has own property by `name`.
|
749
|
+
*
|
750
|
+
* expect('test').to.have.ownProperty('length');
|
751
|
+
*
|
752
|
+
* @name ownProperty
|
753
|
+
* @alias haveOwnProperty
|
754
|
+
* @param {String} name
|
755
|
+
* @api public
|
756
|
+
*/
|
757
|
+
|
758
|
+
Assertion.prototype.ownProperty = function (name) {
|
759
|
+
var obj = flag(this, 'object');
|
760
|
+
this.assert(
|
761
|
+
obj.hasOwnProperty(name)
|
762
|
+
, 'expected #{this} to have own property ' + util.inspect(name)
|
763
|
+
, 'expected #{this} to not have own property ' + util.inspect(name));
|
764
|
+
return this;
|
765
|
+
};
|
766
|
+
|
767
|
+
/**
|
768
|
+
* ### .length(val)
|
769
|
+
*
|
770
|
+
* Assert that object has expected length.
|
771
|
+
*
|
772
|
+
* expect([1,2,3]).to.have.length(3);
|
773
|
+
* expect('foobar').to.have.length(6);
|
774
|
+
*
|
775
|
+
* @name length
|
776
|
+
* @alias lengthOf
|
777
|
+
* @param {Number} length
|
778
|
+
* @api public
|
779
|
+
*/
|
780
|
+
|
781
|
+
Assertion.prototype.length = function (n) {
|
782
|
+
var obj = flag(this, 'object');
|
783
|
+
new Assertion(obj).to.have.property('length');
|
784
|
+
var len = obj.length;
|
785
|
+
|
786
|
+
this.assert(
|
787
|
+
len == n
|
788
|
+
, 'expected #{this} to have a length of #{exp} but got #{act}'
|
789
|
+
, 'expected #{this} to not have a length of #{act}'
|
790
|
+
, n
|
791
|
+
, len
|
792
|
+
);
|
793
|
+
|
794
|
+
return this;
|
795
|
+
};
|
796
|
+
|
797
|
+
/**
|
798
|
+
* ### .match(regexp)
|
799
|
+
*
|
800
|
+
* Assert that matches regular expression.
|
801
|
+
*
|
802
|
+
* expect('foobar').to.match(/^foo/);
|
803
|
+
*
|
804
|
+
* @name match
|
805
|
+
* @param {RegExp} RegularExpression
|
806
|
+
* @api public
|
807
|
+
*/
|
808
|
+
|
809
|
+
Assertion.prototype.match = function (re) {
|
810
|
+
var obj = flag(this, 'object');
|
811
|
+
this.assert(
|
812
|
+
re.exec(obj)
|
813
|
+
, 'expected #{this} to match ' + re
|
814
|
+
, 'expected #{this} not to match ' + re);
|
815
|
+
|
816
|
+
return this;
|
817
|
+
};
|
818
|
+
|
819
|
+
|
820
|
+
/**
|
821
|
+
* ### .string(string)
|
822
|
+
*
|
823
|
+
* Assert inclusion of string in string.
|
824
|
+
*
|
825
|
+
* expect('foobar').to.have.string('bar');
|
826
|
+
*
|
827
|
+
* @name string
|
828
|
+
* @param {String} string
|
829
|
+
* @api public
|
830
|
+
*/
|
831
|
+
|
832
|
+
Assertion.prototype.string = function (str) {
|
833
|
+
var obj = flag(this, 'object');
|
834
|
+
new Assertion(obj).is.a('string');
|
835
|
+
|
836
|
+
this.assert(
|
837
|
+
~obj.indexOf(str)
|
838
|
+
, 'expected #{this} to contain ' + util.inspect(str)
|
839
|
+
, 'expected #{this} to not contain ' + util.inspect(str));
|
840
|
+
|
841
|
+
return this;
|
842
|
+
};
|
843
|
+
|
844
|
+
/**
|
845
|
+
* ### .keys(key1, [key2], [...])
|
846
|
+
*
|
847
|
+
* Assert exact keys or the inclusing of keys
|
848
|
+
* using the `include` or `contain` modifier.
|
849
|
+
*
|
850
|
+
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
|
851
|
+
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
|
852
|
+
*
|
853
|
+
* @name keys
|
854
|
+
* @alias key
|
855
|
+
* @param {String|Array} Keys
|
856
|
+
* @api public
|
857
|
+
*/
|
858
|
+
|
859
|
+
Assertion.prototype.keys = function(keys) {
|
860
|
+
var obj = flag(this, 'object')
|
861
|
+
, str
|
862
|
+
, ok = true;
|
863
|
+
|
864
|
+
keys = keys instanceof Array
|
865
|
+
? keys
|
866
|
+
: Array.prototype.slice.call(arguments);
|
867
|
+
|
868
|
+
if (!keys.length) throw new Error('keys required');
|
869
|
+
|
870
|
+
var actual = Object.keys(obj)
|
871
|
+
, len = keys.length;
|
872
|
+
|
873
|
+
// Inclusion
|
874
|
+
ok = keys.every(function(key){
|
875
|
+
return ~actual.indexOf(key);
|
876
|
+
});
|
877
|
+
|
878
|
+
// Strict
|
879
|
+
if (!flag(this, 'negate') && !flag(this, 'contains')) {
|
880
|
+
ok = ok && keys.length == actual.length;
|
881
|
+
}
|
882
|
+
|
883
|
+
// Key string
|
884
|
+
if (len > 1) {
|
885
|
+
keys = keys.map(function(key){
|
886
|
+
return util.inspect(key);
|
887
|
+
});
|
888
|
+
var last = keys.pop();
|
889
|
+
str = keys.join(', ') + ', and ' + last;
|
890
|
+
} else {
|
891
|
+
str = util.inspect(keys[0]);
|
892
|
+
}
|
893
|
+
|
894
|
+
// Form
|
895
|
+
str = (len > 1 ? 'keys ' : 'key ') + str;
|
896
|
+
|
897
|
+
// Have / include
|
898
|
+
str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
|
899
|
+
|
900
|
+
// Assertion
|
901
|
+
this.assert(
|
902
|
+
ok
|
903
|
+
, 'expected #{this} to ' + str
|
904
|
+
, 'expected #{this} to not ' + str
|
905
|
+
, keys
|
906
|
+
, Object.keys(obj)
|
907
|
+
);
|
908
|
+
|
909
|
+
return this;
|
910
|
+
}
|
911
|
+
|
912
|
+
/**
|
913
|
+
* ### .throw(constructor)
|
914
|
+
*
|
915
|
+
* Assert that a function will throw a specific type of error, or specific type of error
|
916
|
+
* (as determined using `instanceof`), optionally with a RegExp or string inclusion test
|
917
|
+
* for the error's message.
|
918
|
+
*
|
919
|
+
* var err = new ReferenceError('This is a bad function.');
|
920
|
+
* var fn = function () { throw err; }
|
921
|
+
* expect(fn).to.throw(ReferenceError);
|
922
|
+
* expect(fn).to.throw(Error);
|
923
|
+
* expect(fn).to.throw(/bad function/);
|
924
|
+
* expect(fn).to.not.throw('good function');
|
925
|
+
* expect(fn).to.throw(ReferenceError, /bad function/);
|
926
|
+
* expect(fn).to.throw(err);
|
927
|
+
* expect(fn).to.not.throw(new RangeError('Out of range.'));
|
928
|
+
*
|
929
|
+
* Please note that when a throw expectation is negated, it will check each
|
930
|
+
* parameter independently, starting with error constructor type. The appropriate way
|
931
|
+
* to check for the existence of a type of error but for a message that does not match
|
932
|
+
* is to use `and`.
|
933
|
+
*
|
934
|
+
* expect(fn).to.throw(ReferenceError)
|
935
|
+
* .and.not.throw(/good function/);
|
936
|
+
*
|
937
|
+
* @name throw
|
938
|
+
* @alias throws
|
939
|
+
* @alias Throw
|
940
|
+
* @param {ErrorConstructor} constructor
|
941
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
942
|
+
* @api public
|
943
|
+
*/
|
944
|
+
|
945
|
+
Assertion.prototype.Throw = function (constructor, msg) {
|
946
|
+
var obj = flag(this, 'object');
|
947
|
+
new Assertion(obj).is.a('function');
|
948
|
+
|
949
|
+
var thrown = false
|
950
|
+
, desiredError = null
|
951
|
+
, name = null;
|
952
|
+
|
953
|
+
if (arguments.length === 0) {
|
954
|
+
msg = null;
|
955
|
+
constructor = null;
|
956
|
+
} else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
|
957
|
+
msg = constructor;
|
958
|
+
constructor = null;
|
959
|
+
} else if (constructor && constructor instanceof Error) {
|
960
|
+
desiredError = constructor;
|
961
|
+
constructor = null;
|
962
|
+
msg = null;
|
963
|
+
} else if (typeof constructor === 'function') {
|
964
|
+
name = (new constructor()).name;
|
965
|
+
} else {
|
966
|
+
constructor = null;
|
967
|
+
}
|
968
|
+
|
969
|
+
try {
|
970
|
+
obj();
|
971
|
+
} catch (err) {
|
972
|
+
// first, check desired error
|
973
|
+
if (desiredError) {
|
974
|
+
this.assert(
|
975
|
+
err === desiredError
|
976
|
+
, 'expected #{this} to throw ' + util.inspect(desiredError) + ' but ' + util.inspect(err) + ' was thrown'
|
977
|
+
, 'expected #{this} to not throw ' + util.inspect(desiredError)
|
978
|
+
);
|
979
|
+
return this;
|
980
|
+
}
|
981
|
+
// next, check constructor
|
982
|
+
if (constructor) {
|
983
|
+
this.assert(
|
984
|
+
err instanceof constructor
|
985
|
+
, 'expected #{this} to throw ' + name + ' but a ' + err.name + ' was thrown'
|
986
|
+
, 'expected #{this} to not throw ' + name );
|
987
|
+
if (!msg) return this;
|
988
|
+
}
|
989
|
+
// next, check message
|
990
|
+
if (err.message && msg && msg instanceof RegExp) {
|
991
|
+
this.assert(
|
992
|
+
msg.exec(err.message)
|
993
|
+
, 'expected #{this} to throw error matching ' + msg + ' but got ' + util.inspect(err.message)
|
994
|
+
, 'expected #{this} to throw error not matching ' + msg
|
995
|
+
);
|
996
|
+
return this;
|
997
|
+
} else if (err.message && msg && 'string' === typeof msg) {
|
998
|
+
this.assert(
|
999
|
+
~err.message.indexOf(msg)
|
1000
|
+
, 'expected #{this} to throw error including #{exp} but got #{act}'
|
1001
|
+
, 'expected #{this} to throw error not including #{act}'
|
1002
|
+
, msg
|
1003
|
+
, err.message
|
1004
|
+
);
|
1005
|
+
return this;
|
1006
|
+
} else {
|
1007
|
+
thrown = true;
|
1008
|
+
}
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
var expectedThrown = name ? name : desiredError ? util.inspect(desiredError) : 'an error';
|
1012
|
+
|
1013
|
+
this.assert(
|
1014
|
+
thrown === true
|
1015
|
+
, 'expected #{this} to throw ' + expectedThrown
|
1016
|
+
, 'expected #{this} to not throw ' + expectedThrown);
|
1017
|
+
|
1018
|
+
return this;
|
1019
|
+
};
|
1020
|
+
|
1021
|
+
/**
|
1022
|
+
* ### .respondTo(method)
|
1023
|
+
*
|
1024
|
+
* Assert that object/class will respond to a method.
|
1025
|
+
*
|
1026
|
+
* expect(Klass).to.respondTo('bar');
|
1027
|
+
* expect(obj).to.respondTo('bar');
|
1028
|
+
*
|
1029
|
+
* @name respondTo
|
1030
|
+
* @param {String} method
|
1031
|
+
* @api public
|
1032
|
+
*/
|
1033
|
+
|
1034
|
+
Assertion.prototype.respondTo = function (method) {
|
1035
|
+
var obj = flag(this, 'object')
|
1036
|
+
, context = ('function' === typeof obj)
|
1037
|
+
? obj.prototype[method]
|
1038
|
+
: obj[method];
|
1039
|
+
|
1040
|
+
this.assert(
|
1041
|
+
'function' === typeof context
|
1042
|
+
, 'expected #{this} to respond to ' + util.inspect(method)
|
1043
|
+
, 'expected #{this} to not respond to ' + util.inspect(method)
|
1044
|
+
, 'function'
|
1045
|
+
, typeof context
|
1046
|
+
);
|
1047
|
+
|
1048
|
+
return this;
|
1049
|
+
};
|
1050
|
+
|
1051
|
+
/**
|
1052
|
+
* ### .satisfy(method)
|
1053
|
+
*
|
1054
|
+
* Assert that passes a truth test.
|
1055
|
+
*
|
1056
|
+
* expect(1).to.satisfy(function(num) { return num > 0; });
|
1057
|
+
*
|
1058
|
+
* @name satisfy
|
1059
|
+
* @param {Function} matcher
|
1060
|
+
* @api public
|
1061
|
+
*/
|
1062
|
+
|
1063
|
+
Assertion.prototype.satisfy = function (matcher) {
|
1064
|
+
var obj = flag(this, 'object');
|
1065
|
+
this.assert(
|
1066
|
+
matcher(obj)
|
1067
|
+
, 'expected #{this} to satisfy ' + util.inspect(matcher)
|
1068
|
+
, 'expected #{this} to not satisfy' + util.inspect(matcher)
|
1069
|
+
, this.negate ? false : true
|
1070
|
+
, matcher(obj)
|
1071
|
+
);
|
1072
|
+
|
1073
|
+
return this;
|
1074
|
+
};
|
1075
|
+
|
1076
|
+
/**
|
1077
|
+
* ### .closeTo(expected, delta)
|
1078
|
+
*
|
1079
|
+
* Assert that actual is equal to +/- delta.
|
1080
|
+
*
|
1081
|
+
* expect(1.5).to.be.closeTo(1, 0.5);
|
1082
|
+
*
|
1083
|
+
* @name closeTo
|
1084
|
+
* @param {Number} expected
|
1085
|
+
* @param {Number} delta
|
1086
|
+
* @api public
|
1087
|
+
*/
|
1088
|
+
|
1089
|
+
Assertion.prototype.closeTo = function (expected, delta) {
|
1090
|
+
var obj = flag(this, 'object');
|
1091
|
+
this.assert(
|
1092
|
+
(obj - delta === expected) || (obj + delta === expected)
|
1093
|
+
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
|
1094
|
+
, 'expected #{this} not to be close to ' + expected + ' +/- ' + delta);
|
1095
|
+
|
1096
|
+
return this;
|
1097
|
+
};
|
1098
|
+
|
1099
|
+
/*!
|
1100
|
+
* Aliases.
|
1101
|
+
*/
|
1102
|
+
|
1103
|
+
(function alias(name, as){
|
1104
|
+
Assertion.prototype[as] = Assertion.prototype[name];
|
1105
|
+
return alias;
|
1106
|
+
})
|
1107
|
+
('equal', 'eq')
|
1108
|
+
('above', 'gt')
|
1109
|
+
('below', 'lt')
|
1110
|
+
('length', 'lengthOf')
|
1111
|
+
('keys', 'key')
|
1112
|
+
('ownProperty', 'haveOwnProperty')
|
1113
|
+
('above', 'greaterThan')
|
1114
|
+
('below', 'lessThan')
|
1115
|
+
('Throw', 'throws')
|
1116
|
+
('Throw', 'throw')
|
1117
|
+
('instanceOf', 'instanceof');
|
1118
|
+
|
1119
|
+
}); // module: assertion.js
|
1120
|
+
|
1121
|
+
require.register("browser/error.js", function(module, exports, require){
|
1122
|
+
/*!
|
1123
|
+
* chai
|
1124
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
1125
|
+
* MIT Licensed
|
1126
|
+
*/
|
1127
|
+
|
1128
|
+
module.exports = AssertionError;
|
1129
|
+
|
1130
|
+
function AssertionError (options) {
|
1131
|
+
options = options || {};
|
1132
|
+
this.message = options.message;
|
1133
|
+
this.actual = options.actual;
|
1134
|
+
this.expected = options.expected;
|
1135
|
+
this.operator = options.operator;
|
1136
|
+
|
1137
|
+
if (options.stackStartFunction && Error.captureStackTrace) {
|
1138
|
+
var stackStartFunction = options.stackStartFunction;
|
1139
|
+
Error.captureStackTrace(this, stackStartFunction);
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
AssertionError.prototype = Object.create(Error.prototype);
|
1144
|
+
AssertionError.prototype.name = 'AssertionError';
|
1145
|
+
AssertionError.prototype.constructor = AssertionError;
|
1146
|
+
|
1147
|
+
AssertionError.prototype.toString = function() {
|
1148
|
+
return this.message;
|
1149
|
+
};
|
1150
|
+
|
1151
|
+
}); // module: browser/error.js
|
1152
|
+
|
1153
|
+
require.register("chai.js", function(module, exports, require){
|
1154
|
+
/*!
|
1155
|
+
* chai
|
1156
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
1157
|
+
* MIT Licensed
|
1158
|
+
*/
|
1159
|
+
|
1160
|
+
var used = []
|
1161
|
+
, exports = module.exports = {};
|
1162
|
+
|
1163
|
+
/*!
|
1164
|
+
* Chai version
|
1165
|
+
*/
|
1166
|
+
|
1167
|
+
exports.version = '1.0.0';
|
1168
|
+
|
1169
|
+
/*!
|
1170
|
+
* Primary `Assertion` prototype
|
1171
|
+
*/
|
1172
|
+
|
1173
|
+
exports.Assertion = require('./assertion');
|
1174
|
+
|
1175
|
+
/*!
|
1176
|
+
* Assertion Error
|
1177
|
+
*/
|
1178
|
+
|
1179
|
+
exports.AssertionError = require('./browser/error');
|
1180
|
+
|
1181
|
+
/*!
|
1182
|
+
* Utils for plugins (not exported)
|
1183
|
+
*/
|
1184
|
+
|
1185
|
+
var util = require('./utils');
|
1186
|
+
|
1187
|
+
/**
|
1188
|
+
* # .use(function)
|
1189
|
+
*
|
1190
|
+
* Provides a way to extend the internals of Chai
|
1191
|
+
*
|
1192
|
+
* @param {Function}
|
1193
|
+
* @returns {this} for chaining
|
1194
|
+
* @api public
|
1195
|
+
*/
|
1196
|
+
|
1197
|
+
exports.use = function (fn) {
|
1198
|
+
if (!~used.indexOf(fn)) {
|
1199
|
+
fn(this, util);
|
1200
|
+
used.push(fn);
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
return this;
|
1204
|
+
};
|
1205
|
+
|
1206
|
+
/*!
|
1207
|
+
* Expect interface
|
1208
|
+
*/
|
1209
|
+
|
1210
|
+
var expect = require('./interface/expect');
|
1211
|
+
exports.use(expect);
|
1212
|
+
|
1213
|
+
/*!
|
1214
|
+
* Should interface
|
1215
|
+
*/
|
1216
|
+
|
1217
|
+
var should = require('./interface/should');
|
1218
|
+
exports.use(should);
|
1219
|
+
|
1220
|
+
/*!
|
1221
|
+
* Assert interface
|
1222
|
+
*/
|
1223
|
+
|
1224
|
+
var assert = require('./interface/assert');
|
1225
|
+
exports.use(assert);
|
1226
|
+
|
1227
|
+
}); // module: chai.js
|
1228
|
+
|
1229
|
+
require.register("interface/assert.js", function(module, exports, require){
|
1230
|
+
/*!
|
1231
|
+
* chai
|
1232
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
1233
|
+
* MIT Licensed
|
1234
|
+
*/
|
1235
|
+
|
1236
|
+
|
1237
|
+
module.exports = function (chai, util) {
|
1238
|
+
|
1239
|
+
/*!
|
1240
|
+
* Chai dependencies.
|
1241
|
+
*/
|
1242
|
+
|
1243
|
+
var Assertion = chai.Assertion
|
1244
|
+
, flag = util.flag;
|
1245
|
+
|
1246
|
+
/*!
|
1247
|
+
* Module export.
|
1248
|
+
*/
|
1249
|
+
|
1250
|
+
/**
|
1251
|
+
* ### assert(expressions, errorMessage)
|
1252
|
+
*
|
1253
|
+
* Write your own test expressions.
|
1254
|
+
*
|
1255
|
+
* @param {Mixed} expression to test for truthiness.
|
1256
|
+
* @param {String} message to display on error
|
1257
|
+
* @name assert
|
1258
|
+
* @api public
|
1259
|
+
*/
|
1260
|
+
|
1261
|
+
var assert = chai.assert = function (express, errmsg) {
|
1262
|
+
var test = new Assertion(null);
|
1263
|
+
test.assert(
|
1264
|
+
express
|
1265
|
+
, errmsg
|
1266
|
+
, '[ negation message unavailable ]'
|
1267
|
+
);
|
1268
|
+
};
|
1269
|
+
|
1270
|
+
/**
|
1271
|
+
* ### .fail(actual, expect, msg, operator)
|
1272
|
+
*
|
1273
|
+
* Throw a failure. Node.js compatible.
|
1274
|
+
*
|
1275
|
+
* @name fail
|
1276
|
+
* @param {*} actual value
|
1277
|
+
* @param {*} expected value
|
1278
|
+
* @param {String} message
|
1279
|
+
* @param {String} operator
|
1280
|
+
* @api public
|
1281
|
+
*/
|
1282
|
+
|
1283
|
+
assert.fail = function (actual, expected, message, operator) {
|
1284
|
+
throw new chai.AssertionError({
|
1285
|
+
actual: actual
|
1286
|
+
, expected: expected
|
1287
|
+
, message: message
|
1288
|
+
, operator: operator
|
1289
|
+
, stackStartFunction: assert.fail
|
1290
|
+
});
|
1291
|
+
};
|
1292
|
+
|
1293
|
+
/**
|
1294
|
+
* ### .ok(object, [message])
|
1295
|
+
*
|
1296
|
+
* Assert object is truthy.
|
1297
|
+
*
|
1298
|
+
* assert.ok('everthing', 'everything is ok');
|
1299
|
+
* assert.ok(false, 'this will fail');
|
1300
|
+
*
|
1301
|
+
* @name ok
|
1302
|
+
* @param {*} object to test
|
1303
|
+
* @param {String} message
|
1304
|
+
* @api public
|
1305
|
+
*/
|
1306
|
+
|
1307
|
+
assert.ok = function (val, msg) {
|
1308
|
+
new Assertion(val, msg).is.ok;
|
1309
|
+
};
|
1310
|
+
|
1311
|
+
/**
|
1312
|
+
* ### .equal(actual, expected, [message])
|
1313
|
+
*
|
1314
|
+
* Assert non-strict equality (==).
|
1315
|
+
*
|
1316
|
+
* assert.equal(3, 3, 'these numbers are equal');
|
1317
|
+
*
|
1318
|
+
* @name equal
|
1319
|
+
* @param {*} actual
|
1320
|
+
* @param {*} expected
|
1321
|
+
* @param {String} message
|
1322
|
+
* @api public
|
1323
|
+
*/
|
1324
|
+
|
1325
|
+
assert.equal = function (act, exp, msg) {
|
1326
|
+
var test = new Assertion(act, msg);
|
1327
|
+
|
1328
|
+
test.assert(
|
1329
|
+
exp == flag(test, 'object')
|
1330
|
+
, 'expected #{this} to equal #{exp}'
|
1331
|
+
, 'expected #{this} to not equal #{act}'
|
1332
|
+
, exp
|
1333
|
+
, act
|
1334
|
+
);
|
1335
|
+
};
|
1336
|
+
|
1337
|
+
/**
|
1338
|
+
* ### .notEqual(actual, expected, [message])
|
1339
|
+
*
|
1340
|
+
* Assert non-strict inequality (!=).
|
1341
|
+
*
|
1342
|
+
* assert.notEqual(3, 4, 'these numbers are not equal');
|
1343
|
+
*
|
1344
|
+
* @name notEqual
|
1345
|
+
* @param {*} actual
|
1346
|
+
* @param {*} expected
|
1347
|
+
* @param {String} message
|
1348
|
+
* @api public
|
1349
|
+
*/
|
1350
|
+
|
1351
|
+
assert.notEqual = function (act, exp, msg) {
|
1352
|
+
var test = new Assertion(act, msg);
|
1353
|
+
|
1354
|
+
test.assert(
|
1355
|
+
exp != flag(test, 'object')
|
1356
|
+
, 'expected #{this} to not equal #{exp}'
|
1357
|
+
, 'expected #{this} to equal #{act}'
|
1358
|
+
, exp
|
1359
|
+
, act
|
1360
|
+
);
|
1361
|
+
};
|
1362
|
+
|
1363
|
+
/**
|
1364
|
+
* ### .strictEqual(actual, expected, [message])
|
1365
|
+
*
|
1366
|
+
* Assert strict equality (===).
|
1367
|
+
*
|
1368
|
+
* assert.strictEqual(true, true, 'these booleans are strictly equal');
|
1369
|
+
*
|
1370
|
+
* @name strictEqual
|
1371
|
+
* @param {*} actual
|
1372
|
+
* @param {*} expected
|
1373
|
+
* @param {String} message
|
1374
|
+
* @api public
|
1375
|
+
*/
|
1376
|
+
|
1377
|
+
assert.strictEqual = function (act, exp, msg) {
|
1378
|
+
new Assertion(act, msg).to.equal(exp);
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
/**
|
1382
|
+
* ### .notStrictEqual(actual, expected, [message])
|
1383
|
+
*
|
1384
|
+
* Assert strict inequality (!==).
|
1385
|
+
*
|
1386
|
+
* assert.notStrictEqual(1, true, 'these booleans are not strictly equal');
|
1387
|
+
*
|
1388
|
+
* @name notStrictEqual
|
1389
|
+
* @param {*} actual
|
1390
|
+
* @param {*} expected
|
1391
|
+
* @param {String} message
|
1392
|
+
* @api public
|
1393
|
+
*/
|
1394
|
+
|
1395
|
+
assert.notStrictEqual = function (act, exp, msg) {
|
1396
|
+
new Assertion(act, msg).to.not.equal(exp);
|
1397
|
+
};
|
1398
|
+
|
1399
|
+
/**
|
1400
|
+
* ### .deepEqual(actual, expected, [message])
|
1401
|
+
*
|
1402
|
+
* Assert not deep equality.
|
1403
|
+
*
|
1404
|
+
* assert.deepEqual({ tea: 'green' }, { tea: 'green' });
|
1405
|
+
*
|
1406
|
+
* @name deepEqual
|
1407
|
+
* @param {*} actual
|
1408
|
+
* @param {*} expected
|
1409
|
+
* @param {String} message
|
1410
|
+
* @api public
|
1411
|
+
*/
|
1412
|
+
|
1413
|
+
assert.deepEqual = function (act, exp, msg) {
|
1414
|
+
new Assertion(act, msg).to.eql(exp);
|
1415
|
+
};
|
1416
|
+
|
1417
|
+
/**
|
1418
|
+
* ### .notDeepEqual(actual, expected, [message])
|
1419
|
+
*
|
1420
|
+
* Assert not deep equality.
|
1421
|
+
*
|
1422
|
+
* assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
|
1423
|
+
*
|
1424
|
+
* @name notDeepEqual
|
1425
|
+
* @param {*} actual
|
1426
|
+
* @param {*} expected
|
1427
|
+
* @param {String} message
|
1428
|
+
* @api public
|
1429
|
+
*/
|
1430
|
+
|
1431
|
+
assert.notDeepEqual = function (act, exp, msg) {
|
1432
|
+
new Assertion(act, msg).to.not.eql(exp);
|
1433
|
+
};
|
1434
|
+
|
1435
|
+
/**
|
1436
|
+
* ### .isTrue(value, [message])
|
1437
|
+
*
|
1438
|
+
* Assert `value` is true.
|
1439
|
+
*
|
1440
|
+
* var tea_served = true;
|
1441
|
+
* assert.isTrue(tea_served, 'the tea has been served');
|
1442
|
+
*
|
1443
|
+
* @name isTrue
|
1444
|
+
* @param {Boolean} value
|
1445
|
+
* @param {String} message
|
1446
|
+
* @api public
|
1447
|
+
*/
|
1448
|
+
|
1449
|
+
assert.isTrue = function (val, msg) {
|
1450
|
+
new Assertion(val, msg).is['true'];
|
1451
|
+
};
|
1452
|
+
|
1453
|
+
/**
|
1454
|
+
* ### .isFalse(value, [message])
|
1455
|
+
*
|
1456
|
+
* Assert `value` is false.
|
1457
|
+
*
|
1458
|
+
* var tea_served = false;
|
1459
|
+
* assert.isFalse(tea_served, 'no tea yet? hmm...');
|
1460
|
+
*
|
1461
|
+
* @name isFalse
|
1462
|
+
* @param {Boolean} value
|
1463
|
+
* @param {String} message
|
1464
|
+
* @api public
|
1465
|
+
*/
|
1466
|
+
|
1467
|
+
assert.isFalse = function (val, msg) {
|
1468
|
+
new Assertion(val, msg).is['false'];
|
1469
|
+
};
|
1470
|
+
|
1471
|
+
/**
|
1472
|
+
* ### .isNull(value, [message])
|
1473
|
+
*
|
1474
|
+
* Assert `value` is null.
|
1475
|
+
*
|
1476
|
+
* assert.isNull(err, 'no errors');
|
1477
|
+
*
|
1478
|
+
* @name isNull
|
1479
|
+
* @param {*} value
|
1480
|
+
* @param {String} message
|
1481
|
+
* @api public
|
1482
|
+
*/
|
1483
|
+
|
1484
|
+
assert.isNull = function (val, msg) {
|
1485
|
+
new Assertion(val, msg).to.equal(null);
|
1486
|
+
};
|
1487
|
+
|
1488
|
+
/**
|
1489
|
+
* ### .isNotNull(value, [message])
|
1490
|
+
*
|
1491
|
+
* Assert `value` is not null.
|
1492
|
+
*
|
1493
|
+
* var tea = 'tasty chai';
|
1494
|
+
* assert.isNotNull(tea, 'great, time for tea!');
|
1495
|
+
*
|
1496
|
+
* @name isNotNull
|
1497
|
+
* @param {*} value
|
1498
|
+
* @param {String} message
|
1499
|
+
* @api public
|
1500
|
+
*/
|
1501
|
+
|
1502
|
+
assert.isNotNull = function (val, msg) {
|
1503
|
+
new Assertion(val, msg).to.not.equal(null);
|
1504
|
+
};
|
1505
|
+
|
1506
|
+
/**
|
1507
|
+
* ### .isUndefined(value, [message])
|
1508
|
+
*
|
1509
|
+
* Assert `value` is undefined.
|
1510
|
+
*
|
1511
|
+
* assert.isUndefined(tea, 'no tea defined');
|
1512
|
+
*
|
1513
|
+
* @name isUndefined
|
1514
|
+
* @param {*} value
|
1515
|
+
* @param {String} message
|
1516
|
+
* @api public
|
1517
|
+
*/
|
1518
|
+
|
1519
|
+
assert.isUndefined = function (val, msg) {
|
1520
|
+
new Assertion(val, msg).to.equal(undefined);
|
1521
|
+
};
|
1522
|
+
|
1523
|
+
/**
|
1524
|
+
* ### .isDefined(value, [message])
|
1525
|
+
*
|
1526
|
+
* Assert `value` is not undefined.
|
1527
|
+
*
|
1528
|
+
* var tea = 'cup of chai';
|
1529
|
+
* assert.isDefined(tea, 'no tea defined');
|
1530
|
+
*
|
1531
|
+
* @name isUndefined
|
1532
|
+
* @param {*} value
|
1533
|
+
* @param {String} message
|
1534
|
+
* @api public
|
1535
|
+
*/
|
1536
|
+
|
1537
|
+
assert.isDefined = function (val, msg) {
|
1538
|
+
new Assertion(val, msg).to.not.equal(undefined);
|
1539
|
+
};
|
1540
|
+
|
1541
|
+
/**
|
1542
|
+
* ### .isFunction(value, [message])
|
1543
|
+
*
|
1544
|
+
* Assert `value` is a function.
|
1545
|
+
*
|
1546
|
+
* var serve_tea = function () { return 'cup of tea'; };
|
1547
|
+
* assert.isFunction(serve_tea, 'great, we can have tea now');
|
1548
|
+
*
|
1549
|
+
* @name isFunction
|
1550
|
+
* @param {Function} value
|
1551
|
+
* @param {String} message
|
1552
|
+
* @api public
|
1553
|
+
*/
|
1554
|
+
|
1555
|
+
assert.isFunction = function (val, msg) {
|
1556
|
+
new Assertion(val, msg).to.be.a('function');
|
1557
|
+
};
|
1558
|
+
|
1559
|
+
/**
|
1560
|
+
* ### .isNotFunction(value, [message])
|
1561
|
+
*
|
1562
|
+
* Assert `value` is NOT a function.
|
1563
|
+
*
|
1564
|
+
* var serve_tea = [ 'heat', 'pour', 'sip' ];
|
1565
|
+
* assert.isNotFunction(serve_tea, 'great, we can have tea now');
|
1566
|
+
*
|
1567
|
+
* @name isNotFunction
|
1568
|
+
* @param {Mixed} value
|
1569
|
+
* @param {String} message
|
1570
|
+
* @api public
|
1571
|
+
*/
|
1572
|
+
|
1573
|
+
assert.isNotFunction = function (val, msg) {
|
1574
|
+
new Assertion(val, msg).to.not.be.a('function');
|
1575
|
+
};
|
1576
|
+
|
1577
|
+
/**
|
1578
|
+
* ### .isObject(value, [message])
|
1579
|
+
*
|
1580
|
+
* Assert `value` is an object.
|
1581
|
+
*
|
1582
|
+
* var selection = { name: 'Chai', serve: 'with spices' };
|
1583
|
+
* assert.isObject(selection, 'tea selection is an object');
|
1584
|
+
*
|
1585
|
+
* @name isObject
|
1586
|
+
* @param {Object} value
|
1587
|
+
* @param {String} message
|
1588
|
+
* @api public
|
1589
|
+
*/
|
1590
|
+
|
1591
|
+
assert.isObject = function (val, msg) {
|
1592
|
+
new Assertion(val, msg).to.be.a('object');
|
1593
|
+
};
|
1594
|
+
|
1595
|
+
/**
|
1596
|
+
* ### .isNotObject(value, [message])
|
1597
|
+
*
|
1598
|
+
* Assert `value` is NOT an object.
|
1599
|
+
*
|
1600
|
+
* var selection = 'chai'
|
1601
|
+
* assert.isObject(selection, 'tea selection is not an object');
|
1602
|
+
*
|
1603
|
+
* @name isNotObject
|
1604
|
+
* @param {Mixed} value
|
1605
|
+
* @param {String} message
|
1606
|
+
* @api public
|
1607
|
+
*/
|
1608
|
+
|
1609
|
+
assert.isNotObject = function (val, msg) {
|
1610
|
+
new Assertion(val, msg).to.not.be.a('object');
|
1611
|
+
};
|
1612
|
+
|
1613
|
+
/**
|
1614
|
+
* ### .isArray(value, [message])
|
1615
|
+
*
|
1616
|
+
* Assert `value` is an instance of Array.
|
1617
|
+
*
|
1618
|
+
* var menu = [ 'green', 'chai', 'oolong' ];
|
1619
|
+
* assert.isArray(menu, 'what kind of tea do we want?');
|
1620
|
+
*
|
1621
|
+
* @name isArray
|
1622
|
+
* @param {Mixed} value
|
1623
|
+
* @param {String} message
|
1624
|
+
* @api public
|
1625
|
+
*/
|
1626
|
+
|
1627
|
+
assert.isArray = function (val, msg) {
|
1628
|
+
new Assertion(val, msg).to.be.instanceOf(Array);
|
1629
|
+
};
|
1630
|
+
|
1631
|
+
/**
|
1632
|
+
* ### .isArray(value, [message])
|
1633
|
+
*
|
1634
|
+
* Assert `value` is NOT an instance of Array.
|
1635
|
+
*
|
1636
|
+
* var menu = 'green|chai|oolong';
|
1637
|
+
* assert.isNotArray(menu, 'what kind of tea do we want?');
|
1638
|
+
*
|
1639
|
+
* @name isNotArray
|
1640
|
+
* @param {Mixed} value
|
1641
|
+
* @param {String} message
|
1642
|
+
* @api public
|
1643
|
+
*/
|
1644
|
+
|
1645
|
+
assert.isNotArray = function (val, msg) {
|
1646
|
+
new Assertion(val, msg).to.not.be.instanceOf(Array);
|
1647
|
+
};
|
1648
|
+
|
1649
|
+
/**
|
1650
|
+
* ### .isString(value, [message])
|
1651
|
+
*
|
1652
|
+
* Assert `value` is a string.
|
1653
|
+
*
|
1654
|
+
* var teaorder = 'chai';
|
1655
|
+
* assert.isString(tea_order, 'order placed');
|
1656
|
+
*
|
1657
|
+
* @name isString
|
1658
|
+
* @param {String} value
|
1659
|
+
* @param {String} message
|
1660
|
+
* @api public
|
1661
|
+
*/
|
1662
|
+
|
1663
|
+
assert.isString = function (val, msg) {
|
1664
|
+
new Assertion(val, msg).to.be.a('string');
|
1665
|
+
};
|
1666
|
+
|
1667
|
+
/**
|
1668
|
+
* ### .isNotString(value, [message])
|
1669
|
+
*
|
1670
|
+
* Assert `value` is NOT a string.
|
1671
|
+
*
|
1672
|
+
* var teaorder = 4;
|
1673
|
+
* assert.isNotString(tea_order, 'order placed');
|
1674
|
+
*
|
1675
|
+
* @name isNotString
|
1676
|
+
* @param {Mixed} value
|
1677
|
+
* @param {String} message
|
1678
|
+
* @api public
|
1679
|
+
*/
|
1680
|
+
|
1681
|
+
assert.isNotString = function (val, msg) {
|
1682
|
+
new Assertion(val, msg).to.not.be.a('string');
|
1683
|
+
};
|
1684
|
+
|
1685
|
+
/**
|
1686
|
+
* ### .isNumber(value, [message])
|
1687
|
+
*
|
1688
|
+
* Assert `value` is a number
|
1689
|
+
*
|
1690
|
+
* var cups = 2;
|
1691
|
+
* assert.isNumber(cups, 'how many cups');
|
1692
|
+
*
|
1693
|
+
* @name isNumber
|
1694
|
+
* @param {Number} value
|
1695
|
+
* @param {String} message
|
1696
|
+
* @api public
|
1697
|
+
*/
|
1698
|
+
|
1699
|
+
assert.isNumber = function (val, msg) {
|
1700
|
+
new Assertion(val, msg).to.be.a('number');
|
1701
|
+
};
|
1702
|
+
|
1703
|
+
/**
|
1704
|
+
* ### .isNotNumber(value, [message])
|
1705
|
+
*
|
1706
|
+
* Assert `value` NOT is a number
|
1707
|
+
*
|
1708
|
+
* var cups = '2 cups please';
|
1709
|
+
* assert.isNotNumber(cups, 'how many cups');
|
1710
|
+
*
|
1711
|
+
* @name isNotNumber
|
1712
|
+
* @param {Mixed} value
|
1713
|
+
* @param {String} message
|
1714
|
+
* @api public
|
1715
|
+
*/
|
1716
|
+
|
1717
|
+
assert.isNotNumber = function (val, msg) {
|
1718
|
+
new Assertion(val, msg).to.not.be.a('number');
|
1719
|
+
};
|
1720
|
+
|
1721
|
+
/**
|
1722
|
+
* ### .isBoolean(value, [message])
|
1723
|
+
*
|
1724
|
+
* Assert `value` is a boolean
|
1725
|
+
*
|
1726
|
+
* var teaready = true
|
1727
|
+
* , teaserved = false;
|
1728
|
+
*
|
1729
|
+
* assert.isBoolean(tea_ready, 'is the tea ready');
|
1730
|
+
* assert.isBoolean(tea_served, 'has tea been served');
|
1731
|
+
*
|
1732
|
+
* @name isBoolean
|
1733
|
+
* @param {Mixed} value
|
1734
|
+
* @param {String} message
|
1735
|
+
* @api public
|
1736
|
+
*/
|
1737
|
+
|
1738
|
+
assert.isBoolean = function (val, msg) {
|
1739
|
+
new Assertion(val, msg).to.be.a('boolean');
|
1740
|
+
};
|
1741
|
+
|
1742
|
+
/**
|
1743
|
+
* ### .isNotBoolean(value, [message])
|
1744
|
+
*
|
1745
|
+
* Assert `value` is NOT a boolean
|
1746
|
+
*
|
1747
|
+
* var teaready = 'yep'
|
1748
|
+
* , teaserved = 'nope';
|
1749
|
+
*
|
1750
|
+
* assert.isNotBoolean(tea_ready, 'is the tea ready');
|
1751
|
+
* assert.isNotBoolean(tea_served, 'has tea been served');
|
1752
|
+
*
|
1753
|
+
* @name isNotBoolean
|
1754
|
+
* @param {Mixed} value
|
1755
|
+
* @param {String} message
|
1756
|
+
* @api public
|
1757
|
+
*/
|
1758
|
+
|
1759
|
+
assert.isNotBoolean = function (val, msg) {
|
1760
|
+
new Assertion(val, msg).to.not.be.a('boolean');
|
1761
|
+
};
|
1762
|
+
|
1763
|
+
/**
|
1764
|
+
* ### .typeOf(value, name, [message])
|
1765
|
+
*
|
1766
|
+
* Assert typeof `value` is `name`.
|
1767
|
+
*
|
1768
|
+
* assert.typeOf('tea', 'string', 'we have a string');
|
1769
|
+
*
|
1770
|
+
* @name typeOf
|
1771
|
+
* @param {Mixed} value
|
1772
|
+
* @param {String} typeof name
|
1773
|
+
* @param {String} message
|
1774
|
+
* @api public
|
1775
|
+
*/
|
1776
|
+
|
1777
|
+
assert.typeOf = function (val, type, msg) {
|
1778
|
+
new Assertion(val, msg).to.be.a(type);
|
1779
|
+
};
|
1780
|
+
|
1781
|
+
/**
|
1782
|
+
* ### .notTypeOf(value, name, [message])
|
1783
|
+
*
|
1784
|
+
* Assert typeof `value` is NOT `name`.
|
1785
|
+
*
|
1786
|
+
* assert.notTypeOf('tea', 'string', 'we have a string');
|
1787
|
+
*
|
1788
|
+
* @name notTypeOf
|
1789
|
+
* @param {Mixed} value
|
1790
|
+
* @param {String} typeof name
|
1791
|
+
* @param {String} message
|
1792
|
+
* @api public
|
1793
|
+
*/
|
1794
|
+
|
1795
|
+
assert.notTypeOf = function (val, type, msg) {
|
1796
|
+
new Assertion(val, msg).to.not.be.a(type);
|
1797
|
+
};
|
1798
|
+
|
1799
|
+
/**
|
1800
|
+
* ### .instanceOf(object, constructor, [message])
|
1801
|
+
*
|
1802
|
+
* Assert `value` is instanceof `constructor`.
|
1803
|
+
*
|
1804
|
+
* var Tea = function (name) { this.name = name; }
|
1805
|
+
* , Chai = new Tea('chai');
|
1806
|
+
*
|
1807
|
+
* assert.instanceOf(Chai, Tea, 'chai is an instance of tea');
|
1808
|
+
*
|
1809
|
+
* @name instanceOf
|
1810
|
+
* @param {Object} object
|
1811
|
+
* @param {Constructor} constructor
|
1812
|
+
* @param {String} message
|
1813
|
+
* @api public
|
1814
|
+
*/
|
1815
|
+
|
1816
|
+
assert.instanceOf = function (val, type, msg) {
|
1817
|
+
new Assertion(val, msg).to.be.instanceOf(type);
|
1818
|
+
};
|
1819
|
+
|
1820
|
+
/**
|
1821
|
+
* ### .notInstanceOf(object, constructor, [message])
|
1822
|
+
*
|
1823
|
+
* Assert `value` is NOT instanceof `constructor`.
|
1824
|
+
*
|
1825
|
+
* var Tea = function (name) { this.name = name; }
|
1826
|
+
* , Chai = new String('chai');
|
1827
|
+
*
|
1828
|
+
* assert.notInstanceOf(Chai, Tea, 'chai is an instance of tea');
|
1829
|
+
*
|
1830
|
+
* @name notInstanceOf
|
1831
|
+
* @param {Object} object
|
1832
|
+
* @param {Constructor} constructor
|
1833
|
+
* @param {String} message
|
1834
|
+
* @api public
|
1835
|
+
*/
|
1836
|
+
|
1837
|
+
assert.notInstanceOf = function (val, type, msg) {
|
1838
|
+
new Assertion(val, msg).to.not.be.instanceOf(type);
|
1839
|
+
};
|
1840
|
+
|
1841
|
+
/**
|
1842
|
+
* ### .include(value, includes, [message])
|
1843
|
+
*
|
1844
|
+
* Assert the inclusion of an object in another. Works
|
1845
|
+
* for strings and arrays.
|
1846
|
+
*
|
1847
|
+
* assert.include('foobar', 'bar', 'foobar contains string `var`);
|
1848
|
+
* assert.include([ 1, 2, 3], 3, 'array contains value);
|
1849
|
+
*
|
1850
|
+
* @name include
|
1851
|
+
* @param {Array|String} value
|
1852
|
+
* @param {*} includes
|
1853
|
+
* @param {String} message
|
1854
|
+
* @api public
|
1855
|
+
*/
|
1856
|
+
|
1857
|
+
assert.include = function (exp, inc, msg) {
|
1858
|
+
var obj = new Assertion(exp, msg);
|
1859
|
+
|
1860
|
+
if (Array.isArray(exp)) {
|
1861
|
+
obj.to.include(inc);
|
1862
|
+
} else if ('string' === typeof exp) {
|
1863
|
+
obj.to.contain.string(inc);
|
1864
|
+
}
|
1865
|
+
};
|
1866
|
+
|
1867
|
+
/**
|
1868
|
+
* ### .match(value, regex, [message])
|
1869
|
+
*
|
1870
|
+
* Assert that `value` matches regular expression.
|
1871
|
+
*
|
1872
|
+
* assert.match('foobar', /^foo/, 'Regexp matches');
|
1873
|
+
*
|
1874
|
+
* @name match
|
1875
|
+
* @param {*} value
|
1876
|
+
* @param {RegExp} RegularExpression
|
1877
|
+
* @param {String} message
|
1878
|
+
* @api public
|
1879
|
+
*/
|
1880
|
+
|
1881
|
+
assert.match = function (exp, re, msg) {
|
1882
|
+
new Assertion(exp, msg).to.match(re);
|
1883
|
+
};
|
1884
|
+
|
1885
|
+
/**
|
1886
|
+
* ### .notMatch(value, regex, [message])
|
1887
|
+
*
|
1888
|
+
* Assert that `value` does not match regular expression.
|
1889
|
+
*
|
1890
|
+
* assert.notMatch('foobar', /^foo/, 'Regexp matches');
|
1891
|
+
*
|
1892
|
+
* @name notMatch
|
1893
|
+
* @param {*} value
|
1894
|
+
* @param {RegExp} RegularExpression
|
1895
|
+
* @param {String} message
|
1896
|
+
* @api public
|
1897
|
+
*/
|
1898
|
+
|
1899
|
+
assert.notMatch = function (exp, re, msg) {
|
1900
|
+
new Assertion(exp, msg).to.not.match(re);
|
1901
|
+
};
|
1902
|
+
|
1903
|
+
/**
|
1904
|
+
* ### .property(object, property, [message])
|
1905
|
+
*
|
1906
|
+
* Assert that `object` has property. Can use dot-notation for deep reference.
|
1907
|
+
*
|
1908
|
+
* assert.property({ tea: { green: 'matcha' }}, 'tea.green');
|
1909
|
+
*
|
1910
|
+
* @name property
|
1911
|
+
* @param {Object} object
|
1912
|
+
* @param {String} Property address
|
1913
|
+
* @param {String} message
|
1914
|
+
* @api public
|
1915
|
+
*/
|
1916
|
+
|
1917
|
+
assert.property = function (obj, prop, msg) {
|
1918
|
+
new Assertion(obj, msg).to.have.property(prop);
|
1919
|
+
};
|
1920
|
+
|
1921
|
+
/**
|
1922
|
+
* ### .notOwnProperty(object, property, [message])
|
1923
|
+
*
|
1924
|
+
* Assert that `object` does not have property. Can use dot-notation for deep reference.
|
1925
|
+
*
|
1926
|
+
* assert.ownProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
|
1927
|
+
*
|
1928
|
+
* @name notOwnProperty
|
1929
|
+
* @param {Object} object
|
1930
|
+
* @param {String} property address
|
1931
|
+
* @param {String} message
|
1932
|
+
* @api public
|
1933
|
+
*/
|
1934
|
+
|
1935
|
+
assert.notProperty = function (obj, prop, msg) {
|
1936
|
+
new Assertion(obj, msg).to.not.have.property(prop);
|
1937
|
+
};
|
1938
|
+
|
1939
|
+
/**
|
1940
|
+
* ### .propertyVal(object, property, value, [message])
|
1941
|
+
*
|
1942
|
+
* Assert that `object` has property with `value`.
|
1943
|
+
* Can use dot-notation for deep reference.
|
1944
|
+
*
|
1945
|
+
* assert.propertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
|
1946
|
+
*
|
1947
|
+
* @name propertyVal
|
1948
|
+
* @param {Object} object
|
1949
|
+
* @param {String} property address
|
1950
|
+
* @param {Mixed} value
|
1951
|
+
* @param {String} message
|
1952
|
+
* @api public
|
1953
|
+
*/
|
1954
|
+
|
1955
|
+
assert.propertyVal = function (obj, prop, val, msg) {
|
1956
|
+
new Assertion(obj, msg).to.have.property(prop, val);
|
1957
|
+
};
|
1958
|
+
|
1959
|
+
/**
|
1960
|
+
* ### .propertyNotVal(object, property, value, [message])
|
1961
|
+
*
|
1962
|
+
* Assert that `object` has property but `value`
|
1963
|
+
* does not equal `value`. Can use dot-notation for deep reference.
|
1964
|
+
*
|
1965
|
+
* assert.propertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
|
1966
|
+
*
|
1967
|
+
* @name propertyNotVal
|
1968
|
+
* @param {Object} object
|
1969
|
+
* @param {String} property address
|
1970
|
+
* @param {Mixed} value
|
1971
|
+
* @param {String} message
|
1972
|
+
* @api public
|
1973
|
+
*/
|
1974
|
+
assert.propertyNotVal = function (obj, prop, val, msg) {
|
1975
|
+
new Assertion(obj, msg).to.not.have.property(prop, val);
|
1976
|
+
};
|
1977
|
+
|
1978
|
+
/**
|
1979
|
+
* ### .lengthOf(object, length, [message])
|
1980
|
+
*
|
1981
|
+
* Assert that object has expected length.
|
1982
|
+
*
|
1983
|
+
* assert.lengthOf([1,2,3], 3, 'Array has length of 3');
|
1984
|
+
* assert.lengthOf('foobar', 5, 'String has length of 6');
|
1985
|
+
*
|
1986
|
+
* @name length
|
1987
|
+
* @param {*} value
|
1988
|
+
* @param {Number} length
|
1989
|
+
* @param {String} message
|
1990
|
+
* @api public
|
1991
|
+
*/
|
1992
|
+
|
1993
|
+
assert.lengthOf = function (exp, len, msg) {
|
1994
|
+
new Assertion(exp, msg).to.have.length(len);
|
1995
|
+
};
|
1996
|
+
|
1997
|
+
/**
|
1998
|
+
* ### .throws(function, [constructor/regexp], [message])
|
1999
|
+
*
|
2000
|
+
* Assert that a function will throw a specific
|
2001
|
+
* type of error.
|
2002
|
+
*
|
2003
|
+
* assert.throw(fn, ReferenceError, 'function throw reference error');
|
2004
|
+
*
|
2005
|
+
* @name throws
|
2006
|
+
* @alias throw
|
2007
|
+
* @param {Function} function to test
|
2008
|
+
* @param {ErrorConstructor} constructor
|
2009
|
+
* @param {String} message
|
2010
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
2011
|
+
* @api public
|
2012
|
+
*/
|
2013
|
+
|
2014
|
+
assert.throws = function (fn, type, msg) {
|
2015
|
+
if ('string' === typeof type) {
|
2016
|
+
msg = type;
|
2017
|
+
type = null;
|
2018
|
+
}
|
2019
|
+
|
2020
|
+
new Assertion(fn, msg).to.Throw(type);
|
2021
|
+
};
|
2022
|
+
|
2023
|
+
/**
|
2024
|
+
* ### .doesNotThrow(function, [constructor/regexp], [message])
|
2025
|
+
*
|
2026
|
+
* Assert that a function will throw a specific
|
2027
|
+
* type of error.
|
2028
|
+
*
|
2029
|
+
* var fn = function (err) { if (err) throw Error(err) };
|
2030
|
+
* assert.doesNotThrow(fn, Error, 'function throw reference error');
|
2031
|
+
*
|
2032
|
+
* @name doesNotThrow
|
2033
|
+
* @param {Function} function to test
|
2034
|
+
* @param {ErrorConstructor} constructor
|
2035
|
+
* @param {String} message
|
2036
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
2037
|
+
* @api public
|
2038
|
+
*/
|
2039
|
+
|
2040
|
+
assert.doesNotThrow = function (fn, type, msg) {
|
2041
|
+
if ('string' === typeof type) {
|
2042
|
+
msg = type;
|
2043
|
+
type = null;
|
2044
|
+
}
|
2045
|
+
|
2046
|
+
new Assertion(fn, msg).to.not.Throw(type);
|
2047
|
+
};
|
2048
|
+
|
2049
|
+
/**
|
2050
|
+
* ### .operator(val, operator, val2, [message])
|
2051
|
+
*
|
2052
|
+
* Compare two values using operator.
|
2053
|
+
*
|
2054
|
+
* assert.operator(1, '<', 2, 'everything is ok');
|
2055
|
+
* assert.operator(1, '>', 2, 'this will fail');
|
2056
|
+
*
|
2057
|
+
* @name operator
|
2058
|
+
* @param {*} object to test
|
2059
|
+
* @param {String} operator
|
2060
|
+
* @param {*} second object
|
2061
|
+
* @param {String} message
|
2062
|
+
* @api public
|
2063
|
+
*/
|
2064
|
+
|
2065
|
+
assert.operator = function (val, operator, val2, msg) {
|
2066
|
+
if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
|
2067
|
+
throw new Error('Invalid operator "' + operator + '"');
|
2068
|
+
}
|
2069
|
+
var test = new Assertion(eval(val + operator + val2), msg);
|
2070
|
+
test.assert(
|
2071
|
+
true === flag(test, 'object')
|
2072
|
+
, 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
|
2073
|
+
, 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
|
2074
|
+
};
|
2075
|
+
|
2076
|
+
/*!
|
2077
|
+
* Undocumented / untested
|
2078
|
+
*/
|
2079
|
+
|
2080
|
+
assert.ifError = function (val, msg) {
|
2081
|
+
new Assertion(val, msg).to.not.be.ok;
|
2082
|
+
};
|
2083
|
+
|
2084
|
+
/*!
|
2085
|
+
* Aliases.
|
2086
|
+
*/
|
2087
|
+
|
2088
|
+
(function alias(name, as){
|
2089
|
+
assert[as] = assert[name];
|
2090
|
+
return alias;
|
2091
|
+
})
|
2092
|
+
('throws', 'throw');
|
2093
|
+
};
|
2094
|
+
|
2095
|
+
}); // module: interface/assert.js
|
2096
|
+
|
2097
|
+
require.register("interface/expect.js", function(module, exports, require){
|
2098
|
+
/*!
|
2099
|
+
* chai
|
2100
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
2101
|
+
* MIT Licensed
|
2102
|
+
*/
|
2103
|
+
|
2104
|
+
module.exports = function (chai, util) {
|
2105
|
+
chai.expect = function (val, message) {
|
2106
|
+
return new chai.Assertion(val, message);
|
2107
|
+
};
|
2108
|
+
};
|
2109
|
+
|
2110
|
+
|
2111
|
+
}); // module: interface/expect.js
|
2112
|
+
|
2113
|
+
require.register("interface/should.js", function(module, exports, require){
|
2114
|
+
/*!
|
2115
|
+
* chai
|
2116
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
2117
|
+
* MIT Licensed
|
2118
|
+
*/
|
2119
|
+
|
2120
|
+
module.exports = function (chai, util) {
|
2121
|
+
var Assertion = chai.Assertion;
|
2122
|
+
|
2123
|
+
function loadShould () {
|
2124
|
+
// modify Object.prototype to have `should`
|
2125
|
+
Object.defineProperty(Object.prototype, 'should',
|
2126
|
+
{ set: function () {}
|
2127
|
+
, get: function(){
|
2128
|
+
if (this instanceof String || this instanceof Number) {
|
2129
|
+
return new Assertion(this.constructor(this));
|
2130
|
+
} else if (this instanceof Boolean) {
|
2131
|
+
return new Assertion(this == true);
|
2132
|
+
}
|
2133
|
+
return new Assertion(this);
|
2134
|
+
}
|
2135
|
+
, configurable: true
|
2136
|
+
});
|
2137
|
+
|
2138
|
+
var should = {};
|
2139
|
+
|
2140
|
+
should.equal = function (val1, val2) {
|
2141
|
+
new Assertion(val1).to.equal(val2);
|
2142
|
+
};
|
2143
|
+
|
2144
|
+
should.Throw = function (fn, errt, errs) {
|
2145
|
+
new Assertion(fn).to.Throw(errt, errs);
|
2146
|
+
};
|
2147
|
+
|
2148
|
+
should.exist = function (val) {
|
2149
|
+
new Assertion(val).to.exist;
|
2150
|
+
}
|
2151
|
+
|
2152
|
+
// negation
|
2153
|
+
should.not = {}
|
2154
|
+
|
2155
|
+
should.not.equal = function (val1, val2) {
|
2156
|
+
new Assertion(val1).to.not.equal(val2);
|
2157
|
+
};
|
2158
|
+
|
2159
|
+
should.not.Throw = function (fn, errt, errs) {
|
2160
|
+
new Assertion(fn).to.not.Throw(errt, errs);
|
2161
|
+
};
|
2162
|
+
|
2163
|
+
should.not.exist = function (val) {
|
2164
|
+
new Assertion(val).to.not.exist;
|
2165
|
+
}
|
2166
|
+
|
2167
|
+
should['throw'] = should['Throw'];
|
2168
|
+
should.not['throw'] = should.not['Throw'];
|
2169
|
+
|
2170
|
+
return should;
|
2171
|
+
};
|
2172
|
+
|
2173
|
+
chai.should = loadShould;
|
2174
|
+
chai.Should = loadShould;
|
2175
|
+
};
|
2176
|
+
|
2177
|
+
}); // module: interface/should.js
|
2178
|
+
|
2179
|
+
require.register("utils/addMethod.js", function(module, exports, require){
|
2180
|
+
/*!
|
2181
|
+
* Chai - addMethod utility
|
2182
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2183
|
+
* MIT Licensed
|
2184
|
+
*/
|
2185
|
+
|
2186
|
+
/**
|
2187
|
+
* ### addMethod (ctx, name, method)
|
2188
|
+
*
|
2189
|
+
* Adds a method to the prototype of an object.
|
2190
|
+
*
|
2191
|
+
* utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
|
2192
|
+
* var obj = utils.flag(this, 'object');
|
2193
|
+
* new chai.Assertion(obj).to.be.equal(str);
|
2194
|
+
* });
|
2195
|
+
*
|
2196
|
+
* Can also be accessed directly from `chai.Assertion`.
|
2197
|
+
*
|
2198
|
+
* chai.Assertion.addMethod('foo', fn);
|
2199
|
+
*
|
2200
|
+
* Then can be used as any other assertion.
|
2201
|
+
*
|
2202
|
+
* expect(fooStr).to.be.foo('bar');
|
2203
|
+
*
|
2204
|
+
* @param {Object} ctx object to which the method is added
|
2205
|
+
* @param {String} name of method to add
|
2206
|
+
* @param {Function} method function to be used for name
|
2207
|
+
* @name addMethod
|
2208
|
+
* @api public
|
2209
|
+
*/
|
2210
|
+
|
2211
|
+
module.exports = function (ctx, name, method) {
|
2212
|
+
ctx[name] = function () {
|
2213
|
+
var result = method.apply(this, arguments);
|
2214
|
+
return result === undefined ? this : result;
|
2215
|
+
};
|
2216
|
+
};
|
2217
|
+
|
2218
|
+
}); // module: utils/addMethod.js
|
2219
|
+
|
2220
|
+
require.register("utils/addProperty.js", function(module, exports, require){
|
2221
|
+
/*!
|
2222
|
+
* Chai - addProperty utility
|
2223
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2224
|
+
* MIT Licensed
|
2225
|
+
*/
|
2226
|
+
|
2227
|
+
/**
|
2228
|
+
* ### addProperty (ctx, name, getter)
|
2229
|
+
*
|
2230
|
+
* Adds a property to the prototype of an object.
|
2231
|
+
*
|
2232
|
+
* utils.addProperty(chai.Assertion.prototype, 'foo', function () {
|
2233
|
+
* var obj = utils.flag(this, 'object');
|
2234
|
+
* new chai.Assertion(obj).to.be.instanceof(Foo);
|
2235
|
+
* });
|
2236
|
+
*
|
2237
|
+
* Can also be accessed directly from `chai.Assertion`.
|
2238
|
+
*
|
2239
|
+
* chai.Assertion.addProperty('foo', fn);
|
2240
|
+
*
|
2241
|
+
* Then can be used as any other assertion.
|
2242
|
+
*
|
2243
|
+
* expect(myFoo).to.be.foo;
|
2244
|
+
*
|
2245
|
+
* @param {Object} ctx object to which the property is added
|
2246
|
+
* @param {String} name of property to add
|
2247
|
+
* @param {Function} getter function to be used for name
|
2248
|
+
* @name addProperty
|
2249
|
+
* @api public
|
2250
|
+
*/
|
2251
|
+
|
2252
|
+
module.exports = function (ctx, name, getter) {
|
2253
|
+
Object.defineProperty(ctx, name,
|
2254
|
+
{ get: function () {
|
2255
|
+
var result = getter.call(this);
|
2256
|
+
return result === undefined ? this : result;
|
2257
|
+
}
|
2258
|
+
, configurable: true
|
2259
|
+
});
|
2260
|
+
};
|
2261
|
+
|
2262
|
+
}); // module: utils/addProperty.js
|
2263
|
+
|
2264
|
+
require.register("utils/eql.js", function(module, exports, require){
|
2265
|
+
// This is directly from Node.js assert
|
2266
|
+
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
2267
|
+
|
2268
|
+
|
2269
|
+
module.exports = _deepEqual;
|
2270
|
+
|
2271
|
+
// For browser implementation
|
2272
|
+
if (!Buffer) {
|
2273
|
+
var Buffer = {
|
2274
|
+
isBuffer: function () {
|
2275
|
+
return false;
|
2276
|
+
}
|
2277
|
+
};
|
2278
|
+
}
|
2279
|
+
|
2280
|
+
function _deepEqual(actual, expected) {
|
2281
|
+
// 7.1. All identical values are equivalent, as determined by ===.
|
2282
|
+
if (actual === expected) {
|
2283
|
+
return true;
|
2284
|
+
|
2285
|
+
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
|
2286
|
+
if (actual.length != expected.length) return false;
|
2287
|
+
|
2288
|
+
for (var i = 0; i < actual.length; i++) {
|
2289
|
+
if (actual[i] !== expected[i]) return false;
|
2290
|
+
}
|
2291
|
+
|
2292
|
+
return true;
|
2293
|
+
|
2294
|
+
// 7.2. If the expected value is a Date object, the actual value is
|
2295
|
+
// equivalent if it is also a Date object that refers to the same time.
|
2296
|
+
} else if (actual instanceof Date && expected instanceof Date) {
|
2297
|
+
return actual.getTime() === expected.getTime();
|
2298
|
+
|
2299
|
+
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
2300
|
+
// equivalence is determined by ==.
|
2301
|
+
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
2302
|
+
return actual === expected;
|
2303
|
+
|
2304
|
+
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
2305
|
+
// determined by having the same number of owned properties (as verified
|
2306
|
+
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
2307
|
+
// (although not necessarily the same order), equivalent values for every
|
2308
|
+
// corresponding key, and an identical 'prototype' property. Note: this
|
2309
|
+
// accounts for both named and indexed properties on Arrays.
|
2310
|
+
} else {
|
2311
|
+
return objEquiv(actual, expected);
|
2312
|
+
}
|
2313
|
+
}
|
2314
|
+
|
2315
|
+
function isUndefinedOrNull(value) {
|
2316
|
+
return value === null || value === undefined;
|
2317
|
+
}
|
2318
|
+
|
2319
|
+
function isArguments(object) {
|
2320
|
+
return Object.prototype.toString.call(object) == '[object Arguments]';
|
2321
|
+
}
|
2322
|
+
|
2323
|
+
function objEquiv(a, b) {
|
2324
|
+
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
2325
|
+
return false;
|
2326
|
+
// an identical 'prototype' property.
|
2327
|
+
if (a.prototype !== b.prototype) return false;
|
2328
|
+
//~~~I've managed to break Object.keys through screwy arguments passing.
|
2329
|
+
// Converting to array solves the problem.
|
2330
|
+
if (isArguments(a)) {
|
2331
|
+
if (!isArguments(b)) {
|
2332
|
+
return false;
|
2333
|
+
}
|
2334
|
+
a = pSlice.call(a);
|
2335
|
+
b = pSlice.call(b);
|
2336
|
+
return _deepEqual(a, b);
|
2337
|
+
}
|
2338
|
+
try {
|
2339
|
+
var ka = Object.keys(a),
|
2340
|
+
kb = Object.keys(b),
|
2341
|
+
key, i;
|
2342
|
+
} catch (e) {//happens when one is a string literal and the other isn't
|
2343
|
+
return false;
|
2344
|
+
}
|
2345
|
+
// having the same number of owned properties (keys incorporates
|
2346
|
+
// hasOwnProperty)
|
2347
|
+
if (ka.length != kb.length)
|
2348
|
+
return false;
|
2349
|
+
//the same set of keys (although not necessarily the same order),
|
2350
|
+
ka.sort();
|
2351
|
+
kb.sort();
|
2352
|
+
//~~~cheap key test
|
2353
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
2354
|
+
if (ka[i] != kb[i])
|
2355
|
+
return false;
|
2356
|
+
}
|
2357
|
+
//equivalent values for every corresponding key, and
|
2358
|
+
//~~~possibly expensive deep test
|
2359
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
2360
|
+
key = ka[i];
|
2361
|
+
if (!_deepEqual(a[key], b[key])) return false;
|
2362
|
+
}
|
2363
|
+
return true;
|
2364
|
+
}
|
2365
|
+
}); // module: utils/eql.js
|
2366
|
+
|
2367
|
+
require.register("utils/flag.js", function(module, exports, require){
|
2368
|
+
/*!
|
2369
|
+
* Chai - flag utility
|
2370
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2371
|
+
* MIT Licensed
|
2372
|
+
*/
|
2373
|
+
|
2374
|
+
/**
|
2375
|
+
* ### flag(object ,key, [value])
|
2376
|
+
*
|
2377
|
+
* Get or set a flag value on an object. If a
|
2378
|
+
* value is provided it will be set, else it will
|
2379
|
+
* return the currently set value or `undefined` if
|
2380
|
+
* the value is not set.
|
2381
|
+
*
|
2382
|
+
* utils.flag(this, 'foo', 'bar'); // setter
|
2383
|
+
* utils.flag(this, 'foo'); // getter, returns `bar`
|
2384
|
+
*
|
2385
|
+
* @param {Object} object (constructed Assertion
|
2386
|
+
* @param {String} key
|
2387
|
+
* @param {Mixed} value (optional)
|
2388
|
+
* @name flag
|
2389
|
+
* @api private
|
2390
|
+
*/
|
2391
|
+
|
2392
|
+
module.exports = function (obj, key, value) {
|
2393
|
+
var flags = obj.__flags || (obj.__flags = Object.create(null));
|
2394
|
+
if (arguments.length === 3) {
|
2395
|
+
flags[key] = value;
|
2396
|
+
} else {
|
2397
|
+
return flags[key];
|
2398
|
+
}
|
2399
|
+
};
|
2400
|
+
|
2401
|
+
}); // module: utils/flag.js
|
2402
|
+
|
2403
|
+
require.register("utils/getActual.js", function(module, exports, require){
|
2404
|
+
/*!
|
2405
|
+
* Chai - getActual utility
|
2406
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2407
|
+
* MIT Licensed
|
2408
|
+
*/
|
2409
|
+
|
2410
|
+
/**
|
2411
|
+
* # getActual(object, [actual])
|
2412
|
+
*
|
2413
|
+
* Returns the `actual` value for an Assertion
|
2414
|
+
*
|
2415
|
+
* @param {Object} object (constructed Assertion)
|
2416
|
+
* @param {Arguments} chai.Assertion.prototype.assert arguments
|
2417
|
+
*/
|
2418
|
+
|
2419
|
+
module.exports = function (obj, args) {
|
2420
|
+
var actual = args[4];
|
2421
|
+
return 'undefined' !== actual ? actual : obj.obj;
|
2422
|
+
};
|
2423
|
+
|
2424
|
+
}); // module: utils/getActual.js
|
2425
|
+
|
2426
|
+
require.register("utils/getMessage.js", function(module, exports, require){
|
2427
|
+
/*!
|
2428
|
+
* Chai - message composition utility
|
2429
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2430
|
+
* MIT Licensed
|
2431
|
+
*/
|
2432
|
+
|
2433
|
+
/*!
|
2434
|
+
* Module dependancies
|
2435
|
+
*/
|
2436
|
+
|
2437
|
+
var flag = require('./flag')
|
2438
|
+
, getActual = require('./getActual')
|
2439
|
+
, inspect = require('./inspect');
|
2440
|
+
|
2441
|
+
/**
|
2442
|
+
* # getMessage(object, message, negateMessage)
|
2443
|
+
*
|
2444
|
+
* Construct the error message based on flags
|
2445
|
+
* and template tags. Template tags will return
|
2446
|
+
* a stringified inspection of the object referenced.
|
2447
|
+
*
|
2448
|
+
* Messsage template tags:
|
2449
|
+
* - `#{this}` current asserted object
|
2450
|
+
* - `#{act}` actual value
|
2451
|
+
* - `#{exp}` expected value
|
2452
|
+
*
|
2453
|
+
* @param {Object} object (constructed Assertion)
|
2454
|
+
* @param {Arguments} chai.Assertion.prototype.assert arguments
|
2455
|
+
*/
|
2456
|
+
|
2457
|
+
module.exports = function (obj, args) {
|
2458
|
+
var negate = flag(obj, 'negate')
|
2459
|
+
, val = flag(obj, 'object')
|
2460
|
+
, expected = args[3]
|
2461
|
+
, actual = getActual(obj, args)
|
2462
|
+
, msg = negate ? args[2] : args[1]
|
2463
|
+
, flagMsg = flag(obj, 'message');
|
2464
|
+
|
2465
|
+
msg = msg || '';
|
2466
|
+
msg = msg
|
2467
|
+
.replace(/#{this}/g, inspect(val))
|
2468
|
+
.replace(/#{act}/g, inspect(actual))
|
2469
|
+
.replace(/#{exp}/g, inspect(expected));
|
2470
|
+
|
2471
|
+
return flagMsg ? flagMsg + ': ' + msg : msg;
|
2472
|
+
};
|
2473
|
+
|
2474
|
+
}); // module: utils/getMessage.js
|
2475
|
+
|
2476
|
+
require.register("utils/getName.js", function(module, exports, require){
|
2477
|
+
/*!
|
2478
|
+
* Chai - getName utility
|
2479
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2480
|
+
* MIT Licensed
|
2481
|
+
*/
|
2482
|
+
|
2483
|
+
/**
|
2484
|
+
* # getName(func)
|
2485
|
+
*
|
2486
|
+
* Gets the name of a function, in a cross-browser way.
|
2487
|
+
*
|
2488
|
+
* @param {Function} a function (usually a constructor)
|
2489
|
+
*/
|
2490
|
+
|
2491
|
+
module.exports = function (func) {
|
2492
|
+
if (func.name) return func.name;
|
2493
|
+
|
2494
|
+
var match = /^\s?function ([^(]*)\(/.exec(func);
|
2495
|
+
return match && match[1] ? match[1] : "";
|
2496
|
+
};
|
2497
|
+
|
2498
|
+
}); // module: utils/getName.js
|
2499
|
+
|
2500
|
+
require.register("utils/getPathValue.js", function(module, exports, require){
|
2501
|
+
/*!
|
2502
|
+
* Chai - getPathValue utility
|
2503
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2504
|
+
* @see https://github.com/logicalparadox/filtr
|
2505
|
+
* MIT Licensed
|
2506
|
+
*/
|
2507
|
+
|
2508
|
+
/**
|
2509
|
+
* ### .getPathValue(path, object)
|
2510
|
+
*
|
2511
|
+
* This allows the retrieval of values in an
|
2512
|
+
* object given a string path.
|
2513
|
+
*
|
2514
|
+
* var obj = {
|
2515
|
+
* prop1: {
|
2516
|
+
* arr: ['a', 'b', 'c']
|
2517
|
+
* , str: 'Hello'
|
2518
|
+
* }
|
2519
|
+
* , prop2: {
|
2520
|
+
* arr: [ { nested: 'Universe' } ]
|
2521
|
+
* , str: 'Hello again!'
|
2522
|
+
* }
|
2523
|
+
* }
|
2524
|
+
*
|
2525
|
+
* The following would be the results.
|
2526
|
+
*
|
2527
|
+
* getPathValue('prop1.str', obj); // Hello
|
2528
|
+
* getPathValue('prop1.att[2]', obj); // b
|
2529
|
+
* getPathValue('prop2.arr[0].nested', obj); // Universe
|
2530
|
+
*
|
2531
|
+
* @param {String} path
|
2532
|
+
* @param {Object} object
|
2533
|
+
* @returns {Object} value or `undefined`
|
2534
|
+
* @name getPathValue
|
2535
|
+
* @api public
|
2536
|
+
*/
|
2537
|
+
|
2538
|
+
var getPathValue = module.exports = function (path, obj) {
|
2539
|
+
var parsed = parsePath(path);
|
2540
|
+
return _getPathValue(parsed, obj);
|
2541
|
+
};
|
2542
|
+
|
2543
|
+
/*!
|
2544
|
+
* ## parsePath(path)
|
2545
|
+
*
|
2546
|
+
* Helper function used to parse string object
|
2547
|
+
* paths. Use in conjunction with `_getPathValue`.
|
2548
|
+
*
|
2549
|
+
* var parsed = parsePath('myobject.property.subprop');
|
2550
|
+
*
|
2551
|
+
* ### Paths:
|
2552
|
+
*
|
2553
|
+
* * Can be as near infinitely deep and nested
|
2554
|
+
* * Arrays are also valid using the formal `myobject.document[3].property`.
|
2555
|
+
*
|
2556
|
+
* @param {String} path
|
2557
|
+
* @returns {Object} parsed
|
2558
|
+
* @api private
|
2559
|
+
*/
|
2560
|
+
|
2561
|
+
function parsePath (path) {
|
2562
|
+
var parts = path.split('.').filter(Boolean);
|
2563
|
+
return parts.map(function (value) {
|
2564
|
+
var re = /([A-Za-z0-9]+)\[(\d+)\]$/
|
2565
|
+
, mArr = re.exec(value)
|
2566
|
+
, val;
|
2567
|
+
if (mArr) val = { p: mArr[1], i: parseFloat(mArr[2]) };
|
2568
|
+
return val || value;
|
2569
|
+
});
|
2570
|
+
};
|
2571
|
+
|
2572
|
+
/*!
|
2573
|
+
* ## _getPathValue(parsed, obj)
|
2574
|
+
*
|
2575
|
+
* Helper companion function for `.parsePath` that returns
|
2576
|
+
* the value located at the parsed address.
|
2577
|
+
*
|
2578
|
+
* var value = getPathValue(parsed, obj);
|
2579
|
+
*
|
2580
|
+
* @param {Object} parsed definition from `parsePath`.
|
2581
|
+
* @param {Object} object to search against
|
2582
|
+
* @returns {Object|Undefined} value
|
2583
|
+
* @api private
|
2584
|
+
*/
|
2585
|
+
|
2586
|
+
function _getPathValue (parsed, obj) {
|
2587
|
+
var tmp = obj
|
2588
|
+
, res;
|
2589
|
+
for (var i = 0, l = parsed.length; i < l; i++) {
|
2590
|
+
var part = parsed[i];
|
2591
|
+
if (tmp) {
|
2592
|
+
if ('object' === typeof part && tmp[part.p]) {
|
2593
|
+
tmp = tmp[part.p][part.i];
|
2594
|
+
} else {
|
2595
|
+
tmp = tmp[part];
|
2596
|
+
}
|
2597
|
+
if (i == (l - 1)) res = tmp;
|
2598
|
+
} else {
|
2599
|
+
res = undefined;
|
2600
|
+
}
|
2601
|
+
}
|
2602
|
+
return res;
|
2603
|
+
};
|
2604
|
+
|
2605
|
+
}); // module: utils/getPathValue.js
|
2606
|
+
|
2607
|
+
require.register("utils/index.js", function(module, exports, require){
|
2608
|
+
/*!
|
2609
|
+
* chai
|
2610
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
2611
|
+
* MIT Licensed
|
2612
|
+
*/
|
2613
|
+
|
2614
|
+
/*!
|
2615
|
+
* Main exports
|
2616
|
+
*/
|
2617
|
+
|
2618
|
+
var exports = module.exports = {};
|
2619
|
+
|
2620
|
+
/*!
|
2621
|
+
* test utility
|
2622
|
+
*/
|
2623
|
+
|
2624
|
+
exports.test = require('./test');
|
2625
|
+
|
2626
|
+
/*!
|
2627
|
+
* message utility
|
2628
|
+
*/
|
2629
|
+
|
2630
|
+
exports.getMessage = require('./getMessage');
|
2631
|
+
|
2632
|
+
/*!
|
2633
|
+
* actual utility
|
2634
|
+
*/
|
2635
|
+
|
2636
|
+
exports.getActual = require('./getActual');
|
2637
|
+
|
2638
|
+
/*!
|
2639
|
+
* Inspect util
|
2640
|
+
*/
|
2641
|
+
|
2642
|
+
exports.inspect = require('./inspect');
|
2643
|
+
|
2644
|
+
/*!
|
2645
|
+
* Flag utility
|
2646
|
+
*/
|
2647
|
+
|
2648
|
+
exports.flag = require('./flag');
|
2649
|
+
|
2650
|
+
/*!
|
2651
|
+
* Deep equal utility
|
2652
|
+
*/
|
2653
|
+
|
2654
|
+
exports.eql = require('./eql');
|
2655
|
+
|
2656
|
+
/*!
|
2657
|
+
* Deep path value
|
2658
|
+
*/
|
2659
|
+
|
2660
|
+
exports.getPathValue = require('./getPathValue');
|
2661
|
+
|
2662
|
+
/*!
|
2663
|
+
* Function name
|
2664
|
+
*/
|
2665
|
+
|
2666
|
+
exports.getName = require('./getName');
|
2667
|
+
|
2668
|
+
/*!
|
2669
|
+
* add Property
|
2670
|
+
*/
|
2671
|
+
|
2672
|
+
exports.addProperty = require('./addProperty');
|
2673
|
+
|
2674
|
+
/*!
|
2675
|
+
* add Method
|
2676
|
+
*/
|
2677
|
+
|
2678
|
+
exports.addMethod = require('./addMethod');
|
2679
|
+
|
2680
|
+
/*!
|
2681
|
+
* overwrite Property
|
2682
|
+
*/
|
2683
|
+
|
2684
|
+
exports.overwriteProperty = require('./overwriteProperty');
|
2685
|
+
|
2686
|
+
/*!
|
2687
|
+
* overwrite Method
|
2688
|
+
*/
|
2689
|
+
|
2690
|
+
exports.overwriteMethod = require('./overwriteMethod');
|
2691
|
+
|
2692
|
+
}); // module: utils/index.js
|
2693
|
+
|
2694
|
+
require.register("utils/inspect.js", function(module, exports, require){
|
2695
|
+
// This is (almost) directly from Node.js utils
|
2696
|
+
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
|
2697
|
+
|
2698
|
+
var getName = require('./getName');
|
2699
|
+
|
2700
|
+
module.exports = inspect;
|
2701
|
+
|
2702
|
+
/**
|
2703
|
+
* Echos the value of a value. Trys to print the value out
|
2704
|
+
* in the best way possible given the different types.
|
2705
|
+
*
|
2706
|
+
* @param {Object} obj The object to print out.
|
2707
|
+
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
2708
|
+
* properties of objects.
|
2709
|
+
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
2710
|
+
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
2711
|
+
* output. Default is false (no coloring).
|
2712
|
+
*/
|
2713
|
+
function inspect(obj, showHidden, depth, colors) {
|
2714
|
+
var ctx = {
|
2715
|
+
showHidden: showHidden,
|
2716
|
+
seen: [],
|
2717
|
+
stylize: function (str) { return str; }
|
2718
|
+
};
|
2719
|
+
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
2720
|
+
}
|
2721
|
+
|
2722
|
+
function formatValue(ctx, value, recurseTimes) {
|
2723
|
+
// Provide a hook for user-specified inspect functions.
|
2724
|
+
// Check that value is an object with an inspect function on it
|
2725
|
+
if (value && typeof value.inspect === 'function' &&
|
2726
|
+
// Filter out the util module, it's inspect function is special
|
2727
|
+
value.inspect !== exports.inspect &&
|
2728
|
+
// Also filter out any prototype objects using the circular check.
|
2729
|
+
!(value.constructor && value.constructor.prototype === value)) {
|
2730
|
+
return value.inspect(recurseTimes);
|
2731
|
+
}
|
2732
|
+
|
2733
|
+
// Primitive types cannot have properties
|
2734
|
+
var primitive = formatPrimitive(ctx, value);
|
2735
|
+
if (primitive) {
|
2736
|
+
return primitive;
|
2737
|
+
}
|
2738
|
+
|
2739
|
+
// Look up the keys of the object.
|
2740
|
+
var visibleKeys = Object.keys(value);
|
2741
|
+
var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
|
2742
|
+
|
2743
|
+
// Some type of object without properties can be shortcutted.
|
2744
|
+
// In IE, errors have a single `stack` property, or if they are vanilla `Error`,
|
2745
|
+
// a `stack` plus `description` property; ignore those for consistency.
|
2746
|
+
if (keys.length === 0 || (isError(value) && (
|
2747
|
+
(keys.length === 1 && keys[0] === 'stack') ||
|
2748
|
+
(keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
|
2749
|
+
))) {
|
2750
|
+
if (typeof value === 'function') {
|
2751
|
+
var name = getName(value);
|
2752
|
+
var nameSuffix = name ? ': ' + name : '';
|
2753
|
+
return ctx.stylize('[Function' + nameSuffix + ']', 'special');
|
2754
|
+
}
|
2755
|
+
if (isRegExp(value)) {
|
2756
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
2757
|
+
}
|
2758
|
+
if (isDate(value)) {
|
2759
|
+
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
|
2760
|
+
}
|
2761
|
+
if (isError(value)) {
|
2762
|
+
return formatError(value);
|
2763
|
+
}
|
2764
|
+
}
|
2765
|
+
|
2766
|
+
var base = '', array = false, braces = ['{', '}'];
|
2767
|
+
|
2768
|
+
// Make Array say that they are Array
|
2769
|
+
if (isArray(value)) {
|
2770
|
+
array = true;
|
2771
|
+
braces = ['[', ']'];
|
2772
|
+
}
|
2773
|
+
|
2774
|
+
// Make functions say that they are functions
|
2775
|
+
if (typeof value === 'function') {
|
2776
|
+
var n = value.name ? ': ' + value.name : '';
|
2777
|
+
base = ' [Function' + n + ']';
|
2778
|
+
}
|
2779
|
+
|
2780
|
+
// Make RegExps say that they are RegExps
|
2781
|
+
if (isRegExp(value)) {
|
2782
|
+
base = ' ' + RegExp.prototype.toString.call(value);
|
2783
|
+
}
|
2784
|
+
|
2785
|
+
// Make dates with properties first say the date
|
2786
|
+
if (isDate(value)) {
|
2787
|
+
base = ' ' + Date.prototype.toUTCString.call(value);
|
2788
|
+
}
|
2789
|
+
|
2790
|
+
// Make error with message first say the error
|
2791
|
+
if (isError(value)) {
|
2792
|
+
base = ' ' + formatError(value);
|
2793
|
+
}
|
2794
|
+
|
2795
|
+
if (keys.length === 0 && (!array || value.length == 0)) {
|
2796
|
+
return braces[0] + base + braces[1];
|
2797
|
+
}
|
2798
|
+
|
2799
|
+
if (recurseTimes < 0) {
|
2800
|
+
if (isRegExp(value)) {
|
2801
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
2802
|
+
} else {
|
2803
|
+
return ctx.stylize('[Object]', 'special');
|
2804
|
+
}
|
2805
|
+
}
|
2806
|
+
|
2807
|
+
ctx.seen.push(value);
|
2808
|
+
|
2809
|
+
var output;
|
2810
|
+
if (array) {
|
2811
|
+
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
2812
|
+
} else {
|
2813
|
+
output = keys.map(function(key) {
|
2814
|
+
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
2815
|
+
});
|
2816
|
+
}
|
2817
|
+
|
2818
|
+
ctx.seen.pop();
|
2819
|
+
|
2820
|
+
return reduceToSingleString(output, base, braces);
|
2821
|
+
}
|
2822
|
+
|
2823
|
+
|
2824
|
+
function formatPrimitive(ctx, value) {
|
2825
|
+
switch (typeof value) {
|
2826
|
+
case 'undefined':
|
2827
|
+
return ctx.stylize('undefined', 'undefined');
|
2828
|
+
|
2829
|
+
case 'string':
|
2830
|
+
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
2831
|
+
.replace(/'/g, "\\'")
|
2832
|
+
.replace(/\\"/g, '"') + '\'';
|
2833
|
+
return ctx.stylize(simple, 'string');
|
2834
|
+
|
2835
|
+
case 'number':
|
2836
|
+
return ctx.stylize('' + value, 'number');
|
2837
|
+
|
2838
|
+
case 'boolean':
|
2839
|
+
return ctx.stylize('' + value, 'boolean');
|
2840
|
+
}
|
2841
|
+
// For some reason typeof null is "object", so special case here.
|
2842
|
+
if (value === null) {
|
2843
|
+
return ctx.stylize('null', 'null');
|
2844
|
+
}
|
2845
|
+
}
|
2846
|
+
|
2847
|
+
|
2848
|
+
function formatError(value) {
|
2849
|
+
return '[' + Error.prototype.toString.call(value) + ']';
|
2850
|
+
}
|
2851
|
+
|
2852
|
+
|
2853
|
+
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
2854
|
+
var output = [];
|
2855
|
+
for (var i = 0, l = value.length; i < l; ++i) {
|
2856
|
+
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
|
2857
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
2858
|
+
String(i), true));
|
2859
|
+
} else {
|
2860
|
+
output.push('');
|
2861
|
+
}
|
2862
|
+
}
|
2863
|
+
keys.forEach(function(key) {
|
2864
|
+
if (!key.match(/^\d+$/)) {
|
2865
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
2866
|
+
key, true));
|
2867
|
+
}
|
2868
|
+
});
|
2869
|
+
return output;
|
2870
|
+
}
|
2871
|
+
|
2872
|
+
|
2873
|
+
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
2874
|
+
var name, str;
|
2875
|
+
if (value.__lookupGetter__) {
|
2876
|
+
if (value.__lookupGetter__(key)) {
|
2877
|
+
if (value.__lookupSetter__(key)) {
|
2878
|
+
str = ctx.stylize('[Getter/Setter]', 'special');
|
2879
|
+
} else {
|
2880
|
+
str = ctx.stylize('[Getter]', 'special');
|
2881
|
+
}
|
2882
|
+
} else {
|
2883
|
+
if (value.__lookupSetter__(key)) {
|
2884
|
+
str = ctx.stylize('[Setter]', 'special');
|
2885
|
+
}
|
2886
|
+
}
|
2887
|
+
}
|
2888
|
+
if (visibleKeys.indexOf(key) < 0) {
|
2889
|
+
name = '[' + key + ']';
|
2890
|
+
}
|
2891
|
+
if (!str) {
|
2892
|
+
if (ctx.seen.indexOf(value[key]) < 0) {
|
2893
|
+
if (recurseTimes === null) {
|
2894
|
+
str = formatValue(ctx, value[key], null);
|
2895
|
+
} else {
|
2896
|
+
str = formatValue(ctx, value[key], recurseTimes - 1);
|
2897
|
+
}
|
2898
|
+
if (str.indexOf('\n') > -1) {
|
2899
|
+
if (array) {
|
2900
|
+
str = str.split('\n').map(function(line) {
|
2901
|
+
return ' ' + line;
|
2902
|
+
}).join('\n').substr(2);
|
2903
|
+
} else {
|
2904
|
+
str = '\n' + str.split('\n').map(function(line) {
|
2905
|
+
return ' ' + line;
|
2906
|
+
}).join('\n');
|
2907
|
+
}
|
2908
|
+
}
|
2909
|
+
} else {
|
2910
|
+
str = ctx.stylize('[Circular]', 'special');
|
2911
|
+
}
|
2912
|
+
}
|
2913
|
+
if (typeof name === 'undefined') {
|
2914
|
+
if (array && key.match(/^\d+$/)) {
|
2915
|
+
return str;
|
2916
|
+
}
|
2917
|
+
name = JSON.stringify('' + key);
|
2918
|
+
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
2919
|
+
name = name.substr(1, name.length - 2);
|
2920
|
+
name = ctx.stylize(name, 'name');
|
2921
|
+
} else {
|
2922
|
+
name = name.replace(/'/g, "\\'")
|
2923
|
+
.replace(/\\"/g, '"')
|
2924
|
+
.replace(/(^"|"$)/g, "'");
|
2925
|
+
name = ctx.stylize(name, 'string');
|
2926
|
+
}
|
2927
|
+
}
|
2928
|
+
|
2929
|
+
return name + ': ' + str;
|
2930
|
+
}
|
2931
|
+
|
2932
|
+
|
2933
|
+
function reduceToSingleString(output, base, braces) {
|
2934
|
+
var numLinesEst = 0;
|
2935
|
+
var length = output.reduce(function(prev, cur) {
|
2936
|
+
numLinesEst++;
|
2937
|
+
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
2938
|
+
return prev + cur.length + 1;
|
2939
|
+
}, 0);
|
2940
|
+
|
2941
|
+
if (length > 60) {
|
2942
|
+
return braces[0] +
|
2943
|
+
(base === '' ? '' : base + '\n ') +
|
2944
|
+
' ' +
|
2945
|
+
output.join(',\n ') +
|
2946
|
+
' ' +
|
2947
|
+
braces[1];
|
2948
|
+
}
|
2949
|
+
|
2950
|
+
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
2951
|
+
}
|
2952
|
+
|
2953
|
+
function isArray(ar) {
|
2954
|
+
return Array.isArray(ar) ||
|
2955
|
+
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
2956
|
+
}
|
2957
|
+
|
2958
|
+
function isRegExp(re) {
|
2959
|
+
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
2960
|
+
}
|
2961
|
+
|
2962
|
+
function isDate(d) {
|
2963
|
+
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
2964
|
+
}
|
2965
|
+
|
2966
|
+
function isError(e) {
|
2967
|
+
return typeof e === 'object' && objectToString(e) === '[object Error]';
|
2968
|
+
}
|
2969
|
+
|
2970
|
+
function objectToString(o) {
|
2971
|
+
return Object.prototype.toString.call(o);
|
2972
|
+
}
|
2973
|
+
}); // module: utils/inspect.js
|
2974
|
+
|
2975
|
+
require.register("utils/overwriteMethod.js", function(module, exports, require){
|
2976
|
+
/*!
|
2977
|
+
* Chai - overwriteMethod utility
|
2978
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
2979
|
+
* MIT Licensed
|
2980
|
+
*/
|
2981
|
+
|
2982
|
+
/**
|
2983
|
+
* ### overwriteMethod (ctx, name, fn)
|
2984
|
+
*
|
2985
|
+
* Overwites an already existing method and provides
|
2986
|
+
* access to previous function. Must return function
|
2987
|
+
* to be used for name.
|
2988
|
+
*
|
2989
|
+
* utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
|
2990
|
+
* return function (str) {
|
2991
|
+
* var obj = utils.flag(this, 'object');
|
2992
|
+
* if (obj instanceof Foo) {
|
2993
|
+
* new chai.Assertion(obj.value).to.equal(str);
|
2994
|
+
* } else {
|
2995
|
+
* _super.apply(this, arguments);
|
2996
|
+
* }
|
2997
|
+
* }
|
2998
|
+
* });
|
2999
|
+
*
|
3000
|
+
* Can also be accessed directly from `chai.Assertion`.
|
3001
|
+
*
|
3002
|
+
* chai.Assertion.overwriteMethod('foo', fn);
|
3003
|
+
*
|
3004
|
+
* Then can be used as any other assertion.
|
3005
|
+
*
|
3006
|
+
* expect(myFoo).to.equal('bar');
|
3007
|
+
*
|
3008
|
+
* @param {Object} ctx object whose method is to be overwritten
|
3009
|
+
* @param {String} name of method to overwrite
|
3010
|
+
* @param {Function} method function that returns a function to be used for name
|
3011
|
+
* @name overwriteMethod
|
3012
|
+
* @api public
|
3013
|
+
*/
|
3014
|
+
|
3015
|
+
module.exports = function (ctx, name, method) {
|
3016
|
+
var _method = ctx[name]
|
3017
|
+
, _super = function () { return this; };
|
3018
|
+
|
3019
|
+
if (_method && 'function' === typeof _method)
|
3020
|
+
_super = _method;
|
3021
|
+
|
3022
|
+
ctx[name] = function () {
|
3023
|
+
var result = method(_super).apply(this, arguments);
|
3024
|
+
return result === undefined ? this : result;
|
3025
|
+
}
|
3026
|
+
};
|
3027
|
+
|
3028
|
+
}); // module: utils/overwriteMethod.js
|
3029
|
+
|
3030
|
+
require.register("utils/overwriteProperty.js", function(module, exports, require){
|
3031
|
+
/*!
|
3032
|
+
* Chai - overwriteProperty utility
|
3033
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
3034
|
+
* MIT Licensed
|
3035
|
+
*/
|
3036
|
+
|
3037
|
+
/**
|
3038
|
+
* ### overwriteProperty (ctx, name, fn)
|
3039
|
+
*
|
3040
|
+
* Overwites an already existing property getter and provides
|
3041
|
+
* access to previous value. Must return function to use as getter.
|
3042
|
+
*
|
3043
|
+
* utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
|
3044
|
+
* return function () {
|
3045
|
+
* var obj = utils.flag(this, 'object');
|
3046
|
+
* if (obj instanceof Foo) {
|
3047
|
+
* new chai.Assertion(obj.name).to.equal('bar');
|
3048
|
+
* } else {
|
3049
|
+
* _super.call(this);
|
3050
|
+
* }
|
3051
|
+
* }
|
3052
|
+
* });
|
3053
|
+
*
|
3054
|
+
*
|
3055
|
+
* Can also be accessed directly from `chai.Assertion`.
|
3056
|
+
*
|
3057
|
+
* chai.Assertion.overwriteProperty('foo', fn);
|
3058
|
+
*
|
3059
|
+
* Then can be used as any other assertion.
|
3060
|
+
*
|
3061
|
+
* expect(myFoo).to.be.ok;
|
3062
|
+
*
|
3063
|
+
* @param {Object} ctx object whose property is to be overwritten
|
3064
|
+
* @param {String} name of property to overwrite
|
3065
|
+
* @param {Function} getter function that returns a getter function to be used for name
|
3066
|
+
* @name overwriteProperty
|
3067
|
+
* @api public
|
3068
|
+
*/
|
3069
|
+
|
3070
|
+
module.exports = function (ctx, name, getter) {
|
3071
|
+
var _get = Object.getOwnPropertyDescriptor(ctx, name)
|
3072
|
+
, _super = function () {};
|
3073
|
+
|
3074
|
+
if (_get && 'function' === typeof _get.get)
|
3075
|
+
_super = _get.get
|
3076
|
+
|
3077
|
+
Object.defineProperty(ctx, name,
|
3078
|
+
{ get: function () {
|
3079
|
+
var result = getter(_super).call(this);
|
3080
|
+
return result === undefined ? this : result;
|
3081
|
+
}
|
3082
|
+
, configurable: true
|
3083
|
+
});
|
3084
|
+
};
|
3085
|
+
|
3086
|
+
}); // module: utils/overwriteProperty.js
|
3087
|
+
|
3088
|
+
require.register("utils/test.js", function(module, exports, require){
|
3089
|
+
/*!
|
3090
|
+
* Chai - test utility
|
3091
|
+
* Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
|
3092
|
+
* MIT Licensed
|
3093
|
+
*/
|
3094
|
+
|
3095
|
+
/*!
|
3096
|
+
* Module dependancies
|
3097
|
+
*/
|
3098
|
+
|
3099
|
+
var flag = require('./flag');
|
3100
|
+
|
3101
|
+
/**
|
3102
|
+
* # test(object, expression)
|
3103
|
+
*
|
3104
|
+
* Test and object for expression.
|
3105
|
+
*
|
3106
|
+
* @param {Object} object (constructed Assertion)
|
3107
|
+
* @param {Arguments} chai.Assertion.prototype.assert arguments
|
3108
|
+
*/
|
3109
|
+
|
3110
|
+
module.exports = function (obj, args) {
|
3111
|
+
var negate = flag(obj, 'negate')
|
3112
|
+
, expr = args[0];
|
3113
|
+
return negate ? !expr : expr;
|
3114
|
+
};
|
3115
|
+
|
3116
|
+
}); // module: utils/test.js
|
3117
|
+
|
3118
|
+
|
3119
|
+
return require('chai');
|
3120
|
+
});
|