Report.rake

Tagged with rake Rails Ruby

Language: Ruby

View as text

require 'hpricot'

APPLICATION = "Saleboard"
APPLICATION_NUMBER="068"
LEAD_DEVELOPER="Kevin Gisi"
PRIMARY_CLIENT="Deb Klossner"

desc "Generate a full report"
task :report => :environment do
  puts "=== Deployment Report Generator ==="
  puts "Building environment report..."
  report = %Q{
    <html>
      <head>
        <title>
          Deployment Checklist
        </title>
      </head>
      <style type="text/css" media="all">
        #content {
          background-color: white;
          width: 800px;
          margin: 20px auto;
          padding: 10px;
          border: 1px solid black;
        }
        td {
          width: 200px;
        }
        #developer_comments {
          height: 350px;
        }
        #client_comments {
          height: 350px;
        }
      </style>
      <style type="text/css" media="print">
        #content {
          border: none;
        }
      </style>
      <body style="background-color: #4B7399">
        <div id="content">
          <h1>
            LTS Deployment Checklist
          </h1><hr />
          <p>
            <b>Application: </b>#{APPLICATION}<br />
            <b>Application Number: </b>#{APPLICATION_NUMBER}<br />
            <b>Lead Developer: </b>#{LEAD_DEVELOPER}<br />
            <b>Primary Client: </b>#{PRIMARY_CLIENT}
          </p>
          <p>
            <b>Ruby Version: </b>#{RUBY_VERSION}<br />
            <b>Rails Version: </b>#{Rails.version}<br />
            <b>Report Generated: </b>#{Time.now.strftime('%B%e, %Y')}
          </p>
          <hr />}

  Rake::Task['rcov:full'].invoke

  unit_tests = open("coverage/units/index.html"){|f| Hpricot(f)}
  report += "<h2>Unit Tests</h2><table>"
  report += "<tr><th></th><th align='right'>Total Lines</th><th align='right'>Lines of Code</th><th align='right'>Coverage</th></tr>"
  unit_tests.search("body/table[@class='report']/tbody/tr").each do |row|
    report += "<tr>"
    title = row.at("td")
    report += "<td><i>#{(link=title.at("a")) ? link.inner_html : title.inner_html}</i></td>"
    report += "<td align='right'>#{row.at("td[@class='lines_total']/tt").inner_html}</td>"
    report += "<td align='right'>#{row.at("td[@class='lines_code']/tt").inner_html}</td>"
    report += "<td align='right'>#{row.at("tt[@class='coverage_code']").inner_html}</td>"
    report += "</tr>"
  end
  report += "</table><hr />"

  functional_tests = open("coverage/functionals/index.html"){|f| Hpricot(f)}
  report += "<h2>Functional Tests</h2><table>"
  report += "<tr><th></th><th align='right'>Total Lines</th><th align='right'>Lines of Code</th><th align='right'>Coverage</th></tr>"
  functional_tests.search("body/table[@class='report']/tbody/tr").each do |row|
    report += "<tr>"
    title = row.at("td")
    report += "<td><i>#{(link=title.at("a")) ? link.inner_html : title.inner_html}</i></td>"
    report += "<td align='right'>#{row.at("td[@class='lines_total']/tt").inner_html}</td>"
    report += "<td align='right'>#{row.at("td[@class='lines_code']/tt").inner_html}</td>"
    report += "<td align='right'>#{row.at("tt[@class='coverage_code']").inner_html}</td>"
    report += "</tr>"
  end
  report += "</table><hr />"

  doc = Hpricot(`cucumber features --format html`)
  doc.search("//div[@class='scenario']").each do |scenario|
    scenario.after %q{
      <div style="text-align: right">
        Automated Check <input type=checkbox disabled=true checked=#{(scenario.search('li').inject(true){|log,li| log &&= li.attributes['class'] == 'passed'})}><br />
        Developer Check <input type=checkbox><br />
        Client Check <input type=checkbox>
      </div>
    }
  end
  report += doc.search("//div[@class='cucumber']").to_html

  report += %Q{
    <h1>Comments</h1>
    <h2>Developer Comments</h2>
    <div id="developer_comments">

    </div>
    <h2>Client Comments</h2>
    <div id="client_comments">
    
    </div>
    <h1>Deployment</h1>
    <p>
      Once this application is deployed, LTS-Web Development will provide bug-fixes for requests submitted within two weeks of deployment. Any issues with the application beyond the two-week window may either be immediately fixed - at the discretion of LTS-Web Development - or added as features to a new project request. Any additional features required after deployment will be added as requirements for a new project request, so as to ensure fair distribution of resources to application requests.
    </p>
    <p>
      I understand the deployment policies, and request this application be deployed at the earliest possible time.
    </p>
    <p>
      <u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u>   Date: <u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u>
    </p>
  }

  report += %q{
      </div>
    </body>
  </html>}
  File.open('report.html','w'){|f| f.write(report)}
  puts "Final report written to report.html"
end
Original snippet written by Kevin Gisi
Last updated at 11:19 AM 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.