class QED::Reporter::Html

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.

Public Class Methods

new(*args) click to toggle source
Calls superclass method QED::Reporter::Abstract::new
# 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

Public Instance Methods

after_demo(demo) click to toggle source
# File lib/qed/reporter/html.rb, line 132
def after_demo(demo)
end
after_session(session) click to toggle source
# File lib/qed/reporter/html.rb, line 136
    def after_session(session)
      io.puts <<-END
        </body>
        </html>
      END
    end
before_demo(demo) click to toggle source
# File lib/qed/reporter/html.rb, line 62
    def before_demo(demo)
      io.puts <<-END
        <h2>#{localize_file(demo.file)}</h2>
      END
    end
before_session(session) click to toggle source
# File lib/qed/reporter/html.rb, line 40
    def before_session(session)
      io.puts <<-END
        <html>
        <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
          <title>QED Report</title>
          <style>
            body{width:800px; margin:0 auto;}
            pre{font-family: courier,monospace;}
            .pass{color: #020;}
            .pass pre{color: green;}
            .fail{color: #200; background: pink;}
            .fail pre{color: green;}
            .error{color: #200; background: pink;}
            .error pre{color: red;}
          </style>
        </head>
        <body>
      END
    end
error(step, exception) click to toggle source
# File lib/qed/reporter/html.rb, line 112
    def error(step, exception)
      io.puts ERB.new(<<-END).result(binding)
        <div class="test error">
          #{render(@_explain)}

          <pre>#{step.example}</pre>

          <div class="exception">
            <p>#{exception.class} - #{exception.message}</p>
            <ol>
            <% exception.backtrace.each do |bt| %>
              <li><%= bt %></li>
            <% end %>
            </ol>
          </div>
        </div>
      END
    end
fail(step, assertion) click to toggle source
# File lib/qed/reporter/html.rb, line 92
    def fail(step, assertion)
      io.puts ERB.new(<<-END).result(binding)
        <div class="test fail">
          #{render(@_explain)}

          <pre>#{step.example}</pre>

          <div class="assertion">
            <p>#{assertion.class} - #{assertion.message}</p>
            <ol>
            <% assertion.backtrace.each do |bt| %>
              <li><%= bt %></li>
            <% end %>
            </ol>
          </div>
        </div>
      END
    end
match(step, md) click to toggle source
# 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) click to toggle source
# File lib/qed/reporter/html.rb, line 81
    def pass(step)
      io.puts <<-END
        <div class="test pass">
          #{render(@_explain)}

          <pre>#{step.example}</pre>
        </div>
      END
    end
step(step) click to toggle source
# File lib/qed/reporter/html.rb, line 68
def step(step)
  @_explain = step.explain.dup
end

Private Instance Methods

rdoc() click to toggle source
# File lib/qed/reporter/html.rb, line 149
def rdoc
  @rdoc ||= RDoc::Markup::ToHtml.new
end
render(str) click to toggle source
# File lib/qed/reporter/html.rb, line 145
def render(str)
  rdoc.convert(str.strip)
end