Class: RSpec::Core::Formatters::HtmlFormatter

Inherits:
BaseTextFormatter show all
Defined in:
lib/rspec/legacy_formatters/html_formatter.rb

Constant Summary

Constants inherited from BaseTextFormatter

BaseTextFormatter::VT100_COLORS, BaseTextFormatter::VT100_COLOR_CODES

Constants included from Helpers

RSpec::Core::Formatters::Helpers::DEFAULT_PRECISION, RSpec::Core::Formatters::Helpers::SUB_SECOND_PRECISION

Instance Attribute Summary

Attributes inherited from BaseFormatter

#duration, #example_count, #example_group, #examples, #failed_examples, #failure_count, #output, #pending_count, #pending_examples

Instance Method Summary collapse

Methods inherited from BaseTextFormatter

#close, #color_code_for, #colorise_summary, #colorize, #dump_commands_to_rerun_failed_examples, #dump_profile, #dump_profile_slowest_example_groups, #dump_profile_slowest_examples, #seed, #summary_line

Methods inherited from BaseFormatter

#close, #example_group_finished, #format_backtrace, #stop

Methods included from Helpers

#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes

Methods included from LegacyBacktraceFormatter

#format_backtrace

Constructor Details

#initialize(output) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter.



11
12
13
14
15
16
17
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 11

def initialize(output)
  super(output)
  @example_group_number = 0
  @example_number = 0
  @header_red = nil
  @printer = HtmlPrinter.new(output)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ void (private)



20
21
22
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 20

def method_missing(m, *a, &b)
  # no-op
end

Instance Method Details

#dump_failuresvoid



138
139
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 138

def dump_failures
end

#dump_pendingvoid



141
142
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 141

def dump_pending
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ void



144
145
146
147
148
149
150
151
152
153
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 144

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) ⇒ void



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 72

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.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_numbervoid

The number of the currently running example_group



29
30
31
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 29

def example_group_number
  @example_group_number
end

#example_group_started(example_group) ⇒ void



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 44

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_numbervoid

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



34
35
36
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 34

def example_number
  @example_number
end

#example_passed(example) ⇒ void



66
67
68
69
70
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 66

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) ⇒ void



110
111
112
113
114
115
116
117
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 110

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.execution_result.pending_message )
  @printer.flush
end

#example_started(example) ⇒ void



61
62
63
64
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 61

def example_started(example)
  super(example)
  @example_number += 1
end

#extra_failure_content(exception) ⇒ void

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.



122
123
124
125
126
127
128
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 122

def extra_failure_content(exception)
  require 'rspec/legacy_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) ⇒ void



25
26
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 25

def message(message)
end

#percent_donevoid



130
131
132
133
134
135
136
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 130

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) ⇒ void



38
39
40
41
42
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 38

def start(example_count)
  super(example_count)
  @printer.print_html_start
  @printer.flush
end

#start_dumpvoid



56
57
58
59
# File 'lib/rspec/legacy_formatters/html_formatter.rb', line 56

def start_dump
  @printer.print_example_group_end
  @printer.flush
end