transponder 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18ab8584fb3ef2402e4ca707fb242c0e401f0b48
4
- data.tar.gz: cf760feabb927f05f56b2328e1e73b139362b9b6
3
+ metadata.gz: 0fec12d7a52b2396ec3e8111eebdb23179dfe192
4
+ data.tar.gz: e0b9e960e3c27dc644a9a0fd4ad542a746bc5c61
5
5
  SHA512:
6
- metadata.gz: d7c69f20af83cc68fc137f5e1b42682b91ba20843f6a59e527553a930dcc75b0cfba5c1eb32039eb9f7ddfb886957a6faebb555ced3227826babb5f170b91c53
7
- data.tar.gz: 1d226691918d0f83bd235f33c19f05ccbb9905a1ab3d9ef3aaa3fe4b3e172041863b15b561f9bbb8b3634ed5606db016a289c0da03b5a98ca89ce9b36fec0941
6
+ metadata.gz: ba45cf22e5142201a664890c1ef153f8a5eaeac53bcdd2488de158745428369ad6986eb30c7d7bc5ab9890f8afa08b7d709c11b1eb0ddde136453df3fd12c1d9
7
+ data.tar.gz: d567cae128e3a632ff20a5f1d5e654b97060bcba54071bd5c3c09f052ebbd3d33937d2525b2ea65cdaf0be7e7f4fe7bfc6d08ae0335690468c5a594a2d3ab84a
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Transponder is a opinionated javascript library for assisting in working with front end heavy rails app.
7
7
 
8
- Transponder uncompressed is about 8kb minified & compressed (gzip) its 2kb
8
+ Transponder uncompressed is about 8kb uncompressed / 2kb minified & compressed (gzip)
9
9
 
10
10
  ## Installation
11
11
 
@@ -4,9 +4,12 @@ class Transponder.Response
4
4
  constructor: ->
5
5
  $(document).on 'ajax:complete', (event, xhr, status) =>
6
6
  if xhr.getResponseHeader('Content-Type') is 'application/transmission'
7
- @payload.raw = JSON.parse(xhr.responseText)
7
+ @payload.raw = JSON.parse(@cleanContent(xhr.responseText))
8
8
  element = @payload.raw[0]
9
9
  event_name = @payload.raw[1]
10
10
  content = @payload.raw[2]
11
11
 
12
12
  $(element).trigger(event_name, content)
13
+
14
+ cleanContent: (content) ->
15
+ content.replace(/'/g, '"');
@@ -1,3 +1,3 @@
1
1
  module Transponder
2
- VERSION = "0.9.2"
2
+ VERSION = "0.9.3"
3
3
  end
@@ -49,6 +49,7 @@
49
49
 
50
50
  after_configuration do
51
51
  sprockets.append_path "#{root}/../../../lib/assets/javascripts"
52
+ sprockets.append_path "#{root}/../../../vendor/test_suite"
52
53
  sprockets.append_path "#{root}/../../../spec/javascripts"
53
54
  sprockets.append_path "#{root}/../support"
54
55
  sprockets.append_path "#{root}/../../../examples"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transponder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Siri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-02 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails
@@ -91,12 +91,6 @@ files:
91
91
  - spec/javascripts/runner/source/javascripts/test_runner.js
92
92
  - spec/javascripts/runner/source/layouts/layout.erb
93
93
  - spec/javascripts/runner/source/stylesheets/mocha.css
94
- - spec/javascripts/support/chai-jquery.js
95
- - spec/javascripts/support/chai.js
96
- - spec/javascripts/support/jquery-2.js
97
- - spec/javascripts/support/mocha.js
98
- - spec/javascripts/support/sinon-chai.js
99
- - spec/javascripts/support/sinon.js
100
94
  - spec/javascripts/support/test_setup.js
101
95
  - spec/javascripts/transponder/presenter_test.coffee
102
96
  - spec/javascripts/transponder/presenters/examples_presenter_test.coffee
@@ -146,12 +140,6 @@ test_files:
146
140
  - spec/javascripts/runner/source/javascripts/test_runner.js
147
141
  - spec/javascripts/runner/source/layouts/layout.erb
148
142
  - spec/javascripts/runner/source/stylesheets/mocha.css
149
- - spec/javascripts/support/chai-jquery.js
150
- - spec/javascripts/support/chai.js
151
- - spec/javascripts/support/jquery-2.js
152
- - spec/javascripts/support/mocha.js
153
- - spec/javascripts/support/sinon-chai.js
154
- - spec/javascripts/support/sinon.js
155
143
  - spec/javascripts/support/test_setup.js
156
144
  - spec/javascripts/transponder/presenter_test.coffee
157
145
  - spec/javascripts/transponder/presenters/examples_presenter_test.coffee
@@ -1,237 +0,0 @@
1
- (function (chaiJquery) {
2
- // Module systems magic dance.
3
- if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
4
- // NodeJS
5
- module.exports = chaiJquery;
6
- } else if (typeof define === "function" && define.amd) {
7
- // AMD
8
- define(['jquery'], function ($) {
9
- return function (chai, utils) {
10
- return chaiJquery(chai, utils, $);
11
- };
12
- });
13
- } else {
14
- // Other environment (usually <script> tag): plug in to global chai instance directly.
15
- chai.use(function (chai, utils) {
16
- return chaiJquery(chai, utils, jQuery);
17
- });
18
- }
19
- }(function (chai, utils, $) {
20
- var inspect = utils.inspect,
21
- flag = utils.flag;
22
- $ = $ || jQuery;
23
-
24
- $.fn.inspect = function (depth) {
25
- var el = $('<div />').append(this.clone());
26
- if (depth !== undefined) {
27
- var children = el.children();
28
- while (depth-- > 0)
29
- children = children.children();
30
- children.html('...');
31
- }
32
- return el.html();
33
- };
34
-
35
- var props = {attr: 'attribute', css: 'CSS property'};
36
- for (var prop in props) {
37
- (function (prop, description) {
38
- chai.Assertion.addMethod(prop, function (name, val) {
39
- var actual = flag(this, 'object')[prop](name);
40
-
41
- if (!flag(this, 'negate') || undefined === val) {
42
- this.assert(
43
- undefined !== actual
44
- , 'expected #{this} to have a #{exp} ' + description
45
- , 'expected #{this} not to have a #{exp} ' + description
46
- , name
47
- );
48
- }
49
-
50
- if (undefined !== val) {
51
- this.assert(
52
- val === actual
53
- , 'expected #{this} to have a ' + inspect(name) + ' ' + description + ' with the value #{exp}, but the value was #{act}'
54
- , 'expected #{this} not to have a ' + inspect(name) + ' ' + description + ' with the value #{act}'
55
- , val
56
- , actual
57
- );
58
- }
59
-
60
- flag(this, 'object', actual);
61
- });
62
- })(prop, props[prop]);
63
- }
64
-
65
- chai.Assertion.addMethod('data', function (name, val) {
66
- // Work around a chai bug (https://github.com/logicalparadox/chai/issues/16)
67
- if (flag(this, 'negate') && undefined !== val && undefined === flag(this, 'object').data(name)) {
68
- return;
69
- }
70
-
71
- var assertion = new chai.Assertion(flag(this, 'object').data());
72
- if (flag(this, 'negate'))
73
- assertion = assertion.not;
74
- return assertion.property(name, val);
75
- });
76
-
77
- chai.Assertion.addMethod('class', function (className) {
78
- this.assert(
79
- flag(this, 'object').hasClass(className)
80
- , 'expected #{this} to have class #{exp}'
81
- , 'expected #{this} not to have class #{exp}'
82
- , className
83
- );
84
- });
85
-
86
- chai.Assertion.addMethod('id', function (id) {
87
- this.assert(
88
- flag(this, 'object').attr('id') === id
89
- , 'expected #{this} to have id #{exp}'
90
- , 'expected #{this} not to have id #{exp}'
91
- , id
92
- );
93
- });
94
-
95
- chai.Assertion.addMethod('html', function (html) {
96
- this.assert(
97
- flag(this, 'object').html() === html
98
- , 'expected #{this} to have HTML #{exp}'
99
- , 'expected #{this} not to have HTML #{exp}'
100
- , html
101
- );
102
- });
103
-
104
- chai.Assertion.addMethod('text', function (text) {
105
- this.assert(
106
- flag(this, 'object').text() === text
107
- , 'expected #{this} to have text #{exp}'
108
- , 'expected #{this} not to have text #{exp}'
109
- , text
110
- );
111
- });
112
-
113
- chai.Assertion.addMethod('value', function (value) {
114
- this.assert(
115
- flag(this, 'object').val() === value
116
- , 'expected #{this} to have value #{exp}'
117
- , 'expected #{this} not to have value #{exp}'
118
- , value
119
- );
120
- });
121
-
122
- $.each(['visible', 'hidden', 'selected', 'checked', 'disabled'], function (i, attr) {
123
- chai.Assertion.addProperty(attr, function () {
124
- this.assert(
125
- flag(this, 'object').is(':' + attr)
126
- , 'expected #{this} to be ' + attr
127
- , 'expected #{this} not to be ' + attr);
128
- });
129
- });
130
-
131
- chai.Assertion.overwriteProperty('exist', function (_super) {
132
- return function () {
133
- var obj = flag(this, 'object');
134
- if (obj instanceof $) {
135
- this.assert(
136
- obj.length > 0
137
- , 'expected ' + inspect(obj.selector) + ' to exist'
138
- , 'expected ' + inspect(obj.selector) + ' not to exist');
139
- } else {
140
- _super.apply(this, arguments);
141
- }
142
- };
143
- });
144
-
145
- chai.Assertion.overwriteProperty('empty', function (_super) {
146
- return function () {
147
- var obj = flag(this, 'object');
148
- if (obj instanceof $) {
149
- this.assert(
150
- obj.is(':empty')
151
- , 'expected #{this} to be empty'
152
- , 'expected #{this} not to be empty');
153
- } else {
154
- _super.apply(this, arguments);
155
- }
156
- };
157
- });
158
-
159
- chai.Assertion.overwriteProperty('be', function (_super) {
160
- return function () {
161
- var be = function (selector) {
162
- var obj = flag(this, 'object');
163
- if (obj instanceof $) {
164
- this.assert(
165
- obj.is(selector)
166
- , 'expected #{this} to be #{exp}'
167
- , 'expected #{this} not to be #{exp}'
168
- , selector
169
- );
170
- } else {
171
- _super.apply(this, arguments);
172
- }
173
- };
174
- be.__proto__ = this;
175
- return be;
176
- }
177
- });
178
-
179
- chai.Assertion.overwriteMethod('match', function (_super) {
180
- return function (selector) {
181
- var obj = flag(this, 'object');
182
- if (obj instanceof $) {
183
- this.assert(
184
- obj.is(selector)
185
- , 'expected #{this} to match #{exp}'
186
- , 'expected #{this} not to match #{exp}'
187
- , selector
188
- );
189
- } else {
190
- _super.apply(this, arguments);
191
- }
192
- }
193
- });
194
-
195
- chai.Assertion.overwriteProperty('contain', function (_super) {
196
- return function () {
197
- _super.call(this);
198
- var contain = function (text) {
199
- var obj = flag(this, 'object');
200
- if (obj instanceof $) {
201
- this.assert(
202
- obj.is(':contains(\'' + text + '\')')
203
- , 'expected #{this} to contain #{exp}'
204
- , 'expected #{this} not to contain #{exp}'
205
- , text
206
- );
207
- } else {
208
- Function.prototype.apply.call(_super.call(this), this, arguments);
209
- }
210
- };
211
- contain.__proto__ = this;
212
- return contain;
213
- }
214
- });
215
-
216
- chai.Assertion.overwriteProperty('have', function (_super) {
217
- return function () {
218
- var obj = flag(this, 'object');
219
- if (obj instanceof $) {
220
- var have = function (selector) {
221
- this.assert(
222
- // Using find() rather than has() to work around a jQuery bug:
223
- // http://bugs.jquery.com/ticket/11706
224
- obj.find(selector).length > 0
225
- , 'expected #{this} to have #{exp}'
226
- , 'expected #{this} not to have #{exp}'
227
- , selector
228
- );
229
- };
230
- have.__proto__ = this;
231
- return have;
232
- } else {
233
- _super.call(this);
234
- }
235
- }
236
- });
237
- }));
@@ -1,4251 +0,0 @@
1
- ;(function(){
2
-
3
- /**
4
- * Require the given path.
5
- *
6
- * @param {String} path
7
- * @return {Object} exports
8
- * @api public
9
- */
10
-
11
- function require(path, parent, orig) {
12
- var resolved = require.resolve(path);
13
-
14
- // lookup failed
15
- if (null == resolved) {
16
- orig = orig || path;
17
- parent = parent || 'root';
18
- var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
19
- err.path = orig;
20
- err.parent = parent;
21
- err.require = true;
22
- throw err;
23
- }
24
-
25
- var module = require.modules[resolved];
26
-
27
- // perform real require()
28
- // by invoking the module's
29
- // registered function
30
- if (!module.exports) {
31
- module.exports = {};
32
- module.client = module.component = true;
33
- module.call(this, module.exports, require.relative(resolved), module);
34
- }
35
-
36
- return module.exports;
37
- }
38
-
39
- /**
40
- * Registered modules.
41
- */
42
-
43
- require.modules = {};
44
-
45
- /**
46
- * Registered aliases.
47
- */
48
-
49
- require.aliases = {};
50
-
51
- /**
52
- * Resolve `path`.
53
- *
54
- * Lookup:
55
- *
56
- * - PATH/index.js
57
- * - PATH.js
58
- * - PATH
59
- *
60
- * @param {String} path
61
- * @return {String} path or null
62
- * @api private
63
- */
64
-
65
- require.resolve = function(path) {
66
- if (path.charAt(0) === '/') path = path.slice(1);
67
- var index = path + '/index.js';
68
-
69
- var paths = [
70
- path,
71
- path + '.js',
72
- path + '.json',
73
- path + '/index.js',
74
- path + '/index.json'
75
- ];
76
-
77
- for (var i = 0; i < paths.length; i++) {
78
- var path = paths[i];
79
- if (require.modules.hasOwnProperty(path)) return path;
80
- }
81
-
82
- if (require.aliases.hasOwnProperty(index)) {
83
- return require.aliases[index];
84
- }
85
- };
86
-
87
- /**
88
- * Normalize `path` relative to the current path.
89
- *
90
- * @param {String} curr
91
- * @param {String} path
92
- * @return {String}
93
- * @api private
94
- */
95
-
96
- require.normalize = function(curr, path) {
97
- var segs = [];
98
-
99
- if ('.' != path.charAt(0)) return path;
100
-
101
- curr = curr.split('/');
102
- path = path.split('/');
103
-
104
- for (var i = 0; i < path.length; ++i) {
105
- if ('..' == path[i]) {
106
- curr.pop();
107
- } else if ('.' != path[i] && '' != path[i]) {
108
- segs.push(path[i]);
109
- }
110
- }
111
-
112
- return curr.concat(segs).join('/');
113
- };
114
-
115
- /**
116
- * Register module at `path` with callback `definition`.
117
- *
118
- * @param {String} path
119
- * @param {Function} definition
120
- * @api private
121
- */
122
-
123
- require.register = function(path, definition) {
124
- require.modules[path] = definition;
125
- };
126
-
127
- /**
128
- * Alias a module definition.
129
- *
130
- * @param {String} from
131
- * @param {String} to
132
- * @api private
133
- */
134
-
135
- require.alias = function(from, to) {
136
- if (!require.modules.hasOwnProperty(from)) {
137
- throw new Error('Failed to alias "' + from + '", it does not exist');
138
- }
139
- require.aliases[to] = from;
140
- };
141
-
142
- /**
143
- * Return a require function relative to the `parent` path.
144
- *
145
- * @param {String} parent
146
- * @return {Function}
147
- * @api private
148
- */
149
-
150
- require.relative = function(parent) {
151
- var p = require.normalize(parent, '..');
152
-
153
- /**
154
- * lastIndexOf helper.
155
- */
156
-
157
- function lastIndexOf(arr, obj) {
158
- var i = arr.length;
159
- while (i--) {
160
- if (arr[i] === obj) return i;
161
- }
162
- return -1;
163
- }
164
-
165
- /**
166
- * The relative require() itself.
167
- */
168
-
169
- function localRequire(path) {
170
- var resolved = localRequire.resolve(path);
171
- return require(resolved, parent, path);
172
- }
173
-
174
- /**
175
- * Resolve relative to the parent.
176
- */
177
-
178
- localRequire.resolve = function(path) {
179
- var c = path.charAt(0);
180
- if ('/' == c) return path.slice(1);
181
- if ('.' == c) return require.normalize(p, path);
182
-
183
- // resolve deps by returning
184
- // the dep in the nearest "deps"
185
- // directory
186
- var segs = parent.split('/');
187
- var i = lastIndexOf(segs, 'deps') + 1;
188
- if (!i) i = 0;
189
- path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
190
- return path;
191
- };
192
-
193
- /**
194
- * Check if module is defined at `path`.
195
- */
196
-
197
- localRequire.exists = function(path) {
198
- return require.modules.hasOwnProperty(localRequire.resolve(path));
199
- };
200
-
201
- return localRequire;
202
- };
203
- require.register("chai/index.js", function(exports, require, module){
204
- module.exports = require('./lib/chai');
205
-
206
- });
207
- require.register("chai/lib/chai.js", function(exports, require, module){
208
- /*!
209
- * chai
210
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
211
- * MIT Licensed
212
- */
213
-
214
- var used = []
215
- , exports = module.exports = {};
216
-
217
- /*!
218
- * Chai version
219
- */
220
-
221
- exports.version = '1.6.0';
222
-
223
- /*!
224
- * Primary `Assertion` prototype
225
- */
226
-
227
- exports.Assertion = require('./chai/assertion');
228
-
229
- /*!
230
- * Assertion Error
231
- */
232
-
233
- exports.AssertionError = require('./chai/error');
234
-
235
- /*!
236
- * Utils for plugins (not exported)
237
- */
238
-
239
- var util = require('./chai/utils');
240
-
241
- /**
242
- * # .use(function)
243
- *
244
- * Provides a way to extend the internals of Chai
245
- *
246
- * @param {Function}
247
- * @returns {this} for chaining
248
- * @api public
249
- */
250
-
251
- exports.use = function (fn) {
252
- if (!~used.indexOf(fn)) {
253
- fn(this, util);
254
- used.push(fn);
255
- }
256
-
257
- return this;
258
- };
259
-
260
- /*!
261
- * Core Assertions
262
- */
263
-
264
- var core = require('./chai/core/assertions');
265
- exports.use(core);
266
-
267
- /*!
268
- * Expect interface
269
- */
270
-
271
- var expect = require('./chai/interface/expect');
272
- exports.use(expect);
273
-
274
- /*!
275
- * Should interface
276
- */
277
-
278
- var should = require('./chai/interface/should');
279
- exports.use(should);
280
-
281
- /*!
282
- * Assert interface
283
- */
284
-
285
- var assert = require('./chai/interface/assert');
286
- exports.use(assert);
287
-
288
- });
289
- require.register("chai/lib/chai/assertion.js", function(exports, require, module){
290
- /*!
291
- * chai
292
- * http://chaijs.com
293
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
294
- * MIT Licensed
295
- */
296
-
297
- /*!
298
- * Module dependencies.
299
- */
300
-
301
- var AssertionError = require('./error')
302
- , util = require('./utils')
303
- , flag = util.flag;
304
-
305
- /*!
306
- * Module export.
307
- */
308
-
309
- module.exports = Assertion;
310
-
311
-
312
- /*!
313
- * Assertion Constructor
314
- *
315
- * Creates object for chaining.
316
- *
317
- * @api private
318
- */
319
-
320
- function Assertion (obj, msg, stack) {
321
- flag(this, 'ssfi', stack || arguments.callee);
322
- flag(this, 'object', obj);
323
- flag(this, 'message', msg);
324
- }
325
-
326
- /*!
327
- * ### Assertion.includeStack
328
- *
329
- * User configurable property, influences whether stack trace
330
- * is included in Assertion error message. Default of false
331
- * suppresses stack trace in the error message
332
- *
333
- * Assertion.includeStack = true; // enable stack on error
334
- *
335
- * @api public
336
- */
337
-
338
- Assertion.includeStack = false;
339
-
340
- /*!
341
- * ### Assertion.showDiff
342
- *
343
- * User configurable property, influences whether or not
344
- * the `showDiff` flag should be included in the thrown
345
- * AssertionErrors. `false` will always be `false`; `true`
346
- * will be true when the assertion has requested a diff
347
- * be shown.
348
- *
349
- * @api public
350
- */
351
-
352
- Assertion.showDiff = true;
353
-
354
- Assertion.addProperty = function (name, fn) {
355
- util.addProperty(this.prototype, name, fn);
356
- };
357
-
358
- Assertion.addMethod = function (name, fn) {
359
- util.addMethod(this.prototype, name, fn);
360
- };
361
-
362
- Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
363
- util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
364
- };
365
-
366
- Assertion.overwriteProperty = function (name, fn) {
367
- util.overwriteProperty(this.prototype, name, fn);
368
- };
369
-
370
- Assertion.overwriteMethod = function (name, fn) {
371
- util.overwriteMethod(this.prototype, name, fn);
372
- };
373
-
374
- /*!
375
- * ### .assert(expression, message, negateMessage, expected, actual)
376
- *
377
- * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
378
- *
379
- * @name assert
380
- * @param {Philosophical} expression to be tested
381
- * @param {String} message to display if fails
382
- * @param {String} negatedMessage to display if negated expression fails
383
- * @param {Mixed} expected value (remember to check for negation)
384
- * @param {Mixed} actual (optional) will default to `this.obj`
385
- * @api private
386
- */
387
-
388
- Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
389
- var ok = util.test(this, arguments);
390
- if (true !== showDiff) showDiff = false;
391
- if (true !== Assertion.showDiff) showDiff = false;
392
-
393
- if (!ok) {
394
- var msg = util.getMessage(this, arguments)
395
- , actual = util.getActual(this, arguments);
396
- throw new AssertionError({
397
- message: msg
398
- , actual: actual
399
- , expected: expected
400
- , stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
401
- , showDiff: showDiff
402
- });
403
- }
404
- };
405
-
406
- /*!
407
- * ### ._obj
408
- *
409
- * Quick reference to stored `actual` value for plugin developers.
410
- *
411
- * @api private
412
- */
413
-
414
- Object.defineProperty(Assertion.prototype, '_obj',
415
- { get: function () {
416
- return flag(this, 'object');
417
- }
418
- , set: function (val) {
419
- flag(this, 'object', val);
420
- }
421
- });
422
-
423
- });
424
- require.register("chai/lib/chai/error.js", function(exports, require, module){
425
- /*!
426
- * chai
427
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
428
- * MIT Licensed
429
- */
430
-
431
- /*!
432
- * Main export
433
- */
434
-
435
- module.exports = AssertionError;
436
-
437
- /**
438
- * # AssertionError (constructor)
439
- *
440
- * Create a new assertion error based on the Javascript
441
- * `Error` prototype.
442
- *
443
- * **Options**
444
- * - message
445
- * - actual
446
- * - expected
447
- * - operator
448
- * - startStackFunction
449
- *
450
- * @param {Object} options
451
- * @api public
452
- */
453
-
454
- function AssertionError (options) {
455
- options = options || {};
456
- this.message = options.message;
457
- this.actual = options.actual;
458
- this.expected = options.expected;
459
- this.operator = options.operator;
460
- this.showDiff = options.showDiff;
461
-
462
- if (options.stackStartFunction && Error.captureStackTrace) {
463
- var stackStartFunction = options.stackStartFunction;
464
- Error.captureStackTrace(this, stackStartFunction);
465
- }
466
- }
467
-
468
- /*!
469
- * Inherit from Error
470
- */
471
-
472
- AssertionError.prototype = Object.create(Error.prototype);
473
- AssertionError.prototype.name = 'AssertionError';
474
- AssertionError.prototype.constructor = AssertionError;
475
-
476
- /**
477
- * # toString()
478
- *
479
- * Override default to string method
480
- */
481
-
482
- AssertionError.prototype.toString = function() {
483
- return this.message;
484
- };
485
-
486
- });
487
- require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
488
- /*!
489
- * chai
490
- * http://chaijs.com
491
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
492
- * MIT Licensed
493
- */
494
-
495
- module.exports = function (chai, _) {
496
- var Assertion = chai.Assertion
497
- , toString = Object.prototype.toString
498
- , flag = _.flag;
499
-
500
- /**
501
- * ### Language Chains
502
- *
503
- * The following are provide as chainable getters to
504
- * improve the readability of your assertions. They
505
- * do not provide an testing capability unless they
506
- * have been overwritten by a plugin.
507
- *
508
- * **Chains**
509
- *
510
- * - to
511
- * - be
512
- * - been
513
- * - is
514
- * - that
515
- * - and
516
- * - have
517
- * - with
518
- * - at
519
- * - of
520
- * - same
521
- *
522
- * @name language chains
523
- * @api public
524
- */
525
-
526
- [ 'to', 'be', 'been'
527
- , 'is', 'and', 'have'
528
- , 'with', 'that', 'at'
529
- , 'of', 'same' ].forEach(function (chain) {
530
- Assertion.addProperty(chain, function () {
531
- return this;
532
- });
533
- });
534
-
535
- /**
536
- * ### .not
537
- *
538
- * Negates any of assertions following in the chain.
539
- *
540
- * expect(foo).to.not.equal('bar');
541
- * expect(goodFn).to.not.throw(Error);
542
- * expect({ foo: 'baz' }).to.have.property('foo')
543
- * .and.not.equal('bar');
544
- *
545
- * @name not
546
- * @api public
547
- */
548
-
549
- Assertion.addProperty('not', function () {
550
- flag(this, 'negate', true);
551
- });
552
-
553
- /**
554
- * ### .deep
555
- *
556
- * Sets the `deep` flag, later used by the `equal` and
557
- * `property` assertions.
558
- *
559
- * expect(foo).to.deep.equal({ bar: 'baz' });
560
- * expect({ foo: { bar: { baz: 'quux' } } })
561
- * .to.have.deep.property('foo.bar.baz', 'quux');
562
- *
563
- * @name deep
564
- * @api public
565
- */
566
-
567
- Assertion.addProperty('deep', function () {
568
- flag(this, 'deep', true);
569
- });
570
-
571
- /**
572
- * ### .a(type)
573
- *
574
- * The `a` and `an` assertions are aliases that can be
575
- * used either as language chains or to assert a value's
576
- * type.
577
- *
578
- * // typeof
579
- * expect('test').to.be.a('string');
580
- * expect({ foo: 'bar' }).to.be.an('object');
581
- * expect(null).to.be.a('null');
582
- * expect(undefined).to.be.an('undefined');
583
- *
584
- * // language chain
585
- * expect(foo).to.be.an.instanceof(Foo);
586
- *
587
- * @name a
588
- * @alias an
589
- * @param {String} type
590
- * @param {String} message _optional_
591
- * @api public
592
- */
593
-
594
- function an (type, msg) {
595
- if (msg) flag(this, 'message', msg);
596
- type = type.toLowerCase();
597
- var obj = flag(this, 'object')
598
- , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
599
-
600
- this.assert(
601
- type === _.type(obj)
602
- , 'expected #{this} to be ' + article + type
603
- , 'expected #{this} not to be ' + article + type
604
- );
605
- }
606
-
607
- Assertion.addChainableMethod('an', an);
608
- Assertion.addChainableMethod('a', an);
609
-
610
- /**
611
- * ### .include(value)
612
- *
613
- * The `include` and `contain` assertions can be used as either property
614
- * based language chains or as methods to assert the inclusion of an object
615
- * in an array or a substring in a string. When used as language chains,
616
- * they toggle the `contain` flag for the `keys` assertion.
617
- *
618
- * expect([1,2,3]).to.include(2);
619
- * expect('foobar').to.contain('foo');
620
- * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
621
- *
622
- * @name include
623
- * @alias contain
624
- * @param {Object|String|Number} obj
625
- * @param {String} message _optional_
626
- * @api public
627
- */
628
-
629
- function includeChainingBehavior () {
630
- flag(this, 'contains', true);
631
- }
632
-
633
- function include (val, msg) {
634
- if (msg) flag(this, 'message', msg);
635
- var obj = flag(this, 'object')
636
- this.assert(
637
- ~obj.indexOf(val)
638
- , 'expected #{this} to include ' + _.inspect(val)
639
- , 'expected #{this} to not include ' + _.inspect(val));
640
- }
641
-
642
- Assertion.addChainableMethod('include', include, includeChainingBehavior);
643
- Assertion.addChainableMethod('contain', include, includeChainingBehavior);
644
-
645
- /**
646
- * ### .ok
647
- *
648
- * Asserts that the target is truthy.
649
- *
650
- * expect('everthing').to.be.ok;
651
- * expect(1).to.be.ok;
652
- * expect(false).to.not.be.ok;
653
- * expect(undefined).to.not.be.ok;
654
- * expect(null).to.not.be.ok;
655
- *
656
- * @name ok
657
- * @api public
658
- */
659
-
660
- Assertion.addProperty('ok', function () {
661
- this.assert(
662
- flag(this, 'object')
663
- , 'expected #{this} to be truthy'
664
- , 'expected #{this} to be falsy');
665
- });
666
-
667
- /**
668
- * ### .true
669
- *
670
- * Asserts that the target is `true`.
671
- *
672
- * expect(true).to.be.true;
673
- * expect(1).to.not.be.true;
674
- *
675
- * @name true
676
- * @api public
677
- */
678
-
679
- Assertion.addProperty('true', function () {
680
- this.assert(
681
- true === flag(this, 'object')
682
- , 'expected #{this} to be true'
683
- , 'expected #{this} to be false'
684
- , this.negate ? false : true
685
- );
686
- });
687
-
688
- /**
689
- * ### .false
690
- *
691
- * Asserts that the target is `false`.
692
- *
693
- * expect(false).to.be.false;
694
- * expect(0).to.not.be.false;
695
- *
696
- * @name false
697
- * @api public
698
- */
699
-
700
- Assertion.addProperty('false', function () {
701
- this.assert(
702
- false === flag(this, 'object')
703
- , 'expected #{this} to be false'
704
- , 'expected #{this} to be true'
705
- , this.negate ? true : false
706
- );
707
- });
708
-
709
- /**
710
- * ### .null
711
- *
712
- * Asserts that the target is `null`.
713
- *
714
- * expect(null).to.be.null;
715
- * expect(undefined).not.to.be.null;
716
- *
717
- * @name null
718
- * @api public
719
- */
720
-
721
- Assertion.addProperty('null', function () {
722
- this.assert(
723
- null === flag(this, 'object')
724
- , 'expected #{this} to be null'
725
- , 'expected #{this} not to be null'
726
- );
727
- });
728
-
729
- /**
730
- * ### .undefined
731
- *
732
- * Asserts that the target is `undefined`.
733
- *
734
- * expect(undefined).to.be.undefined;
735
- * expect(null).to.not.be.undefined;
736
- *
737
- * @name undefined
738
- * @api public
739
- */
740
-
741
- Assertion.addProperty('undefined', function () {
742
- this.assert(
743
- undefined === flag(this, 'object')
744
- , 'expected #{this} to be undefined'
745
- , 'expected #{this} not to be undefined'
746
- );
747
- });
748
-
749
- /**
750
- * ### .exist
751
- *
752
- * Asserts that the target is neither `null` nor `undefined`.
753
- *
754
- * var foo = 'hi'
755
- * , bar = null
756
- * , baz;
757
- *
758
- * expect(foo).to.exist;
759
- * expect(bar).to.not.exist;
760
- * expect(baz).to.not.exist;
761
- *
762
- * @name exist
763
- * @api public
764
- */
765
-
766
- Assertion.addProperty('exist', function () {
767
- this.assert(
768
- null != flag(this, 'object')
769
- , 'expected #{this} to exist'
770
- , 'expected #{this} to not exist'
771
- );
772
- });
773
-
774
-
775
- /**
776
- * ### .empty
777
- *
778
- * Asserts that the target's length is `0`. For arrays, it checks
779
- * the `length` property. For objects, it gets the count of
780
- * enumerable keys.
781
- *
782
- * expect([]).to.be.empty;
783
- * expect('').to.be.empty;
784
- * expect({}).to.be.empty;
785
- *
786
- * @name empty
787
- * @api public
788
- */
789
-
790
- Assertion.addProperty('empty', function () {
791
- var obj = flag(this, 'object')
792
- , expected = obj;
793
-
794
- if (Array.isArray(obj) || 'string' === typeof object) {
795
- expected = obj.length;
796
- } else if (typeof obj === 'object') {
797
- expected = Object.keys(obj).length;
798
- }
799
-
800
- this.assert(
801
- !expected
802
- , 'expected #{this} to be empty'
803
- , 'expected #{this} not to be empty'
804
- );
805
- });
806
-
807
- /**
808
- * ### .arguments
809
- *
810
- * Asserts that the target is an arguments object.
811
- *
812
- * function test () {
813
- * expect(arguments).to.be.arguments;
814
- * }
815
- *
816
- * @name arguments
817
- * @alias Arguments
818
- * @api public
819
- */
820
-
821
- function checkArguments () {
822
- var obj = flag(this, 'object')
823
- , type = Object.prototype.toString.call(obj);
824
- this.assert(
825
- '[object Arguments]' === type
826
- , 'expected #{this} to be arguments but got ' + type
827
- , 'expected #{this} to not be arguments'
828
- );
829
- }
830
-
831
- Assertion.addProperty('arguments', checkArguments);
832
- Assertion.addProperty('Arguments', checkArguments);
833
-
834
- /**
835
- * ### .equal(value)
836
- *
837
- * Asserts that the target is strictly equal (`===`) to `value`.
838
- * Alternately, if the `deep` flag is set, asserts that
839
- * the target is deeply equal to `value`.
840
- *
841
- * expect('hello').to.equal('hello');
842
- * expect(42).to.equal(42);
843
- * expect(1).to.not.equal(true);
844
- * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
845
- * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
846
- *
847
- * @name equal
848
- * @alias equals
849
- * @alias eq
850
- * @alias deep.equal
851
- * @param {Mixed} value
852
- * @param {String} message _optional_
853
- * @api public
854
- */
855
-
856
- function assertEqual (val, msg) {
857
- if (msg) flag(this, 'message', msg);
858
- var obj = flag(this, 'object');
859
- if (flag(this, 'deep')) {
860
- return this.eql(val);
861
- } else {
862
- this.assert(
863
- val === obj
864
- , 'expected #{this} to equal #{exp}'
865
- , 'expected #{this} to not equal #{exp}'
866
- , val
867
- , this._obj
868
- , true
869
- );
870
- }
871
- }
872
-
873
- Assertion.addMethod('equal', assertEqual);
874
- Assertion.addMethod('equals', assertEqual);
875
- Assertion.addMethod('eq', assertEqual);
876
-
877
- /**
878
- * ### .eql(value)
879
- *
880
- * Asserts that the target is deeply equal to `value`.
881
- *
882
- * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
883
- * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
884
- *
885
- * @name eql
886
- * @alias eqls
887
- * @param {Mixed} value
888
- * @param {String} message _optional_
889
- * @api public
890
- */
891
-
892
- function assertEql(obj, msg) {
893
- if (msg) flag(this, 'message', msg);
894
- this.assert(
895
- _.eql(obj, flag(this, 'object'))
896
- , 'expected #{this} to deeply equal #{exp}'
897
- , 'expected #{this} to not deeply equal #{exp}'
898
- , obj
899
- , this._obj
900
- , true
901
- );
902
- }
903
-
904
- Assertion.addMethod('eql', assertEql);
905
- Assertion.addMethod('eqls', assertEql);
906
-
907
- /**
908
- * ### .above(value)
909
- *
910
- * Asserts that the target is greater than `value`.
911
- *
912
- * expect(10).to.be.above(5);
913
- *
914
- * Can also be used in conjunction with `length` to
915
- * assert a minimum length. The benefit being a
916
- * more informative error message than if the length
917
- * was supplied directly.
918
- *
919
- * expect('foo').to.have.length.above(2);
920
- * expect([ 1, 2, 3 ]).to.have.length.above(2);
921
- *
922
- * @name above
923
- * @alias gt
924
- * @alias greaterThan
925
- * @param {Number} value
926
- * @param {String} message _optional_
927
- * @api public
928
- */
929
-
930
- function assertAbove (n, msg) {
931
- if (msg) flag(this, 'message', msg);
932
- var obj = flag(this, 'object');
933
- if (flag(this, 'doLength')) {
934
- new Assertion(obj, msg).to.have.property('length');
935
- var len = obj.length;
936
- this.assert(
937
- len > n
938
- , 'expected #{this} to have a length above #{exp} but got #{act}'
939
- , 'expected #{this} to not have a length above #{exp}'
940
- , n
941
- , len
942
- );
943
- } else {
944
- this.assert(
945
- obj > n
946
- , 'expected #{this} to be above ' + n
947
- , 'expected #{this} to be at most ' + n
948
- );
949
- }
950
- }
951
-
952
- Assertion.addMethod('above', assertAbove);
953
- Assertion.addMethod('gt', assertAbove);
954
- Assertion.addMethod('greaterThan', assertAbove);
955
-
956
- /**
957
- * ### .least(value)
958
- *
959
- * Asserts that the target is greater than or equal to `value`.
960
- *
961
- * expect(10).to.be.at.least(10);
962
- *
963
- * Can also be used in conjunction with `length` to
964
- * assert a minimum length. The benefit being a
965
- * more informative error message than if the length
966
- * was supplied directly.
967
- *
968
- * expect('foo').to.have.length.of.at.least(2);
969
- * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
970
- *
971
- * @name least
972
- * @alias gte
973
- * @param {Number} value
974
- * @param {String} message _optional_
975
- * @api public
976
- */
977
-
978
- function assertLeast (n, msg) {
979
- if (msg) flag(this, 'message', msg);
980
- var obj = flag(this, 'object');
981
- if (flag(this, 'doLength')) {
982
- new Assertion(obj, msg).to.have.property('length');
983
- var len = obj.length;
984
- this.assert(
985
- len >= n
986
- , 'expected #{this} to have a length at least #{exp} but got #{act}'
987
- , 'expected #{this} to have a length below #{exp}'
988
- , n
989
- , len
990
- );
991
- } else {
992
- this.assert(
993
- obj >= n
994
- , 'expected #{this} to be at least ' + n
995
- , 'expected #{this} to be below ' + n
996
- );
997
- }
998
- }
999
-
1000
- Assertion.addMethod('least', assertLeast);
1001
- Assertion.addMethod('gte', assertLeast);
1002
-
1003
- /**
1004
- * ### .below(value)
1005
- *
1006
- * Asserts that the target is less than `value`.
1007
- *
1008
- * expect(5).to.be.below(10);
1009
- *
1010
- * Can also be used in conjunction with `length` to
1011
- * assert a maximum length. The benefit being a
1012
- * more informative error message than if the length
1013
- * was supplied directly.
1014
- *
1015
- * expect('foo').to.have.length.below(4);
1016
- * expect([ 1, 2, 3 ]).to.have.length.below(4);
1017
- *
1018
- * @name below
1019
- * @alias lt
1020
- * @alias lessThan
1021
- * @param {Number} value
1022
- * @param {String} message _optional_
1023
- * @api public
1024
- */
1025
-
1026
- function assertBelow (n, msg) {
1027
- if (msg) flag(this, 'message', msg);
1028
- var obj = flag(this, 'object');
1029
- if (flag(this, 'doLength')) {
1030
- new Assertion(obj, msg).to.have.property('length');
1031
- var len = obj.length;
1032
- this.assert(
1033
- len < n
1034
- , 'expected #{this} to have a length below #{exp} but got #{act}'
1035
- , 'expected #{this} to not have a length below #{exp}'
1036
- , n
1037
- , len
1038
- );
1039
- } else {
1040
- this.assert(
1041
- obj < n
1042
- , 'expected #{this} to be below ' + n
1043
- , 'expected #{this} to be at least ' + n
1044
- );
1045
- }
1046
- }
1047
-
1048
- Assertion.addMethod('below', assertBelow);
1049
- Assertion.addMethod('lt', assertBelow);
1050
- Assertion.addMethod('lessThan', assertBelow);
1051
-
1052
- /**
1053
- * ### .most(value)
1054
- *
1055
- * Asserts that the target is less than or equal to `value`.
1056
- *
1057
- * expect(5).to.be.at.most(5);
1058
- *
1059
- * Can also be used in conjunction with `length` to
1060
- * assert a maximum length. The benefit being a
1061
- * more informative error message than if the length
1062
- * was supplied directly.
1063
- *
1064
- * expect('foo').to.have.length.of.at.most(4);
1065
- * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
1066
- *
1067
- * @name most
1068
- * @alias lte
1069
- * @param {Number} value
1070
- * @param {String} message _optional_
1071
- * @api public
1072
- */
1073
-
1074
- function assertMost (n, msg) {
1075
- if (msg) flag(this, 'message', msg);
1076
- var obj = flag(this, 'object');
1077
- if (flag(this, 'doLength')) {
1078
- new Assertion(obj, msg).to.have.property('length');
1079
- var len = obj.length;
1080
- this.assert(
1081
- len <= n
1082
- , 'expected #{this} to have a length at most #{exp} but got #{act}'
1083
- , 'expected #{this} to have a length above #{exp}'
1084
- , n
1085
- , len
1086
- );
1087
- } else {
1088
- this.assert(
1089
- obj <= n
1090
- , 'expected #{this} to be at most ' + n
1091
- , 'expected #{this} to be above ' + n
1092
- );
1093
- }
1094
- }
1095
-
1096
- Assertion.addMethod('most', assertMost);
1097
- Assertion.addMethod('lte', assertMost);
1098
-
1099
- /**
1100
- * ### .within(start, finish)
1101
- *
1102
- * Asserts that the target is within a range.
1103
- *
1104
- * expect(7).to.be.within(5,10);
1105
- *
1106
- * Can also be used in conjunction with `length` to
1107
- * assert a length range. The benefit being a
1108
- * more informative error message than if the length
1109
- * was supplied directly.
1110
- *
1111
- * expect('foo').to.have.length.within(2,4);
1112
- * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1113
- *
1114
- * @name within
1115
- * @param {Number} start lowerbound inclusive
1116
- * @param {Number} finish upperbound inclusive
1117
- * @param {String} message _optional_
1118
- * @api public
1119
- */
1120
-
1121
- Assertion.addMethod('within', function (start, finish, msg) {
1122
- if (msg) flag(this, 'message', msg);
1123
- var obj = flag(this, 'object')
1124
- , range = start + '..' + finish;
1125
- if (flag(this, 'doLength')) {
1126
- new Assertion(obj, msg).to.have.property('length');
1127
- var len = obj.length;
1128
- this.assert(
1129
- len >= start && len <= finish
1130
- , 'expected #{this} to have a length within ' + range
1131
- , 'expected #{this} to not have a length within ' + range
1132
- );
1133
- } else {
1134
- this.assert(
1135
- obj >= start && obj <= finish
1136
- , 'expected #{this} to be within ' + range
1137
- , 'expected #{this} to not be within ' + range
1138
- );
1139
- }
1140
- });
1141
-
1142
- /**
1143
- * ### .instanceof(constructor)
1144
- *
1145
- * Asserts that the target is an instance of `constructor`.
1146
- *
1147
- * var Tea = function (name) { this.name = name; }
1148
- * , Chai = new Tea('chai');
1149
- *
1150
- * expect(Chai).to.be.an.instanceof(Tea);
1151
- * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
1152
- *
1153
- * @name instanceof
1154
- * @param {Constructor} constructor
1155
- * @param {String} message _optional_
1156
- * @alias instanceOf
1157
- * @api public
1158
- */
1159
-
1160
- function assertInstanceOf (constructor, msg) {
1161
- if (msg) flag(this, 'message', msg);
1162
- var name = _.getName(constructor);
1163
- this.assert(
1164
- flag(this, 'object') instanceof constructor
1165
- , 'expected #{this} to be an instance of ' + name
1166
- , 'expected #{this} to not be an instance of ' + name
1167
- );
1168
- };
1169
-
1170
- Assertion.addMethod('instanceof', assertInstanceOf);
1171
- Assertion.addMethod('instanceOf', assertInstanceOf);
1172
-
1173
- /**
1174
- * ### .property(name, [value])
1175
- *
1176
- * Asserts that the target has a property `name`, optionally asserting that
1177
- * the value of that property is strictly equal to `value`.
1178
- * If the `deep` flag is set, you can use dot- and bracket-notation for deep
1179
- * references into objects and arrays.
1180
- *
1181
- * // simple referencing
1182
- * var obj = { foo: 'bar' };
1183
- * expect(obj).to.have.property('foo');
1184
- * expect(obj).to.have.property('foo', 'bar');
1185
- *
1186
- * // deep referencing
1187
- * var deepObj = {
1188
- * green: { tea: 'matcha' }
1189
- * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
1190
- * };
1191
-
1192
- * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
1193
- * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
1194
- * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
1195
- *
1196
- * You can also use an array as the starting point of a `deep.property`
1197
- * assertion, or traverse nested arrays.
1198
- *
1199
- * var arr = [
1200
- * [ 'chai', 'matcha', 'konacha' ]
1201
- * , [ { tea: 'chai' }
1202
- * , { tea: 'matcha' }
1203
- * , { tea: 'konacha' } ]
1204
- * ];
1205
- *
1206
- * expect(arr).to.have.deep.property('[0][1]', 'matcha');
1207
- * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
1208
- *
1209
- * Furthermore, `property` changes the subject of the assertion
1210
- * to be the value of that property from the original object. This
1211
- * permits for further chainable assertions on that property.
1212
- *
1213
- * expect(obj).to.have.property('foo')
1214
- * .that.is.a('string');
1215
- * expect(deepObj).to.have.property('green')
1216
- * .that.is.an('object')
1217
- * .that.deep.equals({ tea: 'matcha' });
1218
- * expect(deepObj).to.have.property('teas')
1219
- * .that.is.an('array')
1220
- * .with.deep.property('[2]')
1221
- * .that.deep.equals({ tea: 'konacha' });
1222
- *
1223
- * @name property
1224
- * @alias deep.property
1225
- * @param {String} name
1226
- * @param {Mixed} value (optional)
1227
- * @param {String} message _optional_
1228
- * @returns value of property for chaining
1229
- * @api public
1230
- */
1231
-
1232
- Assertion.addMethod('property', function (name, val, msg) {
1233
- if (msg) flag(this, 'message', msg);
1234
-
1235
- var descriptor = flag(this, 'deep') ? 'deep property ' : 'property '
1236
- , negate = flag(this, 'negate')
1237
- , obj = flag(this, 'object')
1238
- , value = flag(this, 'deep')
1239
- ? _.getPathValue(name, obj)
1240
- : obj[name];
1241
-
1242
- if (negate && undefined !== val) {
1243
- if (undefined === value) {
1244
- msg = (msg != null) ? msg + ': ' : '';
1245
- throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
1246
- }
1247
- } else {
1248
- this.assert(
1249
- undefined !== value
1250
- , 'expected #{this} to have a ' + descriptor + _.inspect(name)
1251
- , 'expected #{this} to not have ' + descriptor + _.inspect(name));
1252
- }
1253
-
1254
- if (undefined !== val) {
1255
- this.assert(
1256
- val === value
1257
- , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
1258
- , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
1259
- , val
1260
- , value
1261
- );
1262
- }
1263
-
1264
- flag(this, 'object', value);
1265
- });
1266
-
1267
-
1268
- /**
1269
- * ### .ownProperty(name)
1270
- *
1271
- * Asserts that the target has an own property `name`.
1272
- *
1273
- * expect('test').to.have.ownProperty('length');
1274
- *
1275
- * @name ownProperty
1276
- * @alias haveOwnProperty
1277
- * @param {String} name
1278
- * @param {String} message _optional_
1279
- * @api public
1280
- */
1281
-
1282
- function assertOwnProperty (name, msg) {
1283
- if (msg) flag(this, 'message', msg);
1284
- var obj = flag(this, 'object');
1285
- this.assert(
1286
- obj.hasOwnProperty(name)
1287
- , 'expected #{this} to have own property ' + _.inspect(name)
1288
- , 'expected #{this} to not have own property ' + _.inspect(name)
1289
- );
1290
- }
1291
-
1292
- Assertion.addMethod('ownProperty', assertOwnProperty);
1293
- Assertion.addMethod('haveOwnProperty', assertOwnProperty);
1294
-
1295
- /**
1296
- * ### .length(value)
1297
- *
1298
- * Asserts that the target's `length` property has
1299
- * the expected value.
1300
- *
1301
- * expect([ 1, 2, 3]).to.have.length(3);
1302
- * expect('foobar').to.have.length(6);
1303
- *
1304
- * Can also be used as a chain precursor to a value
1305
- * comparison for the length property.
1306
- *
1307
- * expect('foo').to.have.length.above(2);
1308
- * expect([ 1, 2, 3 ]).to.have.length.above(2);
1309
- * expect('foo').to.have.length.below(4);
1310
- * expect([ 1, 2, 3 ]).to.have.length.below(4);
1311
- * expect('foo').to.have.length.within(2,4);
1312
- * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
1313
- *
1314
- * @name length
1315
- * @alias lengthOf
1316
- * @param {Number} length
1317
- * @param {String} message _optional_
1318
- * @api public
1319
- */
1320
-
1321
- function assertLengthChain () {
1322
- flag(this, 'doLength', true);
1323
- }
1324
-
1325
- function assertLength (n, msg) {
1326
- if (msg) flag(this, 'message', msg);
1327
- var obj = flag(this, 'object');
1328
- new Assertion(obj, msg).to.have.property('length');
1329
- var len = obj.length;
1330
-
1331
- this.assert(
1332
- len == n
1333
- , 'expected #{this} to have a length of #{exp} but got #{act}'
1334
- , 'expected #{this} to not have a length of #{act}'
1335
- , n
1336
- , len
1337
- );
1338
- }
1339
-
1340
- Assertion.addChainableMethod('length', assertLength, assertLengthChain);
1341
- Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
1342
-
1343
- /**
1344
- * ### .match(regexp)
1345
- *
1346
- * Asserts that the target matches a regular expression.
1347
- *
1348
- * expect('foobar').to.match(/^foo/);
1349
- *
1350
- * @name match
1351
- * @param {RegExp} RegularExpression
1352
- * @param {String} message _optional_
1353
- * @api public
1354
- */
1355
-
1356
- Assertion.addMethod('match', function (re, msg) {
1357
- if (msg) flag(this, 'message', msg);
1358
- var obj = flag(this, 'object');
1359
- this.assert(
1360
- re.exec(obj)
1361
- , 'expected #{this} to match ' + re
1362
- , 'expected #{this} not to match ' + re
1363
- );
1364
- });
1365
-
1366
- /**
1367
- * ### .string(string)
1368
- *
1369
- * Asserts that the string target contains another string.
1370
- *
1371
- * expect('foobar').to.have.string('bar');
1372
- *
1373
- * @name string
1374
- * @param {String} string
1375
- * @param {String} message _optional_
1376
- * @api public
1377
- */
1378
-
1379
- Assertion.addMethod('string', function (str, msg) {
1380
- if (msg) flag(this, 'message', msg);
1381
- var obj = flag(this, 'object');
1382
- new Assertion(obj, msg).is.a('string');
1383
-
1384
- this.assert(
1385
- ~obj.indexOf(str)
1386
- , 'expected #{this} to contain ' + _.inspect(str)
1387
- , 'expected #{this} to not contain ' + _.inspect(str)
1388
- );
1389
- });
1390
-
1391
-
1392
- /**
1393
- * ### .keys(key1, [key2], [...])
1394
- *
1395
- * Asserts that the target has exactly the given keys, or
1396
- * asserts the inclusion of some keys when using the
1397
- * `include` or `contain` modifiers.
1398
- *
1399
- * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
1400
- * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
1401
- *
1402
- * @name keys
1403
- * @alias key
1404
- * @param {String...|Array} keys
1405
- * @api public
1406
- */
1407
-
1408
- function assertKeys (keys) {
1409
- var obj = flag(this, 'object')
1410
- , str
1411
- , ok = true;
1412
-
1413
- keys = keys instanceof Array
1414
- ? keys
1415
- : Array.prototype.slice.call(arguments);
1416
-
1417
- if (!keys.length) throw new Error('keys required');
1418
-
1419
- var actual = Object.keys(obj)
1420
- , len = keys.length;
1421
-
1422
- // Inclusion
1423
- ok = keys.every(function(key){
1424
- return ~actual.indexOf(key);
1425
- });
1426
-
1427
- // Strict
1428
- if (!flag(this, 'negate') && !flag(this, 'contains')) {
1429
- ok = ok && keys.length == actual.length;
1430
- }
1431
-
1432
- // Key string
1433
- if (len > 1) {
1434
- keys = keys.map(function(key){
1435
- return _.inspect(key);
1436
- });
1437
- var last = keys.pop();
1438
- str = keys.join(', ') + ', and ' + last;
1439
- } else {
1440
- str = _.inspect(keys[0]);
1441
- }
1442
-
1443
- // Form
1444
- str = (len > 1 ? 'keys ' : 'key ') + str;
1445
-
1446
- // Have / include
1447
- str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
1448
-
1449
- // Assertion
1450
- this.assert(
1451
- ok
1452
- , 'expected #{this} to ' + str
1453
- , 'expected #{this} to not ' + str
1454
- );
1455
- }
1456
-
1457
- Assertion.addMethod('keys', assertKeys);
1458
- Assertion.addMethod('key', assertKeys);
1459
-
1460
- /**
1461
- * ### .throw(constructor)
1462
- *
1463
- * Asserts that the function target will throw a specific error, or specific type of error
1464
- * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
1465
- * for the error's message.
1466
- *
1467
- * var err = new ReferenceError('This is a bad function.');
1468
- * var fn = function () { throw err; }
1469
- * expect(fn).to.throw(ReferenceError);
1470
- * expect(fn).to.throw(Error);
1471
- * expect(fn).to.throw(/bad function/);
1472
- * expect(fn).to.not.throw('good function');
1473
- * expect(fn).to.throw(ReferenceError, /bad function/);
1474
- * expect(fn).to.throw(err);
1475
- * expect(fn).to.not.throw(new RangeError('Out of range.'));
1476
- *
1477
- * Please note that when a throw expectation is negated, it will check each
1478
- * parameter independently, starting with error constructor type. The appropriate way
1479
- * to check for the existence of a type of error but for a message that does not match
1480
- * is to use `and`.
1481
- *
1482
- * expect(fn).to.throw(ReferenceError)
1483
- * .and.not.throw(/good function/);
1484
- *
1485
- * @name throw
1486
- * @alias throws
1487
- * @alias Throw
1488
- * @param {ErrorConstructor} constructor
1489
- * @param {String|RegExp} expected error message
1490
- * @param {String} message _optional_
1491
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
1492
- * @api public
1493
- */
1494
-
1495
- function assertThrows (constructor, errMsg, msg) {
1496
- if (msg) flag(this, 'message', msg);
1497
- var obj = flag(this, 'object');
1498
- new Assertion(obj, msg).is.a('function');
1499
-
1500
- var thrown = false
1501
- , desiredError = null
1502
- , name = null
1503
- , thrownError = null;
1504
-
1505
- if (arguments.length === 0) {
1506
- errMsg = null;
1507
- constructor = null;
1508
- } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
1509
- errMsg = constructor;
1510
- constructor = null;
1511
- } else if (constructor && constructor instanceof Error) {
1512
- desiredError = constructor;
1513
- constructor = null;
1514
- errMsg = null;
1515
- } else if (typeof constructor === 'function') {
1516
- name = (new constructor()).name;
1517
- } else {
1518
- constructor = null;
1519
- }
1520
-
1521
- try {
1522
- obj();
1523
- } catch (err) {
1524
- // first, check desired error
1525
- if (desiredError) {
1526
- this.assert(
1527
- err === desiredError
1528
- , 'expected #{this} to throw #{exp} but #{act} was thrown'
1529
- , 'expected #{this} to not throw #{exp}'
1530
- , desiredError
1531
- , err
1532
- );
1533
-
1534
- return this;
1535
- }
1536
- // next, check constructor
1537
- if (constructor) {
1538
- this.assert(
1539
- err instanceof constructor
1540
- , 'expected #{this} to throw #{exp} but #{act} was thrown'
1541
- , 'expected #{this} to not throw #{exp} but #{act} was thrown'
1542
- , name
1543
- , err
1544
- );
1545
-
1546
- if (!errMsg) return this;
1547
- }
1548
- // next, check message
1549
- var message = 'object' === _.type(err) && "message" in err
1550
- ? err.message
1551
- : '' + err;
1552
-
1553
- if ((message != null) && errMsg && errMsg instanceof RegExp) {
1554
- this.assert(
1555
- errMsg.exec(message)
1556
- , 'expected #{this} to throw error matching #{exp} but got #{act}'
1557
- , 'expected #{this} to throw error not matching #{exp}'
1558
- , errMsg
1559
- , message
1560
- );
1561
-
1562
- return this;
1563
- } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
1564
- this.assert(
1565
- ~message.indexOf(errMsg)
1566
- , 'expected #{this} to throw error including #{exp} but got #{act}'
1567
- , 'expected #{this} to throw error not including #{act}'
1568
- , errMsg
1569
- , message
1570
- );
1571
-
1572
- return this;
1573
- } else {
1574
- thrown = true;
1575
- thrownError = err;
1576
- }
1577
- }
1578
-
1579
- var actuallyGot = ''
1580
- , expectedThrown = name !== null
1581
- ? name
1582
- : desiredError
1583
- ? '#{exp}' //_.inspect(desiredError)
1584
- : 'an error';
1585
-
1586
- if (thrown) {
1587
- actuallyGot = ' but #{act} was thrown'
1588
- }
1589
-
1590
- this.assert(
1591
- thrown === true
1592
- , 'expected #{this} to throw ' + expectedThrown + actuallyGot
1593
- , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
1594
- , desiredError
1595
- , thrownError
1596
- );
1597
- };
1598
-
1599
- Assertion.addMethod('throw', assertThrows);
1600
- Assertion.addMethod('throws', assertThrows);
1601
- Assertion.addMethod('Throw', assertThrows);
1602
-
1603
- /**
1604
- * ### .respondTo(method)
1605
- *
1606
- * Asserts that the object or class target will respond to a method.
1607
- *
1608
- * Klass.prototype.bar = function(){};
1609
- * expect(Klass).to.respondTo('bar');
1610
- * expect(obj).to.respondTo('bar');
1611
- *
1612
- * To check if a constructor will respond to a static function,
1613
- * set the `itself` flag.
1614
- *
1615
- * Klass.baz = function(){};
1616
- * expect(Klass).itself.to.respondTo('baz');
1617
- *
1618
- * @name respondTo
1619
- * @param {String} method
1620
- * @param {String} message _optional_
1621
- * @api public
1622
- */
1623
-
1624
- Assertion.addMethod('respondTo', function (method, msg) {
1625
- if (msg) flag(this, 'message', msg);
1626
- var obj = flag(this, 'object')
1627
- , itself = flag(this, 'itself')
1628
- , context = ('function' === _.type(obj) && !itself)
1629
- ? obj.prototype[method]
1630
- : obj[method];
1631
-
1632
- this.assert(
1633
- 'function' === typeof context
1634
- , 'expected #{this} to respond to ' + _.inspect(method)
1635
- , 'expected #{this} to not respond to ' + _.inspect(method)
1636
- );
1637
- });
1638
-
1639
- /**
1640
- * ### .itself
1641
- *
1642
- * Sets the `itself` flag, later used by the `respondTo` assertion.
1643
- *
1644
- * function Foo() {}
1645
- * Foo.bar = function() {}
1646
- * Foo.prototype.baz = function() {}
1647
- *
1648
- * expect(Foo).itself.to.respondTo('bar');
1649
- * expect(Foo).itself.not.to.respondTo('baz');
1650
- *
1651
- * @name itself
1652
- * @api public
1653
- */
1654
-
1655
- Assertion.addProperty('itself', function () {
1656
- flag(this, 'itself', true);
1657
- });
1658
-
1659
- /**
1660
- * ### .satisfy(method)
1661
- *
1662
- * Asserts that the target passes a given truth test.
1663
- *
1664
- * expect(1).to.satisfy(function(num) { return num > 0; });
1665
- *
1666
- * @name satisfy
1667
- * @param {Function} matcher
1668
- * @param {String} message _optional_
1669
- * @api public
1670
- */
1671
-
1672
- Assertion.addMethod('satisfy', function (matcher, msg) {
1673
- if (msg) flag(this, 'message', msg);
1674
- var obj = flag(this, 'object');
1675
- this.assert(
1676
- matcher(obj)
1677
- , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
1678
- , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
1679
- , this.negate ? false : true
1680
- , matcher(obj)
1681
- );
1682
- });
1683
-
1684
- /**
1685
- * ### .closeTo(expected, delta)
1686
- *
1687
- * Asserts that the target is equal `expected`, to within a +/- `delta` range.
1688
- *
1689
- * expect(1.5).to.be.closeTo(1, 0.5);
1690
- *
1691
- * @name closeTo
1692
- * @param {Number} expected
1693
- * @param {Number} delta
1694
- * @param {String} message _optional_
1695
- * @api public
1696
- */
1697
-
1698
- Assertion.addMethod('closeTo', function (expected, delta, msg) {
1699
- if (msg) flag(this, 'message', msg);
1700
- var obj = flag(this, 'object');
1701
- this.assert(
1702
- Math.abs(obj - expected) <= delta
1703
- , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
1704
- , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
1705
- );
1706
- });
1707
-
1708
- function isSubsetOf(subset, superset) {
1709
- return subset.every(function(elem) {
1710
- return superset.indexOf(elem) !== -1;
1711
- })
1712
- }
1713
-
1714
- /**
1715
- * ### .members
1716
- *
1717
- * Asserts that the target is a superset of `set`,
1718
- * or that the target and `set` have the same members.
1719
- *
1720
- * expect([1, 2, 3]).to.include.members([3, 2]);
1721
- * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
1722
- *
1723
- * expect([4, 2]).to.have.members([2, 4]);
1724
- * expect([5, 2]).to.not.have.members([5, 2, 1]);
1725
- *
1726
- * @name members
1727
- * @param {Array} set
1728
- * @param {String} message _optional_
1729
- * @api public
1730
- */
1731
-
1732
- Assertion.addMethod('members', function (subset, msg) {
1733
- if (msg) flag(this, 'message', msg);
1734
- var obj = flag(this, 'object');
1735
-
1736
- new Assertion(obj).to.be.an('array');
1737
- new Assertion(subset).to.be.an('array');
1738
-
1739
- if (flag(this, 'contains')) {
1740
- return this.assert(
1741
- isSubsetOf(subset, obj)
1742
- , 'expected #{this} to be a superset of #{act}'
1743
- , 'expected #{this} to not be a superset of #{act}'
1744
- , obj
1745
- , subset
1746
- );
1747
- }
1748
-
1749
- this.assert(
1750
- isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
1751
- , 'expected #{this} to have the same members as #{act}'
1752
- , 'expected #{this} to not have the same members as #{act}'
1753
- , obj
1754
- , subset
1755
- );
1756
- });
1757
- };
1758
-
1759
- });
1760
- require.register("chai/lib/chai/interface/assert.js", function(exports, require, module){
1761
- /*!
1762
- * chai
1763
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
1764
- * MIT Licensed
1765
- */
1766
-
1767
-
1768
- module.exports = function (chai, util) {
1769
-
1770
- /*!
1771
- * Chai dependencies.
1772
- */
1773
-
1774
- var Assertion = chai.Assertion
1775
- , flag = util.flag;
1776
-
1777
- /*!
1778
- * Module export.
1779
- */
1780
-
1781
- /**
1782
- * ### assert(expression, message)
1783
- *
1784
- * Write your own test expressions.
1785
- *
1786
- * assert('foo' !== 'bar', 'foo is not bar');
1787
- * assert(Array.isArray([]), 'empty arrays are arrays');
1788
- *
1789
- * @param {Mixed} expression to test for truthiness
1790
- * @param {String} message to display on error
1791
- * @name assert
1792
- * @api public
1793
- */
1794
-
1795
- var assert = chai.assert = function (express, errmsg) {
1796
- var test = new Assertion(null);
1797
- test.assert(
1798
- express
1799
- , errmsg
1800
- , '[ negation message unavailable ]'
1801
- );
1802
- };
1803
-
1804
- /**
1805
- * ### .fail(actual, expected, [message], [operator])
1806
- *
1807
- * Throw a failure. Node.js `assert` module-compatible.
1808
- *
1809
- * @name fail
1810
- * @param {Mixed} actual
1811
- * @param {Mixed} expected
1812
- * @param {String} message
1813
- * @param {String} operator
1814
- * @api public
1815
- */
1816
-
1817
- assert.fail = function (actual, expected, message, operator) {
1818
- throw new chai.AssertionError({
1819
- actual: actual
1820
- , expected: expected
1821
- , message: message
1822
- , operator: operator
1823
- , stackStartFunction: assert.fail
1824
- });
1825
- };
1826
-
1827
- /**
1828
- * ### .ok(object, [message])
1829
- *
1830
- * Asserts that `object` is truthy.
1831
- *
1832
- * assert.ok('everything', 'everything is ok');
1833
- * assert.ok(false, 'this will fail');
1834
- *
1835
- * @name ok
1836
- * @param {Mixed} object to test
1837
- * @param {String} message
1838
- * @api public
1839
- */
1840
-
1841
- assert.ok = function (val, msg) {
1842
- new Assertion(val, msg).is.ok;
1843
- };
1844
-
1845
- /**
1846
- * ### .equal(actual, expected, [message])
1847
- *
1848
- * Asserts non-strict equality (`==`) of `actual` and `expected`.
1849
- *
1850
- * assert.equal(3, '3', '== coerces values to strings');
1851
- *
1852
- * @name equal
1853
- * @param {Mixed} actual
1854
- * @param {Mixed} expected
1855
- * @param {String} message
1856
- * @api public
1857
- */
1858
-
1859
- assert.equal = function (act, exp, msg) {
1860
- var test = new Assertion(act, msg);
1861
-
1862
- test.assert(
1863
- exp == flag(test, 'object')
1864
- , 'expected #{this} to equal #{exp}'
1865
- , 'expected #{this} to not equal #{act}'
1866
- , exp
1867
- , act
1868
- );
1869
- };
1870
-
1871
- /**
1872
- * ### .notEqual(actual, expected, [message])
1873
- *
1874
- * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
1875
- *
1876
- * assert.notEqual(3, 4, 'these numbers are not equal');
1877
- *
1878
- * @name notEqual
1879
- * @param {Mixed} actual
1880
- * @param {Mixed} expected
1881
- * @param {String} message
1882
- * @api public
1883
- */
1884
-
1885
- assert.notEqual = function (act, exp, msg) {
1886
- var test = new Assertion(act, msg);
1887
-
1888
- test.assert(
1889
- exp != flag(test, 'object')
1890
- , 'expected #{this} to not equal #{exp}'
1891
- , 'expected #{this} to equal #{act}'
1892
- , exp
1893
- , act
1894
- );
1895
- };
1896
-
1897
- /**
1898
- * ### .strictEqual(actual, expected, [message])
1899
- *
1900
- * Asserts strict equality (`===`) of `actual` and `expected`.
1901
- *
1902
- * assert.strictEqual(true, true, 'these booleans are strictly equal');
1903
- *
1904
- * @name strictEqual
1905
- * @param {Mixed} actual
1906
- * @param {Mixed} expected
1907
- * @param {String} message
1908
- * @api public
1909
- */
1910
-
1911
- assert.strictEqual = function (act, exp, msg) {
1912
- new Assertion(act, msg).to.equal(exp);
1913
- };
1914
-
1915
- /**
1916
- * ### .notStrictEqual(actual, expected, [message])
1917
- *
1918
- * Asserts strict inequality (`!==`) of `actual` and `expected`.
1919
- *
1920
- * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
1921
- *
1922
- * @name notStrictEqual
1923
- * @param {Mixed} actual
1924
- * @param {Mixed} expected
1925
- * @param {String} message
1926
- * @api public
1927
- */
1928
-
1929
- assert.notStrictEqual = function (act, exp, msg) {
1930
- new Assertion(act, msg).to.not.equal(exp);
1931
- };
1932
-
1933
- /**
1934
- * ### .deepEqual(actual, expected, [message])
1935
- *
1936
- * Asserts that `actual` is deeply equal to `expected`.
1937
- *
1938
- * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
1939
- *
1940
- * @name deepEqual
1941
- * @param {Mixed} actual
1942
- * @param {Mixed} expected
1943
- * @param {String} message
1944
- * @api public
1945
- */
1946
-
1947
- assert.deepEqual = function (act, exp, msg) {
1948
- new Assertion(act, msg).to.eql(exp);
1949
- };
1950
-
1951
- /**
1952
- * ### .notDeepEqual(actual, expected, [message])
1953
- *
1954
- * Assert that `actual` is not deeply equal to `expected`.
1955
- *
1956
- * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
1957
- *
1958
- * @name notDeepEqual
1959
- * @param {Mixed} actual
1960
- * @param {Mixed} expected
1961
- * @param {String} message
1962
- * @api public
1963
- */
1964
-
1965
- assert.notDeepEqual = function (act, exp, msg) {
1966
- new Assertion(act, msg).to.not.eql(exp);
1967
- };
1968
-
1969
- /**
1970
- * ### .isTrue(value, [message])
1971
- *
1972
- * Asserts that `value` is true.
1973
- *
1974
- * var teaServed = true;
1975
- * assert.isTrue(teaServed, 'the tea has been served');
1976
- *
1977
- * @name isTrue
1978
- * @param {Mixed} value
1979
- * @param {String} message
1980
- * @api public
1981
- */
1982
-
1983
- assert.isTrue = function (val, msg) {
1984
- new Assertion(val, msg).is['true'];
1985
- };
1986
-
1987
- /**
1988
- * ### .isFalse(value, [message])
1989
- *
1990
- * Asserts that `value` is false.
1991
- *
1992
- * var teaServed = false;
1993
- * assert.isFalse(teaServed, 'no tea yet? hmm...');
1994
- *
1995
- * @name isFalse
1996
- * @param {Mixed} value
1997
- * @param {String} message
1998
- * @api public
1999
- */
2000
-
2001
- assert.isFalse = function (val, msg) {
2002
- new Assertion(val, msg).is['false'];
2003
- };
2004
-
2005
- /**
2006
- * ### .isNull(value, [message])
2007
- *
2008
- * Asserts that `value` is null.
2009
- *
2010
- * assert.isNull(err, 'there was no error');
2011
- *
2012
- * @name isNull
2013
- * @param {Mixed} value
2014
- * @param {String} message
2015
- * @api public
2016
- */
2017
-
2018
- assert.isNull = function (val, msg) {
2019
- new Assertion(val, msg).to.equal(null);
2020
- };
2021
-
2022
- /**
2023
- * ### .isNotNull(value, [message])
2024
- *
2025
- * Asserts that `value` is not null.
2026
- *
2027
- * var tea = 'tasty chai';
2028
- * assert.isNotNull(tea, 'great, time for tea!');
2029
- *
2030
- * @name isNotNull
2031
- * @param {Mixed} value
2032
- * @param {String} message
2033
- * @api public
2034
- */
2035
-
2036
- assert.isNotNull = function (val, msg) {
2037
- new Assertion(val, msg).to.not.equal(null);
2038
- };
2039
-
2040
- /**
2041
- * ### .isUndefined(value, [message])
2042
- *
2043
- * Asserts that `value` is `undefined`.
2044
- *
2045
- * var tea;
2046
- * assert.isUndefined(tea, 'no tea defined');
2047
- *
2048
- * @name isUndefined
2049
- * @param {Mixed} value
2050
- * @param {String} message
2051
- * @api public
2052
- */
2053
-
2054
- assert.isUndefined = function (val, msg) {
2055
- new Assertion(val, msg).to.equal(undefined);
2056
- };
2057
-
2058
- /**
2059
- * ### .isDefined(value, [message])
2060
- *
2061
- * Asserts that `value` is not `undefined`.
2062
- *
2063
- * var tea = 'cup of chai';
2064
- * assert.isDefined(tea, 'tea has been defined');
2065
- *
2066
- * @name isUndefined
2067
- * @param {Mixed} value
2068
- * @param {String} message
2069
- * @api public
2070
- */
2071
-
2072
- assert.isDefined = function (val, msg) {
2073
- new Assertion(val, msg).to.not.equal(undefined);
2074
- };
2075
-
2076
- /**
2077
- * ### .isFunction(value, [message])
2078
- *
2079
- * Asserts that `value` is a function.
2080
- *
2081
- * function serveTea() { return 'cup of tea'; };
2082
- * assert.isFunction(serveTea, 'great, we can have tea now');
2083
- *
2084
- * @name isFunction
2085
- * @param {Mixed} value
2086
- * @param {String} message
2087
- * @api public
2088
- */
2089
-
2090
- assert.isFunction = function (val, msg) {
2091
- new Assertion(val, msg).to.be.a('function');
2092
- };
2093
-
2094
- /**
2095
- * ### .isNotFunction(value, [message])
2096
- *
2097
- * Asserts that `value` is _not_ a function.
2098
- *
2099
- * var serveTea = [ 'heat', 'pour', 'sip' ];
2100
- * assert.isNotFunction(serveTea, 'great, we have listed the steps');
2101
- *
2102
- * @name isNotFunction
2103
- * @param {Mixed} value
2104
- * @param {String} message
2105
- * @api public
2106
- */
2107
-
2108
- assert.isNotFunction = function (val, msg) {
2109
- new Assertion(val, msg).to.not.be.a('function');
2110
- };
2111
-
2112
- /**
2113
- * ### .isObject(value, [message])
2114
- *
2115
- * Asserts that `value` is an object (as revealed by
2116
- * `Object.prototype.toString`).
2117
- *
2118
- * var selection = { name: 'Chai', serve: 'with spices' };
2119
- * assert.isObject(selection, 'tea selection is an object');
2120
- *
2121
- * @name isObject
2122
- * @param {Mixed} value
2123
- * @param {String} message
2124
- * @api public
2125
- */
2126
-
2127
- assert.isObject = function (val, msg) {
2128
- new Assertion(val, msg).to.be.a('object');
2129
- };
2130
-
2131
- /**
2132
- * ### .isNotObject(value, [message])
2133
- *
2134
- * Asserts that `value` is _not_ an object.
2135
- *
2136
- * var selection = 'chai'
2137
- * assert.isObject(selection, 'tea selection is not an object');
2138
- * assert.isObject(null, 'null is not an object');
2139
- *
2140
- * @name isNotObject
2141
- * @param {Mixed} value
2142
- * @param {String} message
2143
- * @api public
2144
- */
2145
-
2146
- assert.isNotObject = function (val, msg) {
2147
- new Assertion(val, msg).to.not.be.a('object');
2148
- };
2149
-
2150
- /**
2151
- * ### .isArray(value, [message])
2152
- *
2153
- * Asserts that `value` is an array.
2154
- *
2155
- * var menu = [ 'green', 'chai', 'oolong' ];
2156
- * assert.isArray(menu, 'what kind of tea do we want?');
2157
- *
2158
- * @name isArray
2159
- * @param {Mixed} value
2160
- * @param {String} message
2161
- * @api public
2162
- */
2163
-
2164
- assert.isArray = function (val, msg) {
2165
- new Assertion(val, msg).to.be.an('array');
2166
- };
2167
-
2168
- /**
2169
- * ### .isNotArray(value, [message])
2170
- *
2171
- * Asserts that `value` is _not_ an array.
2172
- *
2173
- * var menu = 'green|chai|oolong';
2174
- * assert.isNotArray(menu, 'what kind of tea do we want?');
2175
- *
2176
- * @name isNotArray
2177
- * @param {Mixed} value
2178
- * @param {String} message
2179
- * @api public
2180
- */
2181
-
2182
- assert.isNotArray = function (val, msg) {
2183
- new Assertion(val, msg).to.not.be.an('array');
2184
- };
2185
-
2186
- /**
2187
- * ### .isString(value, [message])
2188
- *
2189
- * Asserts that `value` is a string.
2190
- *
2191
- * var teaOrder = 'chai';
2192
- * assert.isString(teaOrder, 'order placed');
2193
- *
2194
- * @name isString
2195
- * @param {Mixed} value
2196
- * @param {String} message
2197
- * @api public
2198
- */
2199
-
2200
- assert.isString = function (val, msg) {
2201
- new Assertion(val, msg).to.be.a('string');
2202
- };
2203
-
2204
- /**
2205
- * ### .isNotString(value, [message])
2206
- *
2207
- * Asserts that `value` is _not_ a string.
2208
- *
2209
- * var teaOrder = 4;
2210
- * assert.isNotString(teaOrder, 'order placed');
2211
- *
2212
- * @name isNotString
2213
- * @param {Mixed} value
2214
- * @param {String} message
2215
- * @api public
2216
- */
2217
-
2218
- assert.isNotString = function (val, msg) {
2219
- new Assertion(val, msg).to.not.be.a('string');
2220
- };
2221
-
2222
- /**
2223
- * ### .isNumber(value, [message])
2224
- *
2225
- * Asserts that `value` is a number.
2226
- *
2227
- * var cups = 2;
2228
- * assert.isNumber(cups, 'how many cups');
2229
- *
2230
- * @name isNumber
2231
- * @param {Number} value
2232
- * @param {String} message
2233
- * @api public
2234
- */
2235
-
2236
- assert.isNumber = function (val, msg) {
2237
- new Assertion(val, msg).to.be.a('number');
2238
- };
2239
-
2240
- /**
2241
- * ### .isNotNumber(value, [message])
2242
- *
2243
- * Asserts that `value` is _not_ a number.
2244
- *
2245
- * var cups = '2 cups please';
2246
- * assert.isNotNumber(cups, 'how many cups');
2247
- *
2248
- * @name isNotNumber
2249
- * @param {Mixed} value
2250
- * @param {String} message
2251
- * @api public
2252
- */
2253
-
2254
- assert.isNotNumber = function (val, msg) {
2255
- new Assertion(val, msg).to.not.be.a('number');
2256
- };
2257
-
2258
- /**
2259
- * ### .isBoolean(value, [message])
2260
- *
2261
- * Asserts that `value` is a boolean.
2262
- *
2263
- * var teaReady = true
2264
- * , teaServed = false;
2265
- *
2266
- * assert.isBoolean(teaReady, 'is the tea ready');
2267
- * assert.isBoolean(teaServed, 'has tea been served');
2268
- *
2269
- * @name isBoolean
2270
- * @param {Mixed} value
2271
- * @param {String} message
2272
- * @api public
2273
- */
2274
-
2275
- assert.isBoolean = function (val, msg) {
2276
- new Assertion(val, msg).to.be.a('boolean');
2277
- };
2278
-
2279
- /**
2280
- * ### .isNotBoolean(value, [message])
2281
- *
2282
- * Asserts that `value` is _not_ a boolean.
2283
- *
2284
- * var teaReady = 'yep'
2285
- * , teaServed = 'nope';
2286
- *
2287
- * assert.isNotBoolean(teaReady, 'is the tea ready');
2288
- * assert.isNotBoolean(teaServed, 'has tea been served');
2289
- *
2290
- * @name isNotBoolean
2291
- * @param {Mixed} value
2292
- * @param {String} message
2293
- * @api public
2294
- */
2295
-
2296
- assert.isNotBoolean = function (val, msg) {
2297
- new Assertion(val, msg).to.not.be.a('boolean');
2298
- };
2299
-
2300
- /**
2301
- * ### .typeOf(value, name, [message])
2302
- *
2303
- * Asserts that `value`'s type is `name`, as determined by
2304
- * `Object.prototype.toString`.
2305
- *
2306
- * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
2307
- * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
2308
- * assert.typeOf('tea', 'string', 'we have a string');
2309
- * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
2310
- * assert.typeOf(null, 'null', 'we have a null');
2311
- * assert.typeOf(undefined, 'undefined', 'we have an undefined');
2312
- *
2313
- * @name typeOf
2314
- * @param {Mixed} value
2315
- * @param {String} name
2316
- * @param {String} message
2317
- * @api public
2318
- */
2319
-
2320
- assert.typeOf = function (val, type, msg) {
2321
- new Assertion(val, msg).to.be.a(type);
2322
- };
2323
-
2324
- /**
2325
- * ### .notTypeOf(value, name, [message])
2326
- *
2327
- * Asserts that `value`'s type is _not_ `name`, as determined by
2328
- * `Object.prototype.toString`.
2329
- *
2330
- * assert.notTypeOf('tea', 'number', 'strings are not numbers');
2331
- *
2332
- * @name notTypeOf
2333
- * @param {Mixed} value
2334
- * @param {String} typeof name
2335
- * @param {String} message
2336
- * @api public
2337
- */
2338
-
2339
- assert.notTypeOf = function (val, type, msg) {
2340
- new Assertion(val, msg).to.not.be.a(type);
2341
- };
2342
-
2343
- /**
2344
- * ### .instanceOf(object, constructor, [message])
2345
- *
2346
- * Asserts that `value` is an instance of `constructor`.
2347
- *
2348
- * var Tea = function (name) { this.name = name; }
2349
- * , chai = new Tea('chai');
2350
- *
2351
- * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
2352
- *
2353
- * @name instanceOf
2354
- * @param {Object} object
2355
- * @param {Constructor} constructor
2356
- * @param {String} message
2357
- * @api public
2358
- */
2359
-
2360
- assert.instanceOf = function (val, type, msg) {
2361
- new Assertion(val, msg).to.be.instanceOf(type);
2362
- };
2363
-
2364
- /**
2365
- * ### .notInstanceOf(object, constructor, [message])
2366
- *
2367
- * Asserts `value` is not an instance of `constructor`.
2368
- *
2369
- * var Tea = function (name) { this.name = name; }
2370
- * , chai = new String('chai');
2371
- *
2372
- * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
2373
- *
2374
- * @name notInstanceOf
2375
- * @param {Object} object
2376
- * @param {Constructor} constructor
2377
- * @param {String} message
2378
- * @api public
2379
- */
2380
-
2381
- assert.notInstanceOf = function (val, type, msg) {
2382
- new Assertion(val, msg).to.not.be.instanceOf(type);
2383
- };
2384
-
2385
- /**
2386
- * ### .include(haystack, needle, [message])
2387
- *
2388
- * Asserts that `haystack` includes `needle`. Works
2389
- * for strings and arrays.
2390
- *
2391
- * assert.include('foobar', 'bar', 'foobar contains string "bar"');
2392
- * assert.include([ 1, 2, 3 ], 3, 'array contains value');
2393
- *
2394
- * @name include
2395
- * @param {Array|String} haystack
2396
- * @param {Mixed} needle
2397
- * @param {String} message
2398
- * @api public
2399
- */
2400
-
2401
- assert.include = function (exp, inc, msg) {
2402
- var obj = new Assertion(exp, msg);
2403
-
2404
- if (Array.isArray(exp)) {
2405
- obj.to.include(inc);
2406
- } else if ('string' === typeof exp) {
2407
- obj.to.contain.string(inc);
2408
- } else {
2409
- throw new chai.AssertionError({
2410
- message: 'expected an array or string'
2411
- , stackStartFunction: assert.include
2412
- });
2413
- }
2414
- };
2415
-
2416
- /**
2417
- * ### .notInclude(haystack, needle, [message])
2418
- *
2419
- * Asserts that `haystack` does not include `needle`. Works
2420
- * for strings and arrays.
2421
- *i
2422
- * assert.notInclude('foobar', 'baz', 'string not include substring');
2423
- * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
2424
- *
2425
- * @name notInclude
2426
- * @param {Array|String} haystack
2427
- * @param {Mixed} needle
2428
- * @param {String} message
2429
- * @api public
2430
- */
2431
-
2432
- assert.notInclude = function (exp, inc, msg) {
2433
- var obj = new Assertion(exp, msg);
2434
-
2435
- if (Array.isArray(exp)) {
2436
- obj.to.not.include(inc);
2437
- } else if ('string' === typeof exp) {
2438
- obj.to.not.contain.string(inc);
2439
- } else {
2440
- throw new chai.AssertionError({
2441
- message: 'expected an array or string'
2442
- , stackStartFunction: assert.include
2443
- });
2444
- }
2445
- };
2446
-
2447
- /**
2448
- * ### .match(value, regexp, [message])
2449
- *
2450
- * Asserts that `value` matches the regular expression `regexp`.
2451
- *
2452
- * assert.match('foobar', /^foo/, 'regexp matches');
2453
- *
2454
- * @name match
2455
- * @param {Mixed} value
2456
- * @param {RegExp} regexp
2457
- * @param {String} message
2458
- * @api public
2459
- */
2460
-
2461
- assert.match = function (exp, re, msg) {
2462
- new Assertion(exp, msg).to.match(re);
2463
- };
2464
-
2465
- /**
2466
- * ### .notMatch(value, regexp, [message])
2467
- *
2468
- * Asserts that `value` does not match the regular expression `regexp`.
2469
- *
2470
- * assert.notMatch('foobar', /^foo/, 'regexp does not match');
2471
- *
2472
- * @name notMatch
2473
- * @param {Mixed} value
2474
- * @param {RegExp} regexp
2475
- * @param {String} message
2476
- * @api public
2477
- */
2478
-
2479
- assert.notMatch = function (exp, re, msg) {
2480
- new Assertion(exp, msg).to.not.match(re);
2481
- };
2482
-
2483
- /**
2484
- * ### .property(object, property, [message])
2485
- *
2486
- * Asserts that `object` has a property named by `property`.
2487
- *
2488
- * assert.property({ tea: { green: 'matcha' }}, 'tea');
2489
- *
2490
- * @name property
2491
- * @param {Object} object
2492
- * @param {String} property
2493
- * @param {String} message
2494
- * @api public
2495
- */
2496
-
2497
- assert.property = function (obj, prop, msg) {
2498
- new Assertion(obj, msg).to.have.property(prop);
2499
- };
2500
-
2501
- /**
2502
- * ### .notProperty(object, property, [message])
2503
- *
2504
- * Asserts that `object` does _not_ have a property named by `property`.
2505
- *
2506
- * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
2507
- *
2508
- * @name notProperty
2509
- * @param {Object} object
2510
- * @param {String} property
2511
- * @param {String} message
2512
- * @api public
2513
- */
2514
-
2515
- assert.notProperty = function (obj, prop, msg) {
2516
- new Assertion(obj, msg).to.not.have.property(prop);
2517
- };
2518
-
2519
- /**
2520
- * ### .deepProperty(object, property, [message])
2521
- *
2522
- * Asserts that `object` has a property named by `property`, which can be a
2523
- * string using dot- and bracket-notation for deep reference.
2524
- *
2525
- * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
2526
- *
2527
- * @name deepProperty
2528
- * @param {Object} object
2529
- * @param {String} property
2530
- * @param {String} message
2531
- * @api public
2532
- */
2533
-
2534
- assert.deepProperty = function (obj, prop, msg) {
2535
- new Assertion(obj, msg).to.have.deep.property(prop);
2536
- };
2537
-
2538
- /**
2539
- * ### .notDeepProperty(object, property, [message])
2540
- *
2541
- * Asserts that `object` does _not_ have a property named by `property`, which
2542
- * can be a string using dot- and bracket-notation for deep reference.
2543
- *
2544
- * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
2545
- *
2546
- * @name notDeepProperty
2547
- * @param {Object} object
2548
- * @param {String} property
2549
- * @param {String} message
2550
- * @api public
2551
- */
2552
-
2553
- assert.notDeepProperty = function (obj, prop, msg) {
2554
- new Assertion(obj, msg).to.not.have.deep.property(prop);
2555
- };
2556
-
2557
- /**
2558
- * ### .propertyVal(object, property, value, [message])
2559
- *
2560
- * Asserts that `object` has a property named by `property` with value given
2561
- * by `value`.
2562
- *
2563
- * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
2564
- *
2565
- * @name propertyVal
2566
- * @param {Object} object
2567
- * @param {String} property
2568
- * @param {Mixed} value
2569
- * @param {String} message
2570
- * @api public
2571
- */
2572
-
2573
- assert.propertyVal = function (obj, prop, val, msg) {
2574
- new Assertion(obj, msg).to.have.property(prop, val);
2575
- };
2576
-
2577
- /**
2578
- * ### .propertyNotVal(object, property, value, [message])
2579
- *
2580
- * Asserts that `object` has a property named by `property`, but with a value
2581
- * different from that given by `value`.
2582
- *
2583
- * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
2584
- *
2585
- * @name propertyNotVal
2586
- * @param {Object} object
2587
- * @param {String} property
2588
- * @param {Mixed} value
2589
- * @param {String} message
2590
- * @api public
2591
- */
2592
-
2593
- assert.propertyNotVal = function (obj, prop, val, msg) {
2594
- new Assertion(obj, msg).to.not.have.property(prop, val);
2595
- };
2596
-
2597
- /**
2598
- * ### .deepPropertyVal(object, property, value, [message])
2599
- *
2600
- * Asserts that `object` has a property named by `property` with value given
2601
- * by `value`. `property` can use dot- and bracket-notation for deep
2602
- * reference.
2603
- *
2604
- * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
2605
- *
2606
- * @name deepPropertyVal
2607
- * @param {Object} object
2608
- * @param {String} property
2609
- * @param {Mixed} value
2610
- * @param {String} message
2611
- * @api public
2612
- */
2613
-
2614
- assert.deepPropertyVal = function (obj, prop, val, msg) {
2615
- new Assertion(obj, msg).to.have.deep.property(prop, val);
2616
- };
2617
-
2618
- /**
2619
- * ### .deepPropertyNotVal(object, property, value, [message])
2620
- *
2621
- * Asserts that `object` has a property named by `property`, but with a value
2622
- * different from that given by `value`. `property` can use dot- and
2623
- * bracket-notation for deep reference.
2624
- *
2625
- * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
2626
- *
2627
- * @name deepPropertyNotVal
2628
- * @param {Object} object
2629
- * @param {String} property
2630
- * @param {Mixed} value
2631
- * @param {String} message
2632
- * @api public
2633
- */
2634
-
2635
- assert.deepPropertyNotVal = function (obj, prop, val, msg) {
2636
- new Assertion(obj, msg).to.not.have.deep.property(prop, val);
2637
- };
2638
-
2639
- /**
2640
- * ### .lengthOf(object, length, [message])
2641
- *
2642
- * Asserts that `object` has a `length` property with the expected value.
2643
- *
2644
- * assert.lengthOf([1,2,3], 3, 'array has length of 3');
2645
- * assert.lengthOf('foobar', 5, 'string has length of 6');
2646
- *
2647
- * @name lengthOf
2648
- * @param {Mixed} object
2649
- * @param {Number} length
2650
- * @param {String} message
2651
- * @api public
2652
- */
2653
-
2654
- assert.lengthOf = function (exp, len, msg) {
2655
- new Assertion(exp, msg).to.have.length(len);
2656
- };
2657
-
2658
- /**
2659
- * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
2660
- *
2661
- * Asserts that `function` will throw an error that is an instance of
2662
- * `constructor`, or alternately that it will throw an error with message
2663
- * matching `regexp`.
2664
- *
2665
- * assert.throw(fn, 'function throws a reference error');
2666
- * assert.throw(fn, /function throws a reference error/);
2667
- * assert.throw(fn, ReferenceError);
2668
- * assert.throw(fn, ReferenceError, 'function throws a reference error');
2669
- * assert.throw(fn, ReferenceError, /function throws a reference error/);
2670
- *
2671
- * @name throws
2672
- * @alias throw
2673
- * @alias Throw
2674
- * @param {Function} function
2675
- * @param {ErrorConstructor} constructor
2676
- * @param {RegExp} regexp
2677
- * @param {String} message
2678
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2679
- * @api public
2680
- */
2681
-
2682
- assert.Throw = function (fn, errt, errs, msg) {
2683
- if ('string' === typeof errt || errt instanceof RegExp) {
2684
- errs = errt;
2685
- errt = null;
2686
- }
2687
-
2688
- new Assertion(fn, msg).to.Throw(errt, errs);
2689
- };
2690
-
2691
- /**
2692
- * ### .doesNotThrow(function, [constructor/regexp], [message])
2693
- *
2694
- * Asserts that `function` will _not_ throw an error that is an instance of
2695
- * `constructor`, or alternately that it will not throw an error with message
2696
- * matching `regexp`.
2697
- *
2698
- * assert.doesNotThrow(fn, Error, 'function does not throw');
2699
- *
2700
- * @name doesNotThrow
2701
- * @param {Function} function
2702
- * @param {ErrorConstructor} constructor
2703
- * @param {RegExp} regexp
2704
- * @param {String} message
2705
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2706
- * @api public
2707
- */
2708
-
2709
- assert.doesNotThrow = function (fn, type, msg) {
2710
- if ('string' === typeof type) {
2711
- msg = type;
2712
- type = null;
2713
- }
2714
-
2715
- new Assertion(fn, msg).to.not.Throw(type);
2716
- };
2717
-
2718
- /**
2719
- * ### .operator(val1, operator, val2, [message])
2720
- *
2721
- * Compares two values using `operator`.
2722
- *
2723
- * assert.operator(1, '<', 2, 'everything is ok');
2724
- * assert.operator(1, '>', 2, 'this will fail');
2725
- *
2726
- * @name operator
2727
- * @param {Mixed} val1
2728
- * @param {String} operator
2729
- * @param {Mixed} val2
2730
- * @param {String} message
2731
- * @api public
2732
- */
2733
-
2734
- assert.operator = function (val, operator, val2, msg) {
2735
- if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
2736
- throw new Error('Invalid operator "' + operator + '"');
2737
- }
2738
- var test = new Assertion(eval(val + operator + val2), msg);
2739
- test.assert(
2740
- true === flag(test, 'object')
2741
- , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
2742
- , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
2743
- };
2744
-
2745
- /**
2746
- * ### .closeTo(actual, expected, delta, [message])
2747
- *
2748
- * Asserts that the target is equal `expected`, to within a +/- `delta` range.
2749
- *
2750
- * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
2751
- *
2752
- * @name closeTo
2753
- * @param {Number} actual
2754
- * @param {Number} expected
2755
- * @param {Number} delta
2756
- * @param {String} message
2757
- * @api public
2758
- */
2759
-
2760
- assert.closeTo = function (act, exp, delta, msg) {
2761
- new Assertion(act, msg).to.be.closeTo(exp, delta);
2762
- };
2763
-
2764
- /**
2765
- * ### .sameMembers(set1, set2, [message])
2766
- *
2767
- * Asserts that `set1` and `set2` have the same members.
2768
- * Order is not taken into account.
2769
- *
2770
- * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
2771
- *
2772
- * @name sameMembers
2773
- * @param {Array} superset
2774
- * @param {Array} subset
2775
- * @param {String} message
2776
- * @api public
2777
- */
2778
-
2779
- assert.sameMembers = function (set1, set2, msg) {
2780
- new Assertion(set1, msg).to.have.same.members(set2);
2781
- }
2782
-
2783
- /**
2784
- * ### .includeMembers(superset, subset, [message])
2785
- *
2786
- * Asserts that `subset` is included in `superset`.
2787
- * Order is not taken into account.
2788
- *
2789
- * assert.includeMembers([ 1, 2, 3 ], [ 2, 1 ], 'include members');
2790
- *
2791
- * @name includeMembers
2792
- * @param {Array} superset
2793
- * @param {Array} subset
2794
- * @param {String} message
2795
- * @api public
2796
- */
2797
-
2798
- assert.includeMembers = function (superset, subset, msg) {
2799
- new Assertion(superset, msg).to.include.members(subset);
2800
- }
2801
-
2802
- /*!
2803
- * Undocumented / untested
2804
- */
2805
-
2806
- assert.ifError = function (val, msg) {
2807
- new Assertion(val, msg).to.not.be.ok;
2808
- };
2809
-
2810
- /*!
2811
- * Aliases.
2812
- */
2813
-
2814
- (function alias(name, as){
2815
- assert[as] = assert[name];
2816
- return alias;
2817
- })
2818
- ('Throw', 'throw')
2819
- ('Throw', 'throws');
2820
- };
2821
-
2822
- });
2823
- require.register("chai/lib/chai/interface/expect.js", function(exports, require, module){
2824
- /*!
2825
- * chai
2826
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2827
- * MIT Licensed
2828
- */
2829
-
2830
- module.exports = function (chai, util) {
2831
- chai.expect = function (val, message) {
2832
- return new chai.Assertion(val, message);
2833
- };
2834
- };
2835
-
2836
-
2837
- });
2838
- require.register("chai/lib/chai/interface/should.js", function(exports, require, module){
2839
- /*!
2840
- * chai
2841
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
2842
- * MIT Licensed
2843
- */
2844
-
2845
- module.exports = function (chai, util) {
2846
- var Assertion = chai.Assertion;
2847
-
2848
- function loadShould () {
2849
- // modify Object.prototype to have `should`
2850
- Object.defineProperty(Object.prototype, 'should',
2851
- {
2852
- set: function (value) {
2853
- // See https://github.com/chaijs/chai/issues/86: this makes
2854
- // `whatever.should = someValue` actually set `someValue`, which is
2855
- // especially useful for `global.should = require('chai').should()`.
2856
- //
2857
- // Note that we have to use [[DefineProperty]] instead of [[Put]]
2858
- // since otherwise we would trigger this very setter!
2859
- Object.defineProperty(this, 'should', {
2860
- value: value,
2861
- enumerable: true,
2862
- configurable: true,
2863
- writable: true
2864
- });
2865
- }
2866
- , get: function(){
2867
- if (this instanceof String || this instanceof Number) {
2868
- return new Assertion(this.constructor(this));
2869
- } else if (this instanceof Boolean) {
2870
- return new Assertion(this == true);
2871
- }
2872
- return new Assertion(this);
2873
- }
2874
- , configurable: true
2875
- });
2876
-
2877
- var should = {};
2878
-
2879
- should.equal = function (val1, val2, msg) {
2880
- new Assertion(val1, msg).to.equal(val2);
2881
- };
2882
-
2883
- should.Throw = function (fn, errt, errs, msg) {
2884
- new Assertion(fn, msg).to.Throw(errt, errs);
2885
- };
2886
-
2887
- should.exist = function (val, msg) {
2888
- new Assertion(val, msg).to.exist;
2889
- }
2890
-
2891
- // negation
2892
- should.not = {}
2893
-
2894
- should.not.equal = function (val1, val2, msg) {
2895
- new Assertion(val1, msg).to.not.equal(val2);
2896
- };
2897
-
2898
- should.not.Throw = function (fn, errt, errs, msg) {
2899
- new Assertion(fn, msg).to.not.Throw(errt, errs);
2900
- };
2901
-
2902
- should.not.exist = function (val, msg) {
2903
- new Assertion(val, msg).to.not.exist;
2904
- }
2905
-
2906
- should['throw'] = should['Throw'];
2907
- should.not['throw'] = should.not['Throw'];
2908
-
2909
- return should;
2910
- };
2911
-
2912
- chai.should = loadShould;
2913
- chai.Should = loadShould;
2914
- };
2915
-
2916
- });
2917
- require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports, require, module){
2918
- /*!
2919
- * Chai - addChainingMethod utility
2920
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
2921
- * MIT Licensed
2922
- */
2923
-
2924
- /*!
2925
- * Module dependencies
2926
- */
2927
-
2928
- var transferFlags = require('./transferFlags');
2929
-
2930
- /*!
2931
- * Module variables
2932
- */
2933
-
2934
- // Check whether `__proto__` is supported
2935
- var hasProtoSupport = '__proto__' in Object;
2936
-
2937
- // Without `__proto__` support, this module will need to add properties to a function.
2938
- // However, some Function.prototype methods cannot be overwritten,
2939
- // and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
2940
- var excludeNames = /^(?:length|name|arguments|caller)$/;
2941
-
2942
- // Cache `Function` properties
2943
- var call = Function.prototype.call,
2944
- apply = Function.prototype.apply;
2945
-
2946
- /**
2947
- * ### addChainableMethod (ctx, name, method, chainingBehavior)
2948
- *
2949
- * Adds a method to an object, such that the method can also be chained.
2950
- *
2951
- * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
2952
- * var obj = utils.flag(this, 'object');
2953
- * new chai.Assertion(obj).to.be.equal(str);
2954
- * });
2955
- *
2956
- * Can also be accessed directly from `chai.Assertion`.
2957
- *
2958
- * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
2959
- *
2960
- * The result can then be used as both a method assertion, executing both `method` and
2961
- * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
2962
- *
2963
- * expect(fooStr).to.be.foo('bar');
2964
- * expect(fooStr).to.be.foo.equal('foo');
2965
- *
2966
- * @param {Object} ctx object to which the method is added
2967
- * @param {String} name of method to add
2968
- * @param {Function} method function to be used for `name`, when called
2969
- * @param {Function} chainingBehavior function to be called every time the property is accessed
2970
- * @name addChainableMethod
2971
- * @api public
2972
- */
2973
-
2974
- module.exports = function (ctx, name, method, chainingBehavior) {
2975
- if (typeof chainingBehavior !== 'function')
2976
- chainingBehavior = function () { };
2977
-
2978
- Object.defineProperty(ctx, name,
2979
- { get: function () {
2980
- chainingBehavior.call(this);
2981
-
2982
- var assert = function () {
2983
- var result = method.apply(this, arguments);
2984
- return result === undefined ? this : result;
2985
- };
2986
-
2987
- // Use `__proto__` if available
2988
- if (hasProtoSupport) {
2989
- // Inherit all properties from the object by replacing the `Function` prototype
2990
- var prototype = assert.__proto__ = Object.create(this);
2991
- // Restore the `call` and `apply` methods from `Function`
2992
- prototype.call = call;
2993
- prototype.apply = apply;
2994
- }
2995
- // Otherwise, redefine all properties (slow!)
2996
- else {
2997
- var asserterNames = Object.getOwnPropertyNames(ctx);
2998
- asserterNames.forEach(function (asserterName) {
2999
- if (!excludeNames.test(asserterName)) {
3000
- var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
3001
- Object.defineProperty(assert, asserterName, pd);
3002
- }
3003
- });
3004
- }
3005
-
3006
- transferFlags(this, assert);
3007
- return assert;
3008
- }
3009
- , configurable: true
3010
- });
3011
- };
3012
-
3013
- });
3014
- require.register("chai/lib/chai/utils/addMethod.js", function(exports, require, module){
3015
- /*!
3016
- * Chai - addMethod utility
3017
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3018
- * MIT Licensed
3019
- */
3020
-
3021
- /**
3022
- * ### .addMethod (ctx, name, method)
3023
- *
3024
- * Adds a method to the prototype of an object.
3025
- *
3026
- * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
3027
- * var obj = utils.flag(this, 'object');
3028
- * new chai.Assertion(obj).to.be.equal(str);
3029
- * });
3030
- *
3031
- * Can also be accessed directly from `chai.Assertion`.
3032
- *
3033
- * chai.Assertion.addMethod('foo', fn);
3034
- *
3035
- * Then can be used as any other assertion.
3036
- *
3037
- * expect(fooStr).to.be.foo('bar');
3038
- *
3039
- * @param {Object} ctx object to which the method is added
3040
- * @param {String} name of method to add
3041
- * @param {Function} method function to be used for name
3042
- * @name addMethod
3043
- * @api public
3044
- */
3045
-
3046
- module.exports = function (ctx, name, method) {
3047
- ctx[name] = function () {
3048
- var result = method.apply(this, arguments);
3049
- return result === undefined ? this : result;
3050
- };
3051
- };
3052
-
3053
- });
3054
- require.register("chai/lib/chai/utils/addProperty.js", function(exports, require, module){
3055
- /*!
3056
- * Chai - addProperty utility
3057
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3058
- * MIT Licensed
3059
- */
3060
-
3061
- /**
3062
- * ### addProperty (ctx, name, getter)
3063
- *
3064
- * Adds a property to the prototype of an object.
3065
- *
3066
- * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
3067
- * var obj = utils.flag(this, 'object');
3068
- * new chai.Assertion(obj).to.be.instanceof(Foo);
3069
- * });
3070
- *
3071
- * Can also be accessed directly from `chai.Assertion`.
3072
- *
3073
- * chai.Assertion.addProperty('foo', fn);
3074
- *
3075
- * Then can be used as any other assertion.
3076
- *
3077
- * expect(myFoo).to.be.foo;
3078
- *
3079
- * @param {Object} ctx object to which the property is added
3080
- * @param {String} name of property to add
3081
- * @param {Function} getter function to be used for name
3082
- * @name addProperty
3083
- * @api public
3084
- */
3085
-
3086
- module.exports = function (ctx, name, getter) {
3087
- Object.defineProperty(ctx, name,
3088
- { get: function () {
3089
- var result = getter.call(this);
3090
- return result === undefined ? this : result;
3091
- }
3092
- , configurable: true
3093
- });
3094
- };
3095
-
3096
- });
3097
- require.register("chai/lib/chai/utils/eql.js", function(exports, require, module){
3098
- // This is (almost) directly from Node.js assert
3099
- // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
3100
-
3101
- module.exports = _deepEqual;
3102
-
3103
- var getEnumerableProperties = require('./getEnumerableProperties');
3104
-
3105
- // for the browser
3106
- var Buffer;
3107
- try {
3108
- Buffer = require('buffer').Buffer;
3109
- } catch (ex) {
3110
- Buffer = {
3111
- isBuffer: function () { return false; }
3112
- };
3113
- }
3114
-
3115
- function _deepEqual(actual, expected, memos) {
3116
-
3117
- // 7.1. All identical values are equivalent, as determined by ===.
3118
- if (actual === expected) {
3119
- return true;
3120
-
3121
- } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
3122
- if (actual.length != expected.length) return false;
3123
-
3124
- for (var i = 0; i < actual.length; i++) {
3125
- if (actual[i] !== expected[i]) return false;
3126
- }
3127
-
3128
- return true;
3129
-
3130
- // 7.2. If the expected value is a Date object, the actual value is
3131
- // equivalent if it is also a Date object that refers to the same time.
3132
- } else if (actual instanceof Date && expected instanceof Date) {
3133
- return actual.getTime() === expected.getTime();
3134
-
3135
- // 7.3. Other pairs that do not both pass typeof value == 'object',
3136
- // equivalence is determined by ==.
3137
- } else if (typeof actual != 'object' && typeof expected != 'object') {
3138
- return actual === expected;
3139
-
3140
- // 7.4. For all other Object pairs, including Array objects, equivalence is
3141
- // determined by having the same number of owned properties (as verified
3142
- // with Object.prototype.hasOwnProperty.call), the same set of keys
3143
- // (although not necessarily the same order), equivalent values for every
3144
- // corresponding key, and an identical 'prototype' property. Note: this
3145
- // accounts for both named and indexed properties on Arrays.
3146
- } else {
3147
- return objEquiv(actual, expected, memos);
3148
- }
3149
- }
3150
-
3151
- function isUndefinedOrNull(value) {
3152
- return value === null || value === undefined;
3153
- }
3154
-
3155
- function isArguments(object) {
3156
- return Object.prototype.toString.call(object) == '[object Arguments]';
3157
- }
3158
-
3159
- function objEquiv(a, b, memos) {
3160
- if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
3161
- return false;
3162
-
3163
- // an identical 'prototype' property.
3164
- if (a.prototype !== b.prototype) return false;
3165
-
3166
- // check if we have already compared a and b
3167
- var i;
3168
- if (memos) {
3169
- for(i = 0; i < memos.length; i++) {
3170
- if ((memos[i][0] === a && memos[i][1] === b) ||
3171
- (memos[i][0] === b && memos[i][1] === a))
3172
- return true;
3173
- }
3174
- } else {
3175
- memos = [];
3176
- }
3177
-
3178
- //~~~I've managed to break Object.keys through screwy arguments passing.
3179
- // Converting to array solves the problem.
3180
- if (isArguments(a)) {
3181
- if (!isArguments(b)) {
3182
- return false;
3183
- }
3184
- a = pSlice.call(a);
3185
- b = pSlice.call(b);
3186
- return _deepEqual(a, b, memos);
3187
- }
3188
- try {
3189
- var ka = getEnumerableProperties(a),
3190
- kb = getEnumerableProperties(b),
3191
- key;
3192
- } catch (e) {//happens when one is a string literal and the other isn't
3193
- return false;
3194
- }
3195
-
3196
- // having the same number of owned properties (keys incorporates
3197
- // hasOwnProperty)
3198
- if (ka.length != kb.length)
3199
- return false;
3200
-
3201
- //the same set of keys (although not necessarily the same order),
3202
- ka.sort();
3203
- kb.sort();
3204
- //~~~cheap key test
3205
- for (i = ka.length - 1; i >= 0; i--) {
3206
- if (ka[i] != kb[i])
3207
- return false;
3208
- }
3209
-
3210
- // remember objects we have compared to guard against circular references
3211
- memos.push([ a, b ]);
3212
-
3213
- //equivalent values for every corresponding key, and
3214
- //~~~possibly expensive deep test
3215
- for (i = ka.length - 1; i >= 0; i--) {
3216
- key = ka[i];
3217
- if (!_deepEqual(a[key], b[key], memos)) return false;
3218
- }
3219
-
3220
- return true;
3221
- }
3222
-
3223
- });
3224
- require.register("chai/lib/chai/utils/flag.js", function(exports, require, module){
3225
- /*!
3226
- * Chai - flag utility
3227
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3228
- * MIT Licensed
3229
- */
3230
-
3231
- /**
3232
- * ### flag(object ,key, [value])
3233
- *
3234
- * Get or set a flag value on an object. If a
3235
- * value is provided it will be set, else it will
3236
- * return the currently set value or `undefined` if
3237
- * the value is not set.
3238
- *
3239
- * utils.flag(this, 'foo', 'bar'); // setter
3240
- * utils.flag(this, 'foo'); // getter, returns `bar`
3241
- *
3242
- * @param {Object} object (constructed Assertion
3243
- * @param {String} key
3244
- * @param {Mixed} value (optional)
3245
- * @name flag
3246
- * @api private
3247
- */
3248
-
3249
- module.exports = function (obj, key, value) {
3250
- var flags = obj.__flags || (obj.__flags = Object.create(null));
3251
- if (arguments.length === 3) {
3252
- flags[key] = value;
3253
- } else {
3254
- return flags[key];
3255
- }
3256
- };
3257
-
3258
- });
3259
- require.register("chai/lib/chai/utils/getActual.js", function(exports, require, module){
3260
- /*!
3261
- * Chai - getActual utility
3262
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3263
- * MIT Licensed
3264
- */
3265
-
3266
- /**
3267
- * # getActual(object, [actual])
3268
- *
3269
- * Returns the `actual` value for an Assertion
3270
- *
3271
- * @param {Object} object (constructed Assertion)
3272
- * @param {Arguments} chai.Assertion.prototype.assert arguments
3273
- */
3274
-
3275
- module.exports = function (obj, args) {
3276
- var actual = args[4];
3277
- return 'undefined' !== typeof actual ? actual : obj._obj;
3278
- };
3279
-
3280
- });
3281
- require.register("chai/lib/chai/utils/getEnumerableProperties.js", function(exports, require, module){
3282
- /*!
3283
- * Chai - getEnumerableProperties utility
3284
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3285
- * MIT Licensed
3286
- */
3287
-
3288
- /**
3289
- * ### .getEnumerableProperties(object)
3290
- *
3291
- * This allows the retrieval of enumerable property names of an object,
3292
- * inherited or not.
3293
- *
3294
- * @param {Object} object
3295
- * @returns {Array}
3296
- * @name getEnumerableProperties
3297
- * @api public
3298
- */
3299
-
3300
- module.exports = function getEnumerableProperties(object) {
3301
- var result = [];
3302
- for (var name in object) {
3303
- result.push(name);
3304
- }
3305
- return result;
3306
- };
3307
-
3308
- });
3309
- require.register("chai/lib/chai/utils/getMessage.js", function(exports, require, module){
3310
- /*!
3311
- * Chai - message composition utility
3312
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3313
- * MIT Licensed
3314
- */
3315
-
3316
- /*!
3317
- * Module dependancies
3318
- */
3319
-
3320
- var flag = require('./flag')
3321
- , getActual = require('./getActual')
3322
- , inspect = require('./inspect')
3323
- , objDisplay = require('./objDisplay');
3324
-
3325
- /**
3326
- * ### .getMessage(object, message, negateMessage)
3327
- *
3328
- * Construct the error message based on flags
3329
- * and template tags. Template tags will return
3330
- * a stringified inspection of the object referenced.
3331
- *
3332
- * Messsage template tags:
3333
- * - `#{this}` current asserted object
3334
- * - `#{act}` actual value
3335
- * - `#{exp}` expected value
3336
- *
3337
- * @param {Object} object (constructed Assertion)
3338
- * @param {Arguments} chai.Assertion.prototype.assert arguments
3339
- * @name getMessage
3340
- * @api public
3341
- */
3342
-
3343
- module.exports = function (obj, args) {
3344
- var negate = flag(obj, 'negate')
3345
- , val = flag(obj, 'object')
3346
- , expected = args[3]
3347
- , actual = getActual(obj, args)
3348
- , msg = negate ? args[2] : args[1]
3349
- , flagMsg = flag(obj, 'message');
3350
-
3351
- msg = msg || '';
3352
- msg = msg
3353
- .replace(/#{this}/g, objDisplay(val))
3354
- .replace(/#{act}/g, objDisplay(actual))
3355
- .replace(/#{exp}/g, objDisplay(expected));
3356
-
3357
- return flagMsg ? flagMsg + ': ' + msg : msg;
3358
- };
3359
-
3360
- });
3361
- require.register("chai/lib/chai/utils/getName.js", function(exports, require, module){
3362
- /*!
3363
- * Chai - getName utility
3364
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3365
- * MIT Licensed
3366
- */
3367
-
3368
- /**
3369
- * # getName(func)
3370
- *
3371
- * Gets the name of a function, in a cross-browser way.
3372
- *
3373
- * @param {Function} a function (usually a constructor)
3374
- */
3375
-
3376
- module.exports = function (func) {
3377
- if (func.name) return func.name;
3378
-
3379
- var match = /^\s?function ([^(]*)\(/.exec(func);
3380
- return match && match[1] ? match[1] : "";
3381
- };
3382
-
3383
- });
3384
- require.register("chai/lib/chai/utils/getPathValue.js", function(exports, require, module){
3385
- /*!
3386
- * Chai - getPathValue utility
3387
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3388
- * @see https://github.com/logicalparadox/filtr
3389
- * MIT Licensed
3390
- */
3391
-
3392
- /**
3393
- * ### .getPathValue(path, object)
3394
- *
3395
- * This allows the retrieval of values in an
3396
- * object given a string path.
3397
- *
3398
- * var obj = {
3399
- * prop1: {
3400
- * arr: ['a', 'b', 'c']
3401
- * , str: 'Hello'
3402
- * }
3403
- * , prop2: {
3404
- * arr: [ { nested: 'Universe' } ]
3405
- * , str: 'Hello again!'
3406
- * }
3407
- * }
3408
- *
3409
- * The following would be the results.
3410
- *
3411
- * getPathValue('prop1.str', obj); // Hello
3412
- * getPathValue('prop1.att[2]', obj); // b
3413
- * getPathValue('prop2.arr[0].nested', obj); // Universe
3414
- *
3415
- * @param {String} path
3416
- * @param {Object} object
3417
- * @returns {Object} value or `undefined`
3418
- * @name getPathValue
3419
- * @api public
3420
- */
3421
-
3422
- var getPathValue = module.exports = function (path, obj) {
3423
- var parsed = parsePath(path);
3424
- return _getPathValue(parsed, obj);
3425
- };
3426
-
3427
- /*!
3428
- * ## parsePath(path)
3429
- *
3430
- * Helper function used to parse string object
3431
- * paths. Use in conjunction with `_getPathValue`.
3432
- *
3433
- * var parsed = parsePath('myobject.property.subprop');
3434
- *
3435
- * ### Paths:
3436
- *
3437
- * * Can be as near infinitely deep and nested
3438
- * * Arrays are also valid using the formal `myobject.document[3].property`.
3439
- *
3440
- * @param {String} path
3441
- * @returns {Object} parsed
3442
- * @api private
3443
- */
3444
-
3445
- function parsePath (path) {
3446
- var str = path.replace(/\[/g, '.[')
3447
- , parts = str.match(/(\\\.|[^.]+?)+/g);
3448
- return parts.map(function (value) {
3449
- var re = /\[(\d+)\]$/
3450
- , mArr = re.exec(value)
3451
- if (mArr) return { i: parseFloat(mArr[1]) };
3452
- else return { p: value };
3453
- });
3454
- };
3455
-
3456
- /*!
3457
- * ## _getPathValue(parsed, obj)
3458
- *
3459
- * Helper companion function for `.parsePath` that returns
3460
- * the value located at the parsed address.
3461
- *
3462
- * var value = getPathValue(parsed, obj);
3463
- *
3464
- * @param {Object} parsed definition from `parsePath`.
3465
- * @param {Object} object to search against
3466
- * @returns {Object|Undefined} value
3467
- * @api private
3468
- */
3469
-
3470
- function _getPathValue (parsed, obj) {
3471
- var tmp = obj
3472
- , res;
3473
- for (var i = 0, l = parsed.length; i < l; i++) {
3474
- var part = parsed[i];
3475
- if (tmp) {
3476
- if ('undefined' !== typeof part.p)
3477
- tmp = tmp[part.p];
3478
- else if ('undefined' !== typeof part.i)
3479
- tmp = tmp[part.i];
3480
- if (i == (l - 1)) res = tmp;
3481
- } else {
3482
- res = undefined;
3483
- }
3484
- }
3485
- return res;
3486
- };
3487
-
3488
- });
3489
- require.register("chai/lib/chai/utils/getProperties.js", function(exports, require, module){
3490
- /*!
3491
- * Chai - getProperties utility
3492
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3493
- * MIT Licensed
3494
- */
3495
-
3496
- /**
3497
- * ### .getProperties(object)
3498
- *
3499
- * This allows the retrieval of property names of an object, enumerable or not,
3500
- * inherited or not.
3501
- *
3502
- * @param {Object} object
3503
- * @returns {Array}
3504
- * @name getProperties
3505
- * @api public
3506
- */
3507
-
3508
- module.exports = function getProperties(object) {
3509
- var result = Object.getOwnPropertyNames(subject);
3510
-
3511
- function addProperty(property) {
3512
- if (result.indexOf(property) === -1) {
3513
- result.push(property);
3514
- }
3515
- }
3516
-
3517
- var proto = Object.getPrototypeOf(subject);
3518
- while (proto !== null) {
3519
- Object.getOwnPropertyNames(proto).forEach(addProperty);
3520
- proto = Object.getPrototypeOf(proto);
3521
- }
3522
-
3523
- return result;
3524
- };
3525
-
3526
- });
3527
- require.register("chai/lib/chai/utils/index.js", function(exports, require, module){
3528
- /*!
3529
- * chai
3530
- * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
3531
- * MIT Licensed
3532
- */
3533
-
3534
- /*!
3535
- * Main exports
3536
- */
3537
-
3538
- var exports = module.exports = {};
3539
-
3540
- /*!
3541
- * test utility
3542
- */
3543
-
3544
- exports.test = require('./test');
3545
-
3546
- /*!
3547
- * type utility
3548
- */
3549
-
3550
- exports.type = require('./type');
3551
-
3552
- /*!
3553
- * message utility
3554
- */
3555
-
3556
- exports.getMessage = require('./getMessage');
3557
-
3558
- /*!
3559
- * actual utility
3560
- */
3561
-
3562
- exports.getActual = require('./getActual');
3563
-
3564
- /*!
3565
- * Inspect util
3566
- */
3567
-
3568
- exports.inspect = require('./inspect');
3569
-
3570
- /*!
3571
- * Object Display util
3572
- */
3573
-
3574
- exports.objDisplay = require('./objDisplay');
3575
-
3576
- /*!
3577
- * Flag utility
3578
- */
3579
-
3580
- exports.flag = require('./flag');
3581
-
3582
- /*!
3583
- * Flag transferring utility
3584
- */
3585
-
3586
- exports.transferFlags = require('./transferFlags');
3587
-
3588
- /*!
3589
- * Deep equal utility
3590
- */
3591
-
3592
- exports.eql = require('./eql');
3593
-
3594
- /*!
3595
- * Deep path value
3596
- */
3597
-
3598
- exports.getPathValue = require('./getPathValue');
3599
-
3600
- /*!
3601
- * Function name
3602
- */
3603
-
3604
- exports.getName = require('./getName');
3605
-
3606
- /*!
3607
- * add Property
3608
- */
3609
-
3610
- exports.addProperty = require('./addProperty');
3611
-
3612
- /*!
3613
- * add Method
3614
- */
3615
-
3616
- exports.addMethod = require('./addMethod');
3617
-
3618
- /*!
3619
- * overwrite Property
3620
- */
3621
-
3622
- exports.overwriteProperty = require('./overwriteProperty');
3623
-
3624
- /*!
3625
- * overwrite Method
3626
- */
3627
-
3628
- exports.overwriteMethod = require('./overwriteMethod');
3629
-
3630
- /*!
3631
- * Add a chainable method
3632
- */
3633
-
3634
- exports.addChainableMethod = require('./addChainableMethod');
3635
-
3636
-
3637
- });
3638
- require.register("chai/lib/chai/utils/inspect.js", function(exports, require, module){
3639
- // This is (almost) directly from Node.js utils
3640
- // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
3641
-
3642
- var getName = require('./getName');
3643
- var getProperties = require('./getProperties');
3644
- var getEnumerableProperties = require('./getEnumerableProperties');
3645
-
3646
- module.exports = inspect;
3647
-
3648
- /**
3649
- * Echos the value of a value. Trys to print the value out
3650
- * in the best way possible given the different types.
3651
- *
3652
- * @param {Object} obj The object to print out.
3653
- * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
3654
- * properties of objects.
3655
- * @param {Number} depth Depth in which to descend in object. Default is 2.
3656
- * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
3657
- * output. Default is false (no coloring).
3658
- */
3659
- function inspect(obj, showHidden, depth, colors) {
3660
- var ctx = {
3661
- showHidden: showHidden,
3662
- seen: [],
3663
- stylize: function (str) { return str; }
3664
- };
3665
- return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
3666
- }
3667
-
3668
- // https://gist.github.com/1044128/
3669
- var getOuterHTML = function(element) {
3670
- if ('outerHTML' in element) return element.outerHTML;
3671
- var ns = "http://www.w3.org/1999/xhtml";
3672
- var container = document.createElementNS(ns, '_');
3673
- var elemProto = (window.HTMLElement || window.Element).prototype;
3674
- var xmlSerializer = new XMLSerializer();
3675
- var html;
3676
- if (document.xmlVersion) {
3677
- return xmlSerializer.serializeToString(element);
3678
- } else {
3679
- container.appendChild(element.cloneNode(false));
3680
- html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
3681
- container.innerHTML = '';
3682
- return html;
3683
- }
3684
- };
3685
-
3686
- // Returns true if object is a DOM element.
3687
- var isDOMElement = function (object) {
3688
- if (typeof HTMLElement === 'object') {
3689
- return object instanceof HTMLElement;
3690
- } else {
3691
- return object &&
3692
- typeof object === 'object' &&
3693
- object.nodeType === 1 &&
3694
- typeof object.nodeName === 'string';
3695
- }
3696
- };
3697
-
3698
- function formatValue(ctx, value, recurseTimes) {
3699
- // Provide a hook for user-specified inspect functions.
3700
- // Check that value is an object with an inspect function on it
3701
- if (value && typeof value.inspect === 'function' &&
3702
- // Filter out the util module, it's inspect function is special
3703
- value.inspect !== exports.inspect &&
3704
- // Also filter out any prototype objects using the circular check.
3705
- !(value.constructor && value.constructor.prototype === value)) {
3706
- return value.inspect(recurseTimes);
3707
- }
3708
-
3709
- // Primitive types cannot have properties
3710
- var primitive = formatPrimitive(ctx, value);
3711
- if (primitive) {
3712
- return primitive;
3713
- }
3714
-
3715
- // If it's DOM elem, get outer HTML.
3716
- if (isDOMElement(value)) {
3717
- return getOuterHTML(value);
3718
- }
3719
-
3720
- // Look up the keys of the object.
3721
- var visibleKeys = getEnumerableProperties(value);
3722
- var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
3723
-
3724
- // Some type of object without properties can be shortcutted.
3725
- // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
3726
- // a `stack` plus `description` property; ignore those for consistency.
3727
- if (keys.length === 0 || (isError(value) && (
3728
- (keys.length === 1 && keys[0] === 'stack') ||
3729
- (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
3730
- ))) {
3731
- if (typeof value === 'function') {
3732
- var name = getName(value);
3733
- var nameSuffix = name ? ': ' + name : '';
3734
- return ctx.stylize('[Function' + nameSuffix + ']', 'special');
3735
- }
3736
- if (isRegExp(value)) {
3737
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3738
- }
3739
- if (isDate(value)) {
3740
- return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
3741
- }
3742
- if (isError(value)) {
3743
- return formatError(value);
3744
- }
3745
- }
3746
-
3747
- var base = '', array = false, braces = ['{', '}'];
3748
-
3749
- // Make Array say that they are Array
3750
- if (isArray(value)) {
3751
- array = true;
3752
- braces = ['[', ']'];
3753
- }
3754
-
3755
- // Make functions say that they are functions
3756
- if (typeof value === 'function') {
3757
- var name = getName(value);
3758
- var nameSuffix = name ? ': ' + name : '';
3759
- base = ' [Function' + nameSuffix + ']';
3760
- }
3761
-
3762
- // Make RegExps say that they are RegExps
3763
- if (isRegExp(value)) {
3764
- base = ' ' + RegExp.prototype.toString.call(value);
3765
- }
3766
-
3767
- // Make dates with properties first say the date
3768
- if (isDate(value)) {
3769
- base = ' ' + Date.prototype.toUTCString.call(value);
3770
- }
3771
-
3772
- // Make error with message first say the error
3773
- if (isError(value)) {
3774
- return formatError(value);
3775
- }
3776
-
3777
- if (keys.length === 0 && (!array || value.length == 0)) {
3778
- return braces[0] + base + braces[1];
3779
- }
3780
-
3781
- if (recurseTimes < 0) {
3782
- if (isRegExp(value)) {
3783
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3784
- } else {
3785
- return ctx.stylize('[Object]', 'special');
3786
- }
3787
- }
3788
-
3789
- ctx.seen.push(value);
3790
-
3791
- var output;
3792
- if (array) {
3793
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
3794
- } else {
3795
- output = keys.map(function(key) {
3796
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
3797
- });
3798
- }
3799
-
3800
- ctx.seen.pop();
3801
-
3802
- return reduceToSingleString(output, base, braces);
3803
- }
3804
-
3805
-
3806
- function formatPrimitive(ctx, value) {
3807
- switch (typeof value) {
3808
- case 'undefined':
3809
- return ctx.stylize('undefined', 'undefined');
3810
-
3811
- case 'string':
3812
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
3813
- .replace(/'/g, "\\'")
3814
- .replace(/\\"/g, '"') + '\'';
3815
- return ctx.stylize(simple, 'string');
3816
-
3817
- case 'number':
3818
- return ctx.stylize('' + value, 'number');
3819
-
3820
- case 'boolean':
3821
- return ctx.stylize('' + value, 'boolean');
3822
- }
3823
- // For some reason typeof null is "object", so special case here.
3824
- if (value === null) {
3825
- return ctx.stylize('null', 'null');
3826
- }
3827
- }
3828
-
3829
-
3830
- function formatError(value) {
3831
- return '[' + Error.prototype.toString.call(value) + ']';
3832
- }
3833
-
3834
-
3835
- function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
3836
- var output = [];
3837
- for (var i = 0, l = value.length; i < l; ++i) {
3838
- if (Object.prototype.hasOwnProperty.call(value, String(i))) {
3839
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3840
- String(i), true));
3841
- } else {
3842
- output.push('');
3843
- }
3844
- }
3845
- keys.forEach(function(key) {
3846
- if (!key.match(/^\d+$/)) {
3847
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3848
- key, true));
3849
- }
3850
- });
3851
- return output;
3852
- }
3853
-
3854
-
3855
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3856
- var name, str;
3857
- if (value.__lookupGetter__) {
3858
- if (value.__lookupGetter__(key)) {
3859
- if (value.__lookupSetter__(key)) {
3860
- str = ctx.stylize('[Getter/Setter]', 'special');
3861
- } else {
3862
- str = ctx.stylize('[Getter]', 'special');
3863
- }
3864
- } else {
3865
- if (value.__lookupSetter__(key)) {
3866
- str = ctx.stylize('[Setter]', 'special');
3867
- }
3868
- }
3869
- }
3870
- if (visibleKeys.indexOf(key) < 0) {
3871
- name = '[' + key + ']';
3872
- }
3873
- if (!str) {
3874
- if (ctx.seen.indexOf(value[key]) < 0) {
3875
- if (recurseTimes === null) {
3876
- str = formatValue(ctx, value[key], null);
3877
- } else {
3878
- str = formatValue(ctx, value[key], recurseTimes - 1);
3879
- }
3880
- if (str.indexOf('\n') > -1) {
3881
- if (array) {
3882
- str = str.split('\n').map(function(line) {
3883
- return ' ' + line;
3884
- }).join('\n').substr(2);
3885
- } else {
3886
- str = '\n' + str.split('\n').map(function(line) {
3887
- return ' ' + line;
3888
- }).join('\n');
3889
- }
3890
- }
3891
- } else {
3892
- str = ctx.stylize('[Circular]', 'special');
3893
- }
3894
- }
3895
- if (typeof name === 'undefined') {
3896
- if (array && key.match(/^\d+$/)) {
3897
- return str;
3898
- }
3899
- name = JSON.stringify('' + key);
3900
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
3901
- name = name.substr(1, name.length - 2);
3902
- name = ctx.stylize(name, 'name');
3903
- } else {
3904
- name = name.replace(/'/g, "\\'")
3905
- .replace(/\\"/g, '"')
3906
- .replace(/(^"|"$)/g, "'");
3907
- name = ctx.stylize(name, 'string');
3908
- }
3909
- }
3910
-
3911
- return name + ': ' + str;
3912
- }
3913
-
3914
-
3915
- function reduceToSingleString(output, base, braces) {
3916
- var numLinesEst = 0;
3917
- var length = output.reduce(function(prev, cur) {
3918
- numLinesEst++;
3919
- if (cur.indexOf('\n') >= 0) numLinesEst++;
3920
- return prev + cur.length + 1;
3921
- }, 0);
3922
-
3923
- if (length > 60) {
3924
- return braces[0] +
3925
- (base === '' ? '' : base + '\n ') +
3926
- ' ' +
3927
- output.join(',\n ') +
3928
- ' ' +
3929
- braces[1];
3930
- }
3931
-
3932
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
3933
- }
3934
-
3935
- function isArray(ar) {
3936
- return Array.isArray(ar) ||
3937
- (typeof ar === 'object' && objectToString(ar) === '[object Array]');
3938
- }
3939
-
3940
- function isRegExp(re) {
3941
- return typeof re === 'object' && objectToString(re) === '[object RegExp]';
3942
- }
3943
-
3944
- function isDate(d) {
3945
- return typeof d === 'object' && objectToString(d) === '[object Date]';
3946
- }
3947
-
3948
- function isError(e) {
3949
- return typeof e === 'object' && objectToString(e) === '[object Error]';
3950
- }
3951
-
3952
- function objectToString(o) {
3953
- return Object.prototype.toString.call(o);
3954
- }
3955
-
3956
- });
3957
- require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require, module){
3958
- /*!
3959
- * Chai - flag utility
3960
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3961
- * MIT Licensed
3962
- */
3963
-
3964
- /*!
3965
- * Module dependancies
3966
- */
3967
-
3968
- var inspect = require('./inspect');
3969
-
3970
- /**
3971
- * ### .objDisplay (object)
3972
- *
3973
- * Determines if an object or an array matches
3974
- * criteria to be inspected in-line for error
3975
- * messages or should be truncated.
3976
- *
3977
- * @param {Mixed} javascript object to inspect
3978
- * @name objDisplay
3979
- * @api public
3980
- */
3981
-
3982
- module.exports = function (obj) {
3983
- var str = inspect(obj)
3984
- , type = Object.prototype.toString.call(obj);
3985
-
3986
- if (str.length >= 40) {
3987
- if (type === '[object Function]') {
3988
- return !obj.name || obj.name === ''
3989
- ? '[Function]'
3990
- : '[Function: ' + obj.name + ']';
3991
- } else if (type === '[object Array]') {
3992
- return '[ Array(' + obj.length + ') ]';
3993
- } else if (type === '[object Object]') {
3994
- var keys = Object.keys(obj)
3995
- , kstr = keys.length > 2
3996
- ? keys.splice(0, 2).join(', ') + ', ...'
3997
- : keys.join(', ');
3998
- return '{ Object (' + kstr + ') }';
3999
- } else {
4000
- return str;
4001
- }
4002
- } else {
4003
- return str;
4004
- }
4005
- };
4006
-
4007
- });
4008
- require.register("chai/lib/chai/utils/overwriteMethod.js", function(exports, require, module){
4009
- /*!
4010
- * Chai - overwriteMethod utility
4011
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4012
- * MIT Licensed
4013
- */
4014
-
4015
- /**
4016
- * ### overwriteMethod (ctx, name, fn)
4017
- *
4018
- * Overwites an already existing method and provides
4019
- * access to previous function. Must return function
4020
- * to be used for name.
4021
- *
4022
- * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
4023
- * return function (str) {
4024
- * var obj = utils.flag(this, 'object');
4025
- * if (obj instanceof Foo) {
4026
- * new chai.Assertion(obj.value).to.equal(str);
4027
- * } else {
4028
- * _super.apply(this, arguments);
4029
- * }
4030
- * }
4031
- * });
4032
- *
4033
- * Can also be accessed directly from `chai.Assertion`.
4034
- *
4035
- * chai.Assertion.overwriteMethod('foo', fn);
4036
- *
4037
- * Then can be used as any other assertion.
4038
- *
4039
- * expect(myFoo).to.equal('bar');
4040
- *
4041
- * @param {Object} ctx object whose method is to be overwritten
4042
- * @param {String} name of method to overwrite
4043
- * @param {Function} method function that returns a function to be used for name
4044
- * @name overwriteMethod
4045
- * @api public
4046
- */
4047
-
4048
- module.exports = function (ctx, name, method) {
4049
- var _method = ctx[name]
4050
- , _super = function () { return this; };
4051
-
4052
- if (_method && 'function' === typeof _method)
4053
- _super = _method;
4054
-
4055
- ctx[name] = function () {
4056
- var result = method(_super).apply(this, arguments);
4057
- return result === undefined ? this : result;
4058
- }
4059
- };
4060
-
4061
- });
4062
- require.register("chai/lib/chai/utils/overwriteProperty.js", function(exports, require, module){
4063
- /*!
4064
- * Chai - overwriteProperty utility
4065
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4066
- * MIT Licensed
4067
- */
4068
-
4069
- /**
4070
- * ### overwriteProperty (ctx, name, fn)
4071
- *
4072
- * Overwites an already existing property getter and provides
4073
- * access to previous value. Must return function to use as getter.
4074
- *
4075
- * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
4076
- * return function () {
4077
- * var obj = utils.flag(this, 'object');
4078
- * if (obj instanceof Foo) {
4079
- * new chai.Assertion(obj.name).to.equal('bar');
4080
- * } else {
4081
- * _super.call(this);
4082
- * }
4083
- * }
4084
- * });
4085
- *
4086
- *
4087
- * Can also be accessed directly from `chai.Assertion`.
4088
- *
4089
- * chai.Assertion.overwriteProperty('foo', fn);
4090
- *
4091
- * Then can be used as any other assertion.
4092
- *
4093
- * expect(myFoo).to.be.ok;
4094
- *
4095
- * @param {Object} ctx object whose property is to be overwritten
4096
- * @param {String} name of property to overwrite
4097
- * @param {Function} getter function that returns a getter function to be used for name
4098
- * @name overwriteProperty
4099
- * @api public
4100
- */
4101
-
4102
- module.exports = function (ctx, name, getter) {
4103
- var _get = Object.getOwnPropertyDescriptor(ctx, name)
4104
- , _super = function () {};
4105
-
4106
- if (_get && 'function' === typeof _get.get)
4107
- _super = _get.get
4108
-
4109
- Object.defineProperty(ctx, name,
4110
- { get: function () {
4111
- var result = getter(_super).call(this);
4112
- return result === undefined ? this : result;
4113
- }
4114
- , configurable: true
4115
- });
4116
- };
4117
-
4118
- });
4119
- require.register("chai/lib/chai/utils/test.js", function(exports, require, module){
4120
- /*!
4121
- * Chai - test utility
4122
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4123
- * MIT Licensed
4124
- */
4125
-
4126
- /*!
4127
- * Module dependancies
4128
- */
4129
-
4130
- var flag = require('./flag');
4131
-
4132
- /**
4133
- * # test(object, expression)
4134
- *
4135
- * Test and object for expression.
4136
- *
4137
- * @param {Object} object (constructed Assertion)
4138
- * @param {Arguments} chai.Assertion.prototype.assert arguments
4139
- */
4140
-
4141
- module.exports = function (obj, args) {
4142
- var negate = flag(obj, 'negate')
4143
- , expr = args[0];
4144
- return negate ? !expr : expr;
4145
- };
4146
-
4147
- });
4148
- require.register("chai/lib/chai/utils/transferFlags.js", function(exports, require, module){
4149
- /*!
4150
- * Chai - transferFlags utility
4151
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4152
- * MIT Licensed
4153
- */
4154
-
4155
- /**
4156
- * ### transferFlags(assertion, object, includeAll = true)
4157
- *
4158
- * Transfer all the flags for `assertion` to `object`. If
4159
- * `includeAll` is set to `false`, then the base Chai
4160
- * assertion flags (namely `object`, `ssfi`, and `message`)
4161
- * will not be transferred.
4162
- *
4163
- *
4164
- * var newAssertion = new Assertion();
4165
- * utils.transferFlags(assertion, newAssertion);
4166
- *
4167
- * var anotherAsseriton = new Assertion(myObj);
4168
- * utils.transferFlags(assertion, anotherAssertion, false);
4169
- *
4170
- * @param {Assertion} assertion the assertion to transfer the flags from
4171
- * @param {Object} object the object to transfer the flags too; usually a new assertion
4172
- * @param {Boolean} includeAll
4173
- * @name getAllFlags
4174
- * @api private
4175
- */
4176
-
4177
- module.exports = function (assertion, object, includeAll) {
4178
- var flags = assertion.__flags || (assertion.__flags = Object.create(null));
4179
-
4180
- if (!object.__flags) {
4181
- object.__flags = Object.create(null);
4182
- }
4183
-
4184
- includeAll = arguments.length === 3 ? includeAll : true;
4185
-
4186
- for (var flag in flags) {
4187
- if (includeAll ||
4188
- (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
4189
- object.__flags[flag] = flags[flag];
4190
- }
4191
- }
4192
- };
4193
-
4194
- });
4195
- require.register("chai/lib/chai/utils/type.js", function(exports, require, module){
4196
- /*!
4197
- * Chai - type utility
4198
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
4199
- * MIT Licensed
4200
- */
4201
-
4202
- /*!
4203
- * Detectable javascript natives
4204
- */
4205
-
4206
- var natives = {
4207
- '[object Arguments]': 'arguments'
4208
- , '[object Array]': 'array'
4209
- , '[object Date]': 'date'
4210
- , '[object Function]': 'function'
4211
- , '[object Number]': 'number'
4212
- , '[object RegExp]': 'regexp'
4213
- , '[object String]': 'string'
4214
- };
4215
-
4216
- /**
4217
- * ### type(object)
4218
- *
4219
- * Better implementation of `typeof` detection that can
4220
- * be used cross-browser. Handles the inconsistencies of
4221
- * Array, `null`, and `undefined` detection.
4222
- *
4223
- * utils.type({}) // 'object'
4224
- * utils.type(null) // `null'
4225
- * utils.type(undefined) // `undefined`
4226
- * utils.type([]) // `array`
4227
- *
4228
- * @param {Mixed} object to detect type of
4229
- * @name type
4230
- * @api private
4231
- */
4232
-
4233
- module.exports = function (obj) {
4234
- var str = Object.prototype.toString.call(obj);
4235
- if (natives[str]) return natives[str];
4236
- if (obj === null) return 'null';
4237
- if (obj === undefined) return 'undefined';
4238
- if (obj === Object(obj)) return 'object';
4239
- return typeof obj;
4240
- };
4241
-
4242
- });
4243
- require.alias("chai/index.js", "chai/index.js");
4244
-
4245
- if (typeof exports == "object") {
4246
- module.exports = require("chai");
4247
- } else if (typeof define == "function" && define.amd) {
4248
- define(function(){ return require("chai"); });
4249
- } else {
4250
- this["chai"] = require("chai");
4251
- }})();