Skip to content

Commit cbd8ce2

Browse files
committed
1 parent 53edb20 commit cbd8ce2

File tree

6 files changed

+60
-35
lines changed

6 files changed

+60
-35
lines changed

expect/Gruntfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ module.exports = function(grunt) {
1313
header: 'define(function(require, exports, module) {',
1414
footer: '});'
1515
},
16-
url: 'https://raw.github.com/LearnBoost/expect.js/<%= pkg.version %>/expect.js',
16+
url: 'https://raw.github.com/LearnBoost/expect.js/<%= pkg.version %>/index.js',
1717
name: 'expect.js'
1818
}
1919
}
2020
});
2121

22-
require('grunt-spm-build').initConfig(grunt, {pkg: pkg});
23-
grunt.loadGlobalTasks('grunt-spm-build');
22+
grunt.loadGlobalTasks('spm-build');
23+
grunt.util._.merge(grunt.config.data, require('spm-build').config);
2424

2525
grunt.loadTasks('../_tasks/download/tasks');
2626
grunt.registerTask('build', ['download', 'spm-build']);

expect/dist/expect-debug.js

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, module) {
1+
define("gallery/expect/0.3.1/expect-debug", [], function(require, exports, module) {
22
(function(global, module) {
3-
if ("undefined" == typeof module) {
4-
var module = {
5-
exports: {}
6-
}, exports = module.exports;
7-
}
3+
var exports = module.exports;
84
/**
95
* Exports.
106
*/
@@ -13,7 +9,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
139
/**
1410
* Exports version.
1511
*/
16-
expect.version = "0.1.2";
12+
expect.version = "0.3.1";
1713
/**
1814
* Possible assertion flags.
1915
*/
@@ -71,10 +67,16 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
7167
*
7268
* @api private
7369
*/
74-
Assertion.prototype.assert = function(truth, msg, error) {
75-
var msg = this.flags.not ? error : msg, ok = this.flags.not ? !truth : truth;
70+
Assertion.prototype.assert = function(truth, msg, error, expected) {
71+
var msg = this.flags.not ? error : msg, ok = this.flags.not ? !truth : truth, err;
7672
if (!ok) {
77-
throw new Error(msg.call(this));
73+
err = new Error(msg.call(this));
74+
if (arguments.length > 3) {
75+
err.actual = this.obj;
76+
err.expected = expected;
77+
err.showDiff = true;
78+
}
79+
throw err;
7880
}
7981
this.and = new Assertion(this.obj);
8082
};
@@ -91,6 +93,19 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
9193
});
9294
};
9395
/**
96+
* Creates an anonymous function which calls fn with arguments.
97+
*
98+
* @api public
99+
*/
100+
Assertion.prototype.withArgs = function() {
101+
expect(this.obj).to.be.a("function");
102+
var fn = this.obj;
103+
var args = Array.prototype.slice.call(arguments);
104+
return expect(function() {
105+
fn.apply(null, args);
106+
});
107+
};
108+
/**
94109
* Assert that the function throws.
95110
*
96111
* @param {Function|RegExp} callback, or regexp to match error string against
@@ -102,19 +117,19 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
102117
try {
103118
this.obj();
104119
} catch (e) {
105-
if ("function" == typeof fn) {
106-
fn(e);
107-
} else if ("object" == typeof fn) {
120+
if (isRegExp(fn)) {
108121
var subject = "string" == typeof e ? e : e.message;
109122
if (not) {
110123
expect(subject).to.not.match(fn);
111124
} else {
112125
expect(subject).to.match(fn);
113126
}
127+
} else if ("function" == typeof fn) {
128+
fn(e);
114129
}
115130
thrown = true;
116131
}
117-
if ("object" == typeof fn && not) {
132+
if (isRegExp(fn) && not) {
118133
// in the presence of a matcher, ensure the `not` only applies to
119134
// the matching.
120135
this.flags.not = false;
@@ -172,11 +187,11 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
172187
* @api public
173188
*/
174189
Assertion.prototype.eql = function(obj) {
175-
this.assert(expect.eql(obj, this.obj), function() {
190+
this.assert(expect.eql(this.obj, obj), function() {
176191
return "expected " + i(this.obj) + " to sort of equal " + i(obj);
177192
}, function() {
178193
return "expected " + i(this.obj) + " to sort of not equal " + i(obj);
179-
});
194+
}, obj);
180195
return this;
181196
};
182197
/**
@@ -205,7 +220,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
205220
// proper english in error msg
206221
var n = /^[aeiou]/.test(type) ? "n" : "";
207222
// typeof with support for 'array'
208-
this.assert("array" == type ? isArray(this.obj) : "object" == type ? "object" == typeof this.obj && null !== this.obj : type == typeof this.obj, function() {
223+
this.assert("array" == type ? isArray(this.obj) : "regexp" == type ? isRegExp(this.obj) : "object" == type ? "object" == typeof this.obj && null !== this.obj : type == typeof this.obj, function() {
209224
return "expected " + i(this.obj) + " to be a" + n + " " + type;
210225
}, function() {
211226
return "expected " + i(this.obj) + " not to be a" + n + " " + type;
@@ -393,8 +408,10 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
393408
* @api public
394409
*/
395410
Assertion.prototype.fail = function(msg) {
396-
msg = msg || "explicit failure";
397-
this.assert(false, msg, msg);
411+
var error = function() {
412+
return msg || "explicit failure";
413+
};
414+
this.assert(false, error, error);
398415
return this;
399416
};
400417
/**
@@ -441,7 +458,6 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
441458
if ("outerHTML" in element) return element.outerHTML;
442459
var ns = "http://www.w3.org/1999/xhtml";
443460
var container = document.createElementNS(ns, "_");
444-
var elemProto = (window.HTMLElement || window.Element).prototype;
445461
var xmlSerializer = new XMLSerializer();
446462
var html;
447463
if (document.xmlVersion) {
@@ -518,6 +534,10 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
518534
if (isDate(value) && $keys.length === 0) {
519535
return stylize(value.toUTCString(), "date");
520536
}
537+
// Error objects can be shortcutted
538+
if (value instanceof Error) {
539+
return stylize("[" + value.toString() + "]", "Error");
540+
}
521541
var base, type, braces;
522542
// Determine the object type
523543
if (isArray(value)) {
@@ -620,8 +640,9 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
620640
}
621641
return format(obj, typeof depth === "undefined" ? 2 : depth);
622642
}
643+
expect.stringify = i;
623644
function isArray(ar) {
624-
return Object.prototype.toString.call(ar) == "[object Array]";
645+
return Object.prototype.toString.call(ar) === "[object Array]";
625646
}
626647
function isRegExp(re) {
627648
var s;
@@ -635,8 +656,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
635656
typeof re === "function" && re.constructor.name === "RegExp" && re.compile && re.test && re.exec && s.match(/^\/.*\/[gim]{0,3}$/);
636657
}
637658
function isDate(d) {
638-
if (d instanceof Date) return true;
639-
return false;
659+
return d instanceof Date;
640660
}
641661
function keys(obj) {
642662
if (Object.keys) {
@@ -704,6 +724,8 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
704724
return actual.getTime() === expected.getTime();
705725
} else if (typeof actual != "object" && typeof expected != "object") {
706726
return actual == expected;
727+
} else if (isRegExp(actual) && isRegExp(expected)) {
728+
return regExpEquiv(actual, expected);
707729
} else {
708730
return objEquiv(actual, expected);
709731
}
@@ -714,6 +736,9 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
714736
function isArguments(object) {
715737
return Object.prototype.toString.call(object) == "[object Arguments]";
716738
}
739+
function regExpEquiv(a, b) {
740+
return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline;
741+
}
717742
function objEquiv(a, b) {
718743
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return false;
719744
// an identical "prototype" property.
@@ -969,5 +994,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
969994
if ("undefined" != typeof window) {
970995
window.expect = module.exports;
971996
}
972-
})(this, "undefined" != typeof module ? module : {}, "undefined" != typeof exports ? exports : {});
973-
});
997+
})(this, "undefined" != typeof module ? module : {
998+
exports: {}
999+
});
1000+
});

0 commit comments

Comments
 (0)