Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created August 29, 2012 17:42
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 ngauthier/3516080 to your computer and use it in GitHub Desktop.
Save ngauthier/3516080 to your computer and use it in GitHub Desktop.
jslint via capybara-webkit
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