Created
February 20, 2011 10:40
-
-
Save kavu/835882 to your computer and use it in GitHub Desktop.
Jasmine + JSLint
This file contains hidden or 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
| /* | |
| Original code: | |
| https://github.com/brandon/lucid/blob/master/spec/javascripts/z_jshint_spec.js | |
| */ | |
| describe('JSHint', function () { | |
| var options = {curly: true, white: true, indent: 2}, | |
| files = /^\/src|.*spec\.js$/; | |
| function get(path) { | |
| path = path + "?" + new Date().getTime(); | |
| var xhr; | |
| try { | |
| xhr = new jasmine.XmlHttpRequest(); | |
| xhr.open("GET", path, false); | |
| xhr.send(null); | |
| } catch (e) { | |
| throw new Error("couldn't fetch " + path + ": " + e); | |
| } | |
| if (xhr.status < 200 || xhr.status > 299) { | |
| throw new Error("Could not load '" + path + "'."); | |
| } | |
| return xhr.responseText; | |
| } | |
| _.each(document.getElementsByTagName('script'), function (element) { | |
| var script = element.getAttribute('src'); | |
| if (!files.test(script)) { | |
| return; | |
| } | |
| it(script, function () { | |
| var self = this; | |
| var source = get(script); | |
| var result = JSHINT(source, options); | |
| _.each(JSHINT.errors, function (error) { | |
| self.addMatcherResult(new jasmine.ExpectationResult({ | |
| passed: false, | |
| message: "line " + error.line + ' - ' + error.reason + ' - ' + error.evidence | |
| })); | |
| }); | |
| expect(true).toBe(true); // force spec to show up if there are no errors | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment