Created
April 20, 2012 09:26
-
-
Save madsheep/2427320 to your computer and use it in GitHub Desktop.
Syntax tests
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
feature "correct syntax in project" do | |
scenario "validate coffeescript files for errors" do | |
Dir["#{Rails.root}/**/*.coffee"].each do |file| | |
%x[coffee --lint -p #{file} ] | |
$?.success?.should be_true | |
end | |
end | |
scenario "validate haml files" do | |
Dir["#{Rails.root}/**/*.haml"].each do |file| | |
next if file.match("vendor") | |
begin | |
error = false | |
Haml::Engine.new(File.read(file)) | |
rescue => e | |
error = "Haml syntax error in #{file}: #{e.message}" | |
end | |
error.should == false | |
end | |
end | |
scenario "validate yaml files" do | |
Dir["#{Rails.root}/**/*.yml"].each do |file| | |
next if file.match("vendor") | |
begin | |
error = false | |
YAML.load_file(file) | |
rescue => e | |
error = "Yaml syntax error in #{file}:#{(e.message.match(/on line (\d+)/)[1] + ':') rescue nil} #{e.message}" | |
end | |
error.should == false | |
end | |
end | |
scenario "validate ruby and rake files" do | |
Dir["#{Rails.root}/**/*.rb", "#{Rails.root}/**/*.rake"].each do |file| | |
next if file.match("vendor") | |
error = lambda { | |
begin | |
eval("BEGIN { return false }\n#{File.open(file).read}", nil, file, 0) | |
rescue SyntaxError => e | |
e.message | |
end | |
}.call | |
error.should == false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment