cruise.rake

Tagged with Ruby Rails cruisecontrol rake

Language: Ruby

View as text

require 'hpricot'

desc "CruiseControl tasks"
task :cruise => :environment do
  app_name = RAILS_ROOT.split('/').reverse[1]
  report_url = "/app/cruise_control/public/reports/#{app_name}.html"
  begin
    File.open("#{RAILS_ROOT}/config/database.yml",'w'){|f| f.write(
%Q{development:
  adapter: sqlite3
  database: db/development.sqlite3

test:
  adapter: sqlite3
  database: db/test.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3})}
    Rake::Task['db:migrate'].invoke
    report = Rake::Task.task_defined?('report')
    if report
      Rake::Task['report'].invoke
      system("cp #{RAILS_ROOT}/report.html #{report_url}")
    else
      rcov = Rake::Task.task_defined?('test:units:rcov')
      ENV["SHOW_ONLY"] = "m" if rcov
      Rake::Task[rcov ? 'test:units:rcov' : 'test:units'].invoke
      ENV["SHOW_ONLY"] = "c" if rcov
      Rake::Task[rcov ? 'test:functionals:rcov' : 'test:functionals'].invoke
      if rcov
        unit_coverage = open("#{RAILS_ROOT}/coverage/units/index.html"){|f| Hpricot(f)}.at("tt[@class='coverage_code']").inner_html
        functional_coverage = open("#{RAILS_ROOT}/coverage/functionals/index.html"){|f| Hpricot(f)}.at("tt[@class='coverage_code']").inner_html
      end
      File.open(report_url,'w'){|f| f.write(%Q{
<html>
<body>
<h1>
  #{app_name.capitalize}
</h1>
<p>
  <ul>
    <li>
      Your unit tests passed#{rcov ? " with #{unit_coverage} coverage" : nil}
    </li>
    <li>
      Your functional tests passed#{rcov ? " with #{functional_coverage} coverage" : nil}
    </li>
  </ul>
</p>
<p>
  For a better report, please add the <a href="http://www.snippetstash.com/public/159.txt">report.rake</a> file to your application.
</p>})}
    end
  rescue
    File.open(report_url,'w'){|f| f.write(%Q{
<html>
<body>
<h1>
  #{app_name.capitalize}
</h1>
<p>
  Your build did not succeed, so no report was generated.
<p>
</body>
</html>})}
    raise "Build failed"
  end
end
Original snippet written by Kevin Gisi
Last updated at 12:09 PM on Jun 06, 2009

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.