Class: QED::Reporter::Html

Inherits:
Abstract show all
Defined in:
lib/qed/reporter/html.rb

Overview

Html Reporter

NOTE: This must be completely redesigned since we moved back to text based evaluation –which makes generting HTML with modifications from the evaluation tricky. But I've come up with a farily clever way to handle this. Take the original and use Tilt to translate it into HTML, then take the evaluation results for code steps and use it to search the HTML for “the closest match”. Find the <pre> tag associated with the text and add class and color style. Of course the tricky part is the matching, but if we run the text snippet through Tilt as well we should be able to get an exact match. It won't be fast, but it should work.

Constant Summary

Constants inherited from Abstract

Abstract::DEFAULT_TRACE_COUNT, Abstract::INFO_SIGNAL, Abstract::INTERNALS

Instance Attribute Summary

Attributes inherited from Abstract

#io, #record, #session

Instance Method Summary collapse

Methods inherited from Abstract

After, Before, When, #after_eval, #after_import, #after_proc, #after_step, #before_eval, #before_import, #before_proc, #before_step, #call, #clean_backtrace, #code_snippet, #count_demo, #count_error, #count_fail, #count_pass, #count_step, #demo, #demos, #errors, #eval, #fails, #file_and_line, #file_line, #get_tally, #import, #localize_file, #omits, #passes, #print_tally, #print_time, #proc, #relative_file, #rule, #sane_backtrace, #source, #steps, #structured_code_snippet, #success?, #trace?, #trace_count

Constructor Details

#initialize(*args) ⇒ Html

Returns a new instance of Html.


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/qed/reporter/html.rb', line 26

def initialize(*args)
  require 'erb'

  begin
    require 'rubygems'
    gem 'rdoc'
    require 'rdoc'
  rescue
  end

  super(*args)
end

Instance Method Details

#after_demo(demo) ⇒ Object


132
133
# File 'lib/qed/reporter/html.rb', line 132

def after_demo(demo)
end

#after_session(session) ⇒ Object


136
137
138
139
140
141
# File 'lib/qed/reporter/html.rb', line 136

def after_session(session)
  io.puts "</body>\n</html>\n"
end

#before_demo(demo) ⇒ Object


62
63
64
65
66
# File 'lib/qed/reporter/html.rb', line 62

def before_demo(demo)
  io.puts "<h2>\#{localize_file(demo.file)}</h2>\n"
end

#before_session(session) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qed/reporter/html.rb', line 40

def before_session(session)
  io.puts "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n<title>QED Report</title>\n<style>\nbody{width:800px; margin:0 auto;}\npre{font-family: courier,monospace;}\n.pass{color: #020;}\n.pass pre{color: green;}\n.fail{color: #200; background: pink;}\n.fail pre{color: green;}\n.error{color: #200; background: pink;}\n.error pre{color: red;}\n</style>\n</head>\n<body>\n"
end

#error(step, exception) ⇒ Object


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/qed/reporter/html.rb', line 112

def error(step, exception)
  io.puts ERB.new("<div class=\"test error\">\n\#{render(@_explain)}\n\n<pre>\#{step.example}</pre>\n\n<div class=\"exception\">\n<p>\#{exception.class} - \#{exception.message}</p>\n<ol>\n<% exception.backtrace.each do |bt| %>\n<li><%= bt %></li>\n<% end %>\n</ol>\n</div>\n</div>\n").result(binding)
end

#fail(step, assertion) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/qed/reporter/html.rb', line 92

def fail(step, assertion)
  io.puts ERB.new("<div class=\"test fail\">\n\#{render(@_explain)}\n\n<pre>\#{step.example}</pre>\n\n<div class=\"assertion\">\n<p>\#{assertion.class} - \#{assertion.message}</p>\n<ol>\n<% assertion.backtrace.each do |bt| %>\n<li><%= bt %></li>\n<% end %>\n</ol>\n</div>\n</div>\n").result(binding)
end

#match(step, md) ⇒ Object


73
74
75
76
77
78
# File 'lib/qed/reporter/html.rb', line 73

def match(step, md)
  #@match = md
  unless md[0].empty?
    @_explain.sub!(md[0], "<b>#{md[0]}</b>")
  end
end

#pass(step) ⇒ Object


81
82
83
84
85
86
87
88
89
# File 'lib/qed/reporter/html.rb', line 81

def pass(step)
  io.puts "<div class=\"test pass\">\n\#{render(@_explain)}\n\n<pre>\#{step.example}</pre>\n</div>\n"
end

#rdocObject (private)


149
150
151
# File 'lib/qed/reporter/html.rb', line 149

def rdoc
  @rdoc ||= RDoc::Markup::ToHtml.new
end

#render(str) ⇒ Object (private)


145
146
147
# File 'lib/qed/reporter/html.rb', line 145

def render(str)
  rdoc.convert(str.strip)
end

#step(step) ⇒ Object


68
69
70
# File 'lib/qed/reporter/html.rb', line 68

def step(step)
  @_explain = step.explain.dup
end