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