Created
August 29, 2012 17:42
-
-
Save ngauthier/3516080 to your computer and use it in GitHub Desktop.
jslint via capybara-webkit
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
require 'test_helper' | |
class JslintTest < ActionDispatch::IntegrationTest | |
include ActionView::Helpers::JavaScriptHelper | |
['file1', 'file2', 'file3'].each do |path| | |
path.gsub!(/^app\/assets\/javascripts\//, "") | |
path += '.js' | |
test "JSLINT #{path}" do | |
assert_jslint(path) | |
end | |
end | |
private | |
def assert_jslint(path) | |
path = "/assets/#{path}" | |
options = { | |
white: true, | |
undef: true, | |
sloppy: true, | |
vars: true, | |
nomen: true, | |
newcap: true, | |
maxerr: 20 | |
} | |
jslint = File.read(Rails.root.join(*%w(vendor assets javascripts jslint.js))) | |
visit path | |
doc = Nokogiri::HTML(page.body) | |
source = doc.css('pre').first.content | |
visit 'about:blank' | |
page.execute_script jslint | |
if !page.evaluate_script %{JSLINT("#{escape_javascript source}", #{options.to_json})} | |
page.evaluate_script(%{JSLINT.errors}).each do |error| | |
puts %{\n#{path}:#{error['line']}@#{error['character']}: #{error['reason']}\n#{error['evidence']}} | |
end | |
flunk 'JSLINT Errors' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment