class RSpec::Core::Formatters::HtmlFormatter

Public Class Methods

new(output) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 9
def initialize(output)
  super(output)
  @example_group_number = 0
  @example_number = 0
  @header_red = nil
  @printer = HtmlPrinter.new(output)
end

Public Instance Methods

dump_failures() click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 136
def dump_failures
end
dump_pending() click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 139
def dump_pending
end
dump_summary(duration, example_count, failure_count, pending_count) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 142
def dump_summary(duration, example_count, failure_count, pending_count)
  @printer.print_summary(
    dry_run?,
    duration,
    example_count,
    failure_count,
    pending_count
  )
  @printer.flush
end
example_failed(example) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 70
def example_failed(example)
  super(example)

  unless @header_red
    @header_red = true
    @printer.make_header_red
  end

  unless @example_group_red
    @example_group_red = true
    @printer.make_example_group_header_red(example_group_number)
  end

  @printer.move_progress(percent_done)

  exception = example.metadata[:execution_result][:exception]
  exception_details = if exception
    {
      :message => exception.message,
      :backtrace => format_backtrace(exception.backtrace, example).join("\n")
    }
  else
    false
  end
  extra = extra_failure_content(exception)

  @printer.print_example_failed(
    example.execution_result[:pending_fixed],
    example.description,
    example.execution_result[:run_time],
    @failed_examples.size,
    exception_details,
    (extra == "") ? false : extra,
    true
  )
  @printer.flush
end
example_group_number() click to toggle source

The number of the currently running example_group

# File lib/rspec/core/formatters/html_formatter.rb, line 27
def example_group_number
  @example_group_number
end
example_group_started(example_group) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 42
def example_group_started(example_group)
  super(example_group)
  @example_group_red = false
  @example_group_number += 1

  unless example_group_number == 1
    @printer.print_example_group_end
  end
  @printer.print_example_group_start( example_group_number, example_group.description, example_group.parent_groups.size )
  @printer.flush
end
example_number() click to toggle source

The number of the currently running example (a global counter)

# File lib/rspec/core/formatters/html_formatter.rb, line 32
def example_number
  @example_number
end
example_passed(example) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 64
def example_passed(example)
  @printer.move_progress(percent_done)
  @printer.print_example_passed( example.description, example.execution_result[:run_time] )
  @printer.flush
end
example_pending(example) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 108
def example_pending(example)

  @printer.make_header_yellow unless @header_red
  @printer.make_example_group_header_yellow(example_group_number) unless @example_group_red
  @printer.move_progress(percent_done)
  @printer.print_example_pending( example.description, example.metadata[:execution_result][:pending_message] )
  @printer.flush
end
example_started(example) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 59
def example_started(example)
  super(example)
  @example_number += 1
end
extra_failure_content(exception) click to toggle source

Override this method if you wish to output extra HTML for a failed spec. For example, you could output links to images or other files produced during the specs.

# File lib/rspec/core/formatters/html_formatter.rb, line 120
def extra_failure_content(exception)
  require 'rspec/core/formatters/snippet_extractor'
  backtrace = exception.backtrace.map {|line| backtrace_line(line)}
  backtrace.compact!
  @snippet_extractor ||= SnippetExtractor.new
  "    <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
end
message(message) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 23
def message(message)
end
percent_done() click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 128
def percent_done
  result = 100.0
  if @example_count > 0
    result = (((example_number).to_f / @example_count.to_f * 1000).to_i / 10.0).to_f
  end
  result
end
start(example_count) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 36
def start(example_count)
  super(example_count)
  @printer.print_html_start
  @printer.flush
end
start_dump() click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 54
def start_dump
  @printer.print_example_group_end
  @printer.flush
end

Private Instance Methods

method_missing(m, *a, &b) click to toggle source
# File lib/rspec/core/formatters/html_formatter.rb, line 18
def method_missing(m, *a, &b)
  # no-op
end