desc 'Custom cruise task for RSpec' task :cruise do ENV['RAILS_ENV'] = 'test' if File.exists?(Dir.pwd + "/config/database.yml") if Dir[Dir.pwd + "/db/migrate/*.rb"].empty? raise "No migration scripts found in db/migrate/ but database.yml exists, " + "CruiseControl won't be able to build the latest test database. Build aborted." end # perform standard Rails database cleanup/preparation tasks if they are defined in project # this is necessary because there is no up-to-date development database on a continuous integration box if Rake.application.lookup('db:test:purge') CruiseControl::invoke_rake_task 'db:test:purge' end if Rake.application.lookup('db:bootstrap') CruiseControl::reconnect CruiseControl::invoke_rake_task 'db:bootstrap' end end # syntax check puts "="*10 + "SYNTAX CHECK" + "="*10 CruiseControl::invoke_rake_task 'test_tasks:check_syntax' # Rspec puts "="*10 + "RSPEC" + "="*10 CruiseControl::invoke_rake_task 'spec' # code quality puts "="*10 + "CODE QUALITY" + "="*10 CruiseControl::invoke_rake_task 'test_tasks:check_code_quality' end namespace :test_tasks do require 'erb' require 'open3' require 'yaml' task :check_syntax => [:check_ruby, :check_erb, :check_yaml] task :check_erb do (Dir["**/*.erb"] + Dir["**/*.rhtml"]).each do |file| next if file.match("vendor/rails") Open3.popen3('ruby -c') do |stdin, stdout, stderr| stdin.puts(ERB.new(File.read(file), nil, '-').src) stdin.close if error = ((stderr.readline rescue false)) puts file + error[1..-1] end stdout.close rescue false stderr.close rescue false end end puts "Erb syntax Ok" end task :check_ruby do Dir['**/*.rb'].each do |file| next if file.match("vendor/rails") next if file.match("vendor/plugins/.*/generators/.*/templates") Open3.popen3("ruby -c #{file}") do |stdin, stdout, stderr| if error = ((stderr.readline rescue false)) puts error end stdin.close rescue false stdout.close rescue false stderr.close rescue false end end puts "Ruby syntax Ok" end task :check_yaml do Dir['**/*.yml'].each do |file| next if file.match("vendor/rails") begin YAML.load_file(file) rescue => e puts "#{file}:#{(e.message.match(/on line (\d+)/)[1] + ':') rescue nil} #{e.message}" end end puts "Yaml syntax Ok" end desc "Check the quality of our /app code against some metrics" task :check_code_quality => :environment do exec "roodi", "'#{File.join(RAILS_ROOT,'app','**','*.rb')}'" end end