Class: ParallelHtmlFormatter
Constant Summary
ParallelTests::RSpec::LoggerBase::RSPEC_1
Instance Method Summary
collapse
#close, #lock_output, #lock_output_begin, #lock_output_end
Constructor Details
Returns a new instance of ParallelHtmlFormatter.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sim/parallel_html_formatter.rb', line 7
def initialize(output)
super(output)
@buffer = StringIO.new
@header_buffer = StringIO.new
@example_group_number = 0
@example_number = 0
@header_red = nil
@printer = RSpec::Core::Formatters::HtmlPrinter.new(@buffer)
@header_printer = RSpec::Core::Formatters::HtmlPrinter.new(@header_buffer)
if ENV[:TEST_ENV_NUMBER.to_s] == ""
lock_output do
@header_printer.print_html_start
@header_buffer.puts "<input id=\"curr_duration\" type=\"hidden\" value=\"0\"/>"
@header_buffer.puts "<input id=\"curr_example_count\" type=\"hidden\" value=\"0\"/>"
@header_buffer.puts "<input id=\"curr_failure_count\" type=\"hidden\" value=\"0\"/>"
@output.puts @header_buffer.string
@output.flush
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
38
39
40
|
# File 'lib/sim/parallel_html_formatter.rb', line 38
def method_missing(m, *a, &b)
end
|
Instance Method Details
#dump_failures ⇒ Object
149
150
|
# File 'lib/sim/parallel_html_formatter.rb', line 149
def dump_failures
end
|
#dump_pending ⇒ Object
152
153
|
# File 'lib/sim/parallel_html_formatter.rb', line 152
def dump_pending
end
|
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/sim/parallel_html_formatter.rb', line 155
def dump_summary(duration, example_count, failure_count, pending_count)
formatted_duration = sprintf("%.5f", duration)
@buffer.puts "<script type=\"text/javascript\">"
@buffer.puts " var curr_duration = parseFloat(document.getElementById('curr_duration').value) + #{formatted_duration};"
@buffer.puts " document.getElementById('curr_duration').value = curr_duration;"
@buffer.puts " document.getElementById('duration').innerHTML = 'Finished in <strong>' + curr_duration.toFixed(3) + ' seconds</strong>';"
@buffer.puts "</script>"
@buffer.puts "<script type=\"text/javascript\">"
@buffer.puts " var curr_example_count = Number(document.getElementById('curr_example_count').value) + #{example_count};"
@buffer.puts " var curr_failure_count = Number(document.getElementById('curr_failure_count').value) + #{failure_count};"
@buffer.puts " document.getElementById('curr_example_count').value = curr_example_count;"
@buffer.puts " document.getElementById('curr_failure_count').value = curr_failure_count;"
@buffer.puts " document.getElementById('totals').innerHTML = curr_example_count + ' example(s),' + curr_failure_count + ' failure(s)';"
@buffer.puts "</script>"
@buffer.puts "</div>"
@buffer.puts "</div>"
lock_output do
@output.puts @buffer.string
@output.flush
end
end
|
#example_failed(example) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/sim/parallel_html_formatter.rb', line 85
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
)
end
|
#example_group_number ⇒ Object
The number of the currently running example_group
47
48
49
|
# File 'lib/sim/parallel_html_formatter.rb', line 47
def example_group_number
@example_group_number
end
|
#example_group_started(example_group) ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/sim/parallel_html_formatter.rb', line 60
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 )
end
|
#example_number ⇒ Object
The number of the currently running example (a global counter)
52
53
54
|
# File 'lib/sim/parallel_html_formatter.rb', line 52
def example_number
@example_number
end
|
#example_passed(example) ⇒ Object
80
81
82
83
|
# File 'lib/sim/parallel_html_formatter.rb', line 80
def example_passed(example)
@printer.move_progress(percent_done)
@printer.print_example_passed( example.description, example.execution_result[:run_time] )
end
|
#example_pending(example) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/sim/parallel_html_formatter.rb', line 122
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] )
end
|
#example_started(example) ⇒ Object
75
76
77
78
|
# File 'lib/sim/parallel_html_formatter.rb', line 75
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.
133
134
135
136
137
138
139
|
# File 'lib/sim/parallel_html_formatter.rb', line 133
def (exception)
require 'rspec/core/formatters/snippet_extractor'
backtrace = exception.backtrace.map {|line| backtrace_line(line)}
backtrace.compact!
@snippet_extractor ||= RSpec::Core::Formatters::SnippetExtractor.new
" <pre class=\"ruby\"><code>#{@snippet_extractor.snippet(backtrace)}</code></pre>"
end
|
#message(message) ⇒ Object
43
44
|
# File 'lib/sim/parallel_html_formatter.rb', line 43
def message(message)
end
|
#percent_done ⇒ Object
141
142
143
144
145
146
147
|
# File 'lib/sim/parallel_html_formatter.rb', line 141
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) ⇒ Object
56
57
58
|
# File 'lib/sim/parallel_html_formatter.rb', line 56
def start(example_count)
super(example_count)
end
|
#start_dump ⇒ Object
71
72
73
|
# File 'lib/sim/parallel_html_formatter.rb', line 71
def start_dump
@printer.print_example_group_end
end
|