Class: Relevance::Tarantula::HtmlReporter
Defined Under Namespace
Classes: HtmlResultOverview
Constant Summary
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
#log, #rails_root, #tarantula_home, #verbose
Constructor Details
Returns a new instance of HtmlReporter.
12
13
14
15
16
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 12
def initialize(basedir)
@basedir = basedir
@results = Struct.new(:successes, :failures).new([], [])
FileUtils.mkdir_p(@basedir)
end
|
Instance Attribute Details
Returns the value of attribute basedir.
7
8
9
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 7
def basedir
@basedir
end
|
Returns the value of attribute results.
7
8
9
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 7
def results
@results
end
|
Instance Method Details
#class_for_code(code) ⇒ Object
CSS class for HTML status codes
103
104
105
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 103
def class_for_code(code)
"r#{Integer(code)/100}"
end
|
#copy_styles ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 41
def copy_styles
FileUtils.mkdir_p(File.join(basedir, "stylesheets"))
Dir.glob("#{tarantula_home}/laf/stylesheets/*.css").each do |file|
FileUtils.cp(file, File.join(basedir, "stylesheets"))
end
FileUtils.mkdir_p(File.join(basedir, "images"))
Dir.glob("#{tarantula_home}/laf/images/*.{jpg,gif,png}").each do |file|
FileUtils.cp(file, File.join(basedir, "images"))
end
FileUtils.mkdir_p(File.join(basedir, "javascripts"))
Dir.glob("#{tarantula_home}/laf/javascripts/*.js").each do |file|
FileUtils.cp(file, File.join(basedir, "javascripts"))
end
end
|
#create_detail_report(result) ⇒ Object
36
37
38
39
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 36
def create_detail_report(result)
template = ERB.new(template("detail.html.erb"))
output(result.file_name, template.result(result.send(:binding)), result.test_name)
end
|
#create_index ⇒ Object
57
58
59
60
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 57
def create_index
template = ERB.new(template("index.html.erb"))
output("index.html", template.result(binding))
end
|
#finish_report(test_name) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 29
def finish_report(test_name)
puts "Writing results to #{basedir}"
copy_styles unless styles_exist?
create_index unless index_exists?
update_index(test_name)
end
|
#index_exists? ⇒ Boolean
74
75
76
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 74
def index_exists?
File.exists?(File.join(basedir, "index.html"))
end
|
#output(name, body, subdir = '') ⇒ Object
95
96
97
98
99
100
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 95
def output(name, body, subdir = '')
FileUtils.mkdir_p(File.join(basedir, subdir)) unless subdir.empty?
File.open(File.join(basedir, subdir, name), "w") do |file|
file.write body
end
end
|
#report(result) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 18
def report(result)
return if result.nil?
create_detail_report(result)
collection = result.success ? results.successes : results.failures
collection << HtmlResultOverview.new(
result.code, result.url, result.description, result.method, result.referrer, result.file_name
)
end
|
#results_html(test_name) ⇒ Object
86
87
88
89
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 86
def results_html(test_name)
template = ERB.new(template("test_report.html.erb"))
template.result(binding)
end
|
#styles_exist? ⇒ Boolean
78
79
80
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 78
def styles_exist?
File.exists?(File.join(basedir, "stylesheets", "tarantula.css"))
end
|
#tab_html(test_name) ⇒ Object
82
83
84
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 82
def tab_html(test_name)
"<li><a href='##{test_name}'><span>#{test_name}</span></a></li>"
end
|
#template(name) ⇒ Object
91
92
93
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 91
def template(name)
File.read(File.join(File.dirname(__FILE__), name))
end
|
#update_index(test_name) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/relevance/tarantula/html_reporter.rb', line 62
def update_index(test_name)
File.open(File.join(basedir, "index.html"), "r+") do |file|
doc = Hpricot file.read
tabs_container = doc.search "#tabs-container ul"
results_container = doc.search "#results-container"
tabs_container.append tab_html(test_name)
results_container.append results_html(test_name)
file.rewind
file.write doc.to_s
end
end
|