lib/jspec.js in visionmedia-jspec-2.8.1 vs lib/jspec.js in visionmedia-jspec-2.8.2
- old
+ new
@@ -3,17 +3,18 @@
(function(){
JSpec = {
- version : '2.8.1',
+ version : '2.8.2',
cache : {},
suites : [],
modules : [],
allSuites : [],
matchers : {},
stubbed : [],
+ request : 'XMLHttpRequest' in this ? XMLHttpRequest : null,
stats : { specs : 0, assertions : 0, failures : 0, passes : 0, specsFinished : 0, suitesFinished : 0 },
options : { profile : false },
/**
* Default context in which bodies are evaluated.
@@ -65,21 +66,17 @@
* @api public
*/
fixture : function(path) {
if (JSpec.cache[path]) return JSpec.cache[path]
- function tryLoading(path) {
- try { return JSpec.load(path) }
- catch (e) {}
- }
return JSpec.cache[path] =
- tryLoading(path) ||
- tryLoading('fixtures/' + path) ||
- tryLoading('fixtures/' + path + '.html') ||
- tryLoading('spec/' + path) ||
- tryLoading('spec/fixtures/' + path) ||
- tryLoading('spec/fixtures/' + path + '.html')
+ JSpec.tryLoading(path) ||
+ JSpec.tryLoading('fixtures/' + path) ||
+ JSpec.tryLoading('fixtures/' + path + '.html') ||
+ JSpec.tryLoading('spec/' + path) ||
+ JSpec.tryLoading('spec/fixtures/' + path) ||
+ JSpec.tryLoading('spec/fixtures/' + path + '.html')
}
},
// --- Objects
@@ -1464,28 +1461,40 @@
},
/**
* Instantiate an XMLHttpRequest.
*
- * @return {ActiveXObject, XMLHttpRequest}
+ * @return {XMLHttpRequest, ActiveXObject}
* @api private
*/
xhr : function() {
- return 'XMLHttpRequest' in main ?
- new XMLHttpRequest:
- new ActiveXObject("Microsoft.XMLHTTP")
+ return new (JSpec.request || ActiveXObject("Microsoft.XMLHTTP"))
},
/**
* Check for HTTP request support.
*
* @return {bool}
* @api private
*/
hasXhr : function() {
- return 'XMLHttpRequest' in main || 'ActiveXObject' in main
+ return JSpec.request || 'ActiveXObject' in main
+ },
+
+ /**
+ * Try loading _file_ returning the contents
+ * string or null. Chain to locate / read a file.
+ *
+ * @param {string} file
+ * @return {string}
+ * @api public
+ */
+
+ tryLoading : function(file) {
+ try { return JSpec.load(file) }
+ catch (e) {}
},
/**
* Load a _file_'s contents.
*
\ No newline at end of file