Skip to content

Instantly share code, notes, and snippets.

@brentkirby
Created September 8, 2012 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentkirby/3680646 to your computer and use it in GitHub Desktop.
Save brentkirby/3680646 to your computer and use it in GitHub Desktop.
Run raw coffeescript specs in browser with jasmine
/*
* Make sure coffeescript.js, jasmine, and all other dependencies are loaded,
* then assign a global "specs" variable which is an array of file names in
* your spec/ folder.
*
* window.specs = ['index'];
*
*/
(function() {
var jasmineEnv, htmlReporter, loaded, ran = false;
loaded = [];
jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
window.onload = loadSpecs;
function loadSpecs(){
jQuery.each(specs, function(ind, file){
var toload = "spec/" + file + "_spec.coffee";
if( loaded.indexOf(toload) == -1 ){
loaded.push(toload);
CoffeeScript.load(toload, finish);
}
});
}
function finish(){
if( loaded.length == specs.length )
runem();
}
function runem(){
if( ran == true ) return;
ran = true;
// without a slight delay, jasmine will error for some reason.
setTimeout(function(){
jasmineEnv.execute();
}, 200);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment