Skip to content

Instantly share code, notes, and snippets.

@madsheep
Created April 20, 2012 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madsheep/2427320 to your computer and use it in GitHub Desktop.
Save madsheep/2427320 to your computer and use it in GitHub Desktop.
Syntax tests
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