Created
November 18, 2012 00:41
-
-
Save gsmaverick/4102057 to your computer and use it in GitHub Desktop.
Spec filtering for Jasmine
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
/** | |
* 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