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 ) {
2
2
( function ( global , module ) {
3
- if ( "undefined" == typeof module ) {
4
- var module = {
5
- exports : { }
6
- } , exports = module . exports ;
7
- }
3
+ var exports = module . exports ;
8
4
/**
9
5
* Exports.
10
6
*/
@@ -13,7 +9,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
13
9
/**
14
10
* Exports version.
15
11
*/
16
- expect . version = "0.1.2 " ;
12
+ expect . version = "0.3.1 " ;
17
13
/**
18
14
* Possible assertion flags.
19
15
*/
@@ -71,10 +67,16 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
71
67
*
72
68
* @api private
73
69
*/
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 ;
76
72
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 ;
78
80
}
79
81
this . and = new Assertion ( this . obj ) ;
80
82
} ;
@@ -91,6 +93,19 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
91
93
} ) ;
92
94
} ;
93
95
/**
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
+ /**
94
109
* Assert that the function throws.
95
110
*
96
111
* @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
102
117
try {
103
118
this . obj ( ) ;
104
119
} catch ( e ) {
105
- if ( "function" == typeof fn ) {
106
- fn ( e ) ;
107
- } else if ( "object" == typeof fn ) {
120
+ if ( isRegExp ( fn ) ) {
108
121
var subject = "string" == typeof e ? e : e . message ;
109
122
if ( not ) {
110
123
expect ( subject ) . to . not . match ( fn ) ;
111
124
} else {
112
125
expect ( subject ) . to . match ( fn ) ;
113
126
}
127
+ } else if ( "function" == typeof fn ) {
128
+ fn ( e ) ;
114
129
}
115
130
thrown = true ;
116
131
}
117
- if ( "object" == typeof fn && not ) {
132
+ if ( isRegExp ( fn ) && not ) {
118
133
// in the presence of a matcher, ensure the `not` only applies to
119
134
// the matching.
120
135
this . flags . not = false ;
@@ -172,11 +187,11 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
172
187
* @api public
173
188
*/
174
189
Assertion . prototype . eql = function ( obj ) {
175
- this . assert ( expect . eql ( obj , this . obj ) , function ( ) {
190
+ this . assert ( expect . eql ( this . obj , obj ) , function ( ) {
176
191
return "expected " + i ( this . obj ) + " to sort of equal " + i ( obj ) ;
177
192
} , function ( ) {
178
193
return "expected " + i ( this . obj ) + " to sort of not equal " + i ( obj ) ;
179
- } ) ;
194
+ } , obj ) ;
180
195
return this ;
181
196
} ;
182
197
/**
@@ -205,7 +220,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
205
220
// proper english in error msg
206
221
var n = / ^ [ a e i o u ] / . test ( type ) ? "n" : "" ;
207
222
// 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 ( ) {
209
224
return "expected " + i ( this . obj ) + " to be a" + n + " " + type ;
210
225
} , function ( ) {
211
226
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
393
408
* @api public
394
409
*/
395
410
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 ) ;
398
415
return this ;
399
416
} ;
400
417
/**
@@ -441,7 +458,6 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
441
458
if ( "outerHTML" in element ) return element . outerHTML ;
442
459
var ns = "http://www.w3.org/1999/xhtml" ;
443
460
var container = document . createElementNS ( ns , "_" ) ;
444
- var elemProto = ( window . HTMLElement || window . Element ) . prototype ;
445
461
var xmlSerializer = new XMLSerializer ( ) ;
446
462
var html ;
447
463
if ( document . xmlVersion ) {
@@ -518,6 +534,10 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
518
534
if ( isDate ( value ) && $keys . length === 0 ) {
519
535
return stylize ( value . toUTCString ( ) , "date" ) ;
520
536
}
537
+ // Error objects can be shortcutted
538
+ if ( value instanceof Error ) {
539
+ return stylize ( "[" + value . toString ( ) + "]" , "Error" ) ;
540
+ }
521
541
var base , type , braces ;
522
542
// Determine the object type
523
543
if ( isArray ( value ) ) {
@@ -620,8 +640,9 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
620
640
}
621
641
return format ( obj , typeof depth === "undefined" ? 2 : depth ) ;
622
642
}
643
+ expect . stringify = i ;
623
644
function isArray ( ar ) {
624
- return Object . prototype . toString . call ( ar ) == "[object Array]" ;
645
+ return Object . prototype . toString . call ( ar ) === "[object Array]" ;
625
646
}
626
647
function isRegExp ( re ) {
627
648
var s ;
@@ -635,8 +656,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
635
656
typeof re === "function" && re . constructor . name === "RegExp" && re . compile && re . test && re . exec && s . match ( / ^ \/ .* \/ [ g i m ] { 0 , 3 } $ / ) ;
636
657
}
637
658
function isDate ( d ) {
638
- if ( d instanceof Date ) return true ;
639
- return false ;
659
+ return d instanceof Date ;
640
660
}
641
661
function keys ( obj ) {
642
662
if ( Object . keys ) {
@@ -704,6 +724,8 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
704
724
return actual . getTime ( ) === expected . getTime ( ) ;
705
725
} else if ( typeof actual != "object" && typeof expected != "object" ) {
706
726
return actual == expected ;
727
+ } else if ( isRegExp ( actual ) && isRegExp ( expected ) ) {
728
+ return regExpEquiv ( actual , expected ) ;
707
729
} else {
708
730
return objEquiv ( actual , expected ) ;
709
731
}
@@ -714,6 +736,9 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
714
736
function isArguments ( object ) {
715
737
return Object . prototype . toString . call ( object ) == "[object Arguments]" ;
716
738
}
739
+ function regExpEquiv ( a , b ) {
740
+ return a . source === b . source && a . global === b . global && a . ignoreCase === b . ignoreCase && a . multiline === b . multiline ;
741
+ }
717
742
function objEquiv ( a , b ) {
718
743
if ( isUndefinedOrNull ( a ) || isUndefinedOrNull ( b ) ) return false ;
719
744
// an identical "prototype" property.
@@ -969,5 +994,7 @@ define("gallery/expect/0.2.0/expect-debug", [], function(require, exports, modul
969
994
if ( "undefined" != typeof window ) {
970
995
window . expect = module . exports ;
971
996
}
972
- } ) ( this , "undefined" != typeof module ? module : { } , "undefined" != typeof exports ? exports : { } ) ;
973
- } ) ;
997
+ } ) ( this , "undefined" != typeof module ? module : {
998
+ exports : { }
999
+ } ) ;
1000
+ } ) ;
0 commit comments