Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gsmaverick
Created November 18, 2012 00:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsmaverick/4102057 to your computer and use it in GitHub Desktop.
Save gsmaverick/4102057 to your computer and use it in GitHub Desktop.
Spec filtering for Jasmine
/**
* Determines if the given jasmine spec should run based on whether it's highest
* level suite desciption match the value of the runMatch parameter in the url.
*
* @param {Spec} spec Jasmine spec object that is about to be executed.
*
* @returns {Boolean} True if spec should run, false if it should be skipped.
*/
var specFilter = function(spec){
/**
* @param {String} name Key of the value to be retrieved from the url.
*
* @returns {Object} Value of the requested key or undefined if the key does
* not exist in the url.
*/
var getQueryParam = function(name){
var pairs = window.location.search.slice(1).split('&');
for (key in pairs){
var arr = pairs[key].split('=');
if (arr[0] === name)
return decodeURIComponent(arr[1].replace(/\+/g, " "));
}
}
var val = getQueryParam('runMatch') || '';
// Find the outermost suite this spec belongs to.
var suite = spec.suite;
while (suite.parentSuite) suite = suite.parentSuite;
return suite.description.toLowerCase().indexOf(val.toLowerCase()) !== -1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment