Update original to use jQuery.ajax instead of jasmine.XmlHttpRequest. It should play better with jasmine 2.0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uniqueLoadIndicator = null; | |
// Loads fixure markup into the DOM as a child of the jasmine_content div | |
spec.loadFixture = function(fixtureName) { | |
var $destination = $('#jasmine_content'); | |
uniqueLoadIndicator = null; | |
var indicatorScript = "<script>uniqueLoadIndicator = 'loaded';</s" + "cript>"; | |
// get the markup, inject it into the dom | |
$destination.html(spec.fixtureHtml(fixtureName) + indicatorScript); | |
while (uniqueLoadIndicator != "loaded") { | |
// | |
if (console) console.log("Browser wasn't ready... sleeping."); | |
spec.retrieveFixture(fixtureName); | |
} | |
uniqueLoadIndicator = null; | |
// keep track of fixture count to fail specs that | |
// call loadFixture() more than once | |
spec.loadFixtureCount++; | |
}; | |
// Returns fixture markup as a string. Useful for fixtures that | |
// represent the response text of ajax requests. | |
spec.readFixture = function(fixtureName) { | |
return spec.fixtureHtml(fixtureName); | |
}; | |
spec.readJSON = function(fixtureName) { | |
var data = spec.fixtureHtml(fixtureName); | |
return window.JSON && window.JSON.parse ? | |
window.JSON.parse( data ) : | |
(new Function("return " + data))(); | |
}; | |
spec.fixtureHtml = function(fixtureName) { | |
if (!spec.cachedFixtures[fixtureName]) { | |
spec.cachedFixtures[fixtureName] = spec.retrieveFixture(fixtureName); | |
} | |
return spec.cachedFixtures[fixtureName]; | |
}; | |
spec.retrieveFixture = function(fixtureName) { | |
// construct a path to the fixture, including a cache-busting timestamp | |
var path = '/spec/javascripts/fixtures/' + fixtureName + "?" + new Date().getTime(); | |
var responseText; | |
// retrieve the fixture markup via xhr request to jasmine server | |
try { | |
$.ajax(path, { | |
dataType: "html", | |
complete: function(xhr, status) { | |
responseText = xhr.responseText; | |
}, | |
error: function(xhr, status, error) { | |
throw new Error("Couldn't load fixture with key: '" + fixtureName + "'. No such file: '" + path + "'."); | |
} | |
}); | |
} catch(e) { | |
throw new Error("couldn't fetch " + path + ": " + e); | |
} | |
return responseText; | |
}; | |
spec.loadFixtureCount = 0; | |
spec.cachedFixtures = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment