Skip to content

Instantly share code, notes, and snippets.

@wireframe
Created June 23, 2011 16:29
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 wireframe/1042920 to your computer and use it in GitHub Desktop.
Save wireframe/1042920 to your computer and use it in GitHub Desktop.
be_lintable.rb
require 'jslint'
# "var someJsExpresion = 'stuff';".should be_lintable
RSpec::Matchers.define :be_lintable do |expected|
match do |actual|
tmp_js_output_dir = Rails.root.join('tmp', 'js_lintable')
FileUtils.mkdir_p tmp_js_output_dir unless File.exists?(tmp_js_output_dir)
tmp_js_output = File.join(tmp_js_output_dir, 'output.js')
File.open(tmp_js_output, 'w') do |file|
file.puts(actual)
end
lint = JSLint::Lint.new(
:paths => [tmp_js_output],
:config_path => Rails.root.join('config', 'jslint.yml')
)
lint.run #raises LintCheckFailure if failure
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment