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

Inherits:
BaseFormatter show all
Defined in:
lib/rspec/core/formatters/html_formatter.rb

Instance Attribute Summary

Attributes inherited from BaseFormatter

#example_group, #output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#close

Constructor Details

#initialize(output) ⇒ HtmlFormatter

Returns a new instance of HtmlFormatter



13
14
15
16
17
18
19
20
# File 'lib/rspec/core/formatters/html_formatter.rb', line 13

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

Instance Method Details

#dump_summary(summary) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/rspec/core/formatters/html_formatter.rb', line 103

def dump_summary(summary)
  @printer.print_summary(
    summary.duration,
    summary.example_count,
    summary.failure_count,
    summary.pending_count
  )
  @printer.flush
end

#example_failed(failure) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rspec/core/formatters/html_formatter.rb', line 55

def example_failed(failure)
  @failed_examples << failure.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)

  example = failure.example

  exception = failure.exception
  message_lines = failure.fully_formatted_lines(nil, RSpec::Core::Notifications::NullColorizer)
  exception_details = if exception
                        {
                          # drop 2 removes the description (regardless of newlines) and leading blank line
                          :message => message_lines.drop(2).join("\n"),
                          :backtrace => failure.formatted_backtrace.join("\n"),
                        }
                      end
  extra = extra_failure_content(failure)

  @printer.print_example_failed(
    example.execution_result.pending_fixed,
    example.description,
    example.execution_result.run_time,
    @failed_examples.size,
    exception_details,
    (extra == "") ? false : extra
  )
  @printer.flush
end

#example_group_started(notification) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rspec/core/formatters/html_formatter.rb', line 28

def example_group_started(notification)
  super
  @example_group_red = false
  @example_group_number += 1

  @printer.print_example_group_end unless example_group_number == 1
  @printer.print_example_group_start(example_group_number,
                                     notification.group.description,
                                     notification.group.parent_groups.size)
  @printer.flush
end

#example_passed(passed) ⇒ Object



49
50
51
52
53
# File 'lib/rspec/core/formatters/html_formatter.rb', line 49

def example_passed(passed)
  @printer.move_progress(percent_done)
  @printer.print_example_passed(passed.example.description, passed.example.execution_result.run_time)
  @printer.flush
end

#example_pending(pending) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/rspec/core/formatters/html_formatter.rb', line 93

def example_pending(pending)
  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(_notification) ⇒ Object



45
46
47
# File 'lib/rspec/core/formatters/html_formatter.rb', line 45

def example_started(_notification)
  @example_number += 1
end

#start(notification) ⇒ Object



22
23
24
25
26
# File 'lib/rspec/core/formatters/html_formatter.rb', line 22

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

#start_dump(_notification) ⇒ Object



40
41
42
43
# File 'lib/rspec/core/formatters/html_formatter.rb', line 40

def start_dump(_notification)
  @printer.print_example_group_end
  @printer.flush
end