Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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