Class: RSpec::Core::Formatters::HtmlFormatter
- Inherits:
-
BaseTextFormatter
show all
- Defined in:
- lib/rspec/core/formatters/html_formatter.rb
Constant Summary
Constant Summary
Constants included
from Helpers
RSpec::Core::Formatters::Helpers::DEFAULT_PRECISION, RSpec::Core::Formatters::Helpers::SUB_SECOND_PRECISION
Instance Attribute Summary
#duration, #example_count, #example_group, #examples, #failed_examples, #failure_count, #output, #pending_count, #pending_examples
Instance Method Summary
(collapse)
#close, #color_code_for, #colorise_summary, #colorize, const_missing, #dump_commands_to_rerun_failed_examples, #dump_profile, #dump_profile_slowest_example_groups, #dump_profile_slowest_examples, #seed, #summary_line
#close, #example_group_finished, #format_backtrace, #stop
Methods included from Helpers
#format_duration, #format_seconds, #pluralize, #strip_trailing_zeroes
#format_backtrace
Constructor Details
A new instance of HtmlFormatter
9
10
11
12
13
14
15
|
# 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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(m, *a)
18
19
20
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 18
def method_missing(m, *a, &b)
end
|
Instance Method Details
- (Object) dump_failures
136
137
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 136
def dump_failures
end
|
- (Object) dump_pending
139
140
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 139
def dump_pending
end
|
- (Object) dump_summary(duration, example_count, failure_count, pending_count)
142
143
144
145
146
147
148
149
150
151
|
# 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
|
- (Object) example_failed(example)
70
71
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
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 70
def example_failed(example)
super(example)
unless @header_red
@header_red = true
@printer.
end
unless @example_group_red
@example_group_red = true
@printer.(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
= (exception)
@printer.print_example_failed(
example.execution_result[:pending_fixed],
example.description,
example.execution_result[:run_time],
@failed_examples.size,
exception_details,
( == "") ? false : ,
true
)
@printer.flush
end
|
- (Object) example_group_number
The number of the currently running example_group
27
28
29
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 27
def example_group_number
@example_group_number
end
|
- (Object) example_group_started(example_group)
42
43
44
45
46
47
48
49
50
51
52
|
# 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
|
- (Object) example_number
The number of the currently running example (a global counter)
32
33
34
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 32
def example_number
@example_number
end
|
- (Object) example_passed(example)
64
65
66
67
68
|
# 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
|
- (Object) example_pending(example)
108
109
110
111
112
113
114
115
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 108
def example_pending(example)
@printer. unless @header_red
@printer.(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
|
- (Object) example_started(example)
59
60
61
62
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 59
def example_started(example)
super(example)
@example_number += 1
end
|
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.
120
121
122
123
124
125
126
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 120
def (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
|
- (Object) message(message)
23
24
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 23
def message(message)
end
|
- (Object) percent_done
128
129
130
131
132
133
134
|
# 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
|
- (Object) start(example_count)
36
37
38
39
40
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 36
def start(example_count)
super(example_count)
@printer.print_html_start
@printer.flush
end
|
- (Object) start_dump
54
55
56
57
|
# File 'lib/rspec/core/formatters/html_formatter.rb', line 54
def start_dump
@printer.print_example_group_end
@printer.flush
end
|