Class: Report

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_qa/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, filename, coverage_report) ⇒ Report

Returns a new instance of Report.



7
8
9
10
11
12
# File 'lib/acts_as_qa/report.rb', line 7

def initialize(name, filename, coverage_report)
  self.name=name
  self.filename=filename
  self.coverage_report=coverage_report
  self.percentage=coverage_report.compact.aaq_percentage
end

Instance Attribute Details

#coverage_reportObject

Returns the value of attribute coverage_report.



5
6
7
# File 'lib/acts_as_qa/report.rb', line 5

def coverage_report
  @coverage_report
end

#filenameObject

Returns the value of attribute filename.



3
4
5
# File 'lib/acts_as_qa/report.rb', line 3

def filename
  @filename
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/acts_as_qa/report.rb', line 2

def name
  @name
end

#percentageObject

Returns the value of attribute percentage.



4
5
6
# File 'lib/acts_as_qa/report.rb', line 4

def percentage
  @percentage
end

Instance Method Details

#generate_html_report(coverage_dir) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acts_as_qa/report.rb', line 14

def generate_html_report(coverage_dir)
  FileUtils.mkpath(coverage_dir+"/"+self.name.split('/')[0..-2].join('/')) if self.name.split('/').length>1
  file = File.new(coverage_dir+"/"+self.name+".html", "w+")
  file.puts('<html><head><link href="'+ Result.css+'" media="screen" rel="stylesheet" type="text/css" /></head><body><h1>'+self.name+'</h1><div class="content">')
  File.open(filename, 'r') do |f|
    lines = f.readlines
    lines.each_index do |i|
      file.puts('<div class="covered_'+self.coverage_report[i].to_s+'"><pre><code>'+CGI::escapeHTML(lines[i])+'</code></pre></div>')
    end
  end
  file.puts('</div></body></html>')
end