Created
June 23, 2011 16:29
-
-
Save wireframe/1042920 to your computer and use it in GitHub Desktop.
be_lintable.rb
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 '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