lib/jspec.js in jspec-2.11.5 vs lib/jspec.js in jspec-2.11.6
- old
+ new
@@ -3,11 +3,11 @@
(function(){
JSpec = {
- version : '2.11.5',
+ version : '2.11.6',
cache : {},
suites : [],
modules : [],
allSuites : [],
matchers : {},
@@ -141,11 +141,11 @@
function bodyContents(body) {
return JSpec.
escape(JSpec.contentsOf(body)).
replace(/^ */gm, function(a){ return (new Array(Math.round(a.length / 3))).join(' ') }).
- replace("\n", '<br/>')
+ replace(/\r\n|\r|\n/gm, '<br/>')
}
report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \
<span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \
<span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \
@@ -724,18 +724,13 @@
* @return {mixed}
* @api private
*/
evalHook : function(module, name, args) {
- var context = this.context || this.defaultContext
- var contents = this.contentsOf(module[name])
- var params = this.paramsFor(module[name])
- module.utilities = module.utilities || {}
- params.unshift('context'); args.unshift(context)
- hook('evaluatingHookBody', module, name, context)
- try { return new Function(params.join(), 'with (this.utilities) { with (context) { with (JSpec) { ' + contents + ' }}}').apply(module, args) }
- catch(e) { error('Error in hook ' + module.name + "." + name + ': ', e) }
+ hook('evaluatingHookBody', module, name)
+ try { return module[name].apply(module, args) }
+ catch(e) { error('Error in hook ' + module.name + '.' + name + ': ', e) }
},
/**
* Same as hook() however accepts only one _arg_ which is
* considered immutable. This function passes the arg
@@ -1309,22 +1304,10 @@
*/
contentsOf : function(body) {
return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]
},
-
- /**
- * Return param names for a function body.
- *
- * @param {function} body
- * @return {array}
- * @api public
- */
-
- paramsFor : function(body) {
- return body.toString().match(/\((.*?)\)/)[1].match(/[\w]+/g) || []
- },
/**
* Evaluate a JSpec capture body.
*
* @param {function} body
@@ -1547,19 +1530,40 @@
},
/**
* Instantiate an XMLHttpRequest.
*
+ * Here we utilize IE's lame ActiveXObjects first which
+ * allow IE access serve files via the file: protocol, otherwise
+ * we then default to XMLHttpRequest.
+ *
* @return {XMLHttpRequest, ActiveXObject}
* @api private
*/
xhr : function() {
- return new (JSpec.request || ActiveXObject("Microsoft.XMLHTTP"))
+ return this.ieXhr() || new JSpec.request
},
/**
+ * Return Microsoft piece of crap ActiveXObject.
+ *
+ * @return {ActiveXObject}
+ * @api public
+ */
+
+ ieXhr : function() {
+ function object(str) {
+ try { return new ActiveXObject(str) } catch(e) {}
+ }
+ return object('Msxml2.XMLHTTP.6.0') ||
+ object('Msxml2.XMLHTTP.3.0') ||
+ object('Msxml2.XMLHTTP') ||
+ object('Microsoft.XMLHTTP')
+ },
+
+ /**
* Check for HTTP request support.
*
* @return {bool}
* @api private
*/
@@ -1599,10 +1603,10 @@
var request = this.xhr()
request.open('GET', file, false)
request.send(null)
if (request.readyState == 4 &&
(request.status == 0 ||
- parseInt(request.status.toString()[0]) == 2))
+ request.status.toString().charAt(0) == 2))
return request.responseText
}
else
error("failed to load `" + file + "'")
},
\ No newline at end of file