Class: QED::Reporter::Html

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

Overview

Html Reporter

Generates a self-contained HTML report of a QED session, with color-coded pass/fail/error results.

Constant Summary

Constants inherited from Abstract

Abstract::INFO_SIGNAL

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, #count_demo, #count_error, #count_fail, #count_pass, #count_step, #demo, #demos, #errors, #eval, #fails, #import, #initialize, #omits, #passes, #proc, #rule, #steps, #success?, #trace?

Constructor Details

This class inherits a constructor from QED::Reporter::Abstract

Instance Method Details

#after_demo(demo) ⇒ Object



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

def after_demo(demo)
  super(demo)
  io.puts %[</div>]
end

#after_session(session) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/qed/reporter/html.rb', line 79

def after_session(session)
  super(session)

  pass_count = passes.size
  fail_count = fails.size
  error_count = errors.size
  total = steps.size

  status = (fail_count + error_count) == 0 ? 'pass' : 'fail'

  io.puts %[<div class="summary #{status}">]
  io.puts %[<p>#{demos.size} demos, #{total} steps: #{fail_count} failures, #{error_count} errors</p>]
  io.puts %[<p class="time">Finished in %.5f seconds</p>] % [Time.now - @start_time]
  io.puts %[</div>]
  io.puts HTML_FOOT
end

#before_demo(demo) ⇒ Object



20
21
22
23
24
# File 'lib/qed/reporter/html.rb', line 20

def before_demo(demo)
  super(demo)
  io.puts %[<div class="demo">]
  io.puts %[<h2 class="demo-file">#{escape(localize_file(demo.file))}</h2>]
end

#before_session(session) ⇒ Object



15
16
17
18
# File 'lib/qed/reporter/html.rb', line 15

def before_session(session)
  super(session)
  io.puts HTML_HEAD
end

#error(step, exception) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/qed/reporter/html.rb', line 60

def error(step, exception)
  super(step, exception)
  io.puts %[<div class="step error">]
  io.puts render(@_explain)
  if step.has_example?
    io.puts %[<pre class="code error">#{escape(step.example)}</pre>]
  end
  io.puts %[<div class="details">]
  io.puts %[<p class="message">ERROR: #{escape(exception.class.to_s)} - #{escape(exception.message)}</p>]
  io.puts %[<pre class="backtrace">#{escape(sane_backtrace(exception).join("\n"))}</pre>]
  io.puts %[</div>]
  io.puts %[</div>]
end

#fail(step, assertion) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/qed/reporter/html.rb', line 46

def fail(step, assertion)
  super(step, assertion)
  io.puts %[<div class="step fail">]
  io.puts render(@_explain)
  if step.has_example?
    io.puts %[<pre class="code fail">#{escape(step.example)}</pre>]
  end
  io.puts %[<div class="details">]
  io.puts %[<p class="message">FAIL: #{escape(assertion.message)}</p>]
  io.puts %[<pre class="backtrace">#{escape(sane_backtrace(assertion).join("\n"))}</pre>]
  io.puts %[</div>]
  io.puts %[</div>]
end

#match(step, md) ⇒ Object



30
31
32
33
34
# File 'lib/qed/reporter/html.rb', line 30

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

#pass(step) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/qed/reporter/html.rb', line 36

def pass(step)
  super(step)
  io.puts %[<div class="step pass">]
  io.puts render(@_explain)
  if step.has_example?
    io.puts %[<pre class="code pass">#{escape(step.example)}</pre>]
  end
  io.puts %[</div>]
end

#step(step) ⇒ Object



26
27
28
# File 'lib/qed/reporter/html.rb', line 26

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