Class: TestBench::Output
- Inherits:
-
Object
show all
- Defined in:
- lib/test_bench/output.rb,
lib/test_bench/output/writer.rb,
lib/test_bench/output/palette.rb,
lib/test_bench/output/assertions.rb,
lib/test_bench/output/writer/assertions.rb,
lib/test_bench/output/writer/assertions/line.rb
Defined Under Namespace
Modules: Assertions, Palette
Classes: Writer
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Output
Returns a new instance of Output.
8
9
10
|
# File 'lib/test_bench/output.rb', line 8
def initialize
@file_result = nil
end
|
Instance Attribute Details
#file_result ⇒ Object
81
82
83
|
# File 'lib/test_bench/output.rb', line 81
def file_result
@file_result or Result::Null
end
|
#reverse_backtraces ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/test_bench/output.rb', line 95
def reverse_backtraces
ivar = :@reverse_backtraces
if instance_variable_defined? ivar
instance_variable_get ivar
else
instance_variable_set ivar, false
end
end
|
#run_result ⇒ Object
123
124
125
|
# File 'lib/test_bench/output.rb', line 123
def run_result
@run_result ||= Result.build
end
|
#writer ⇒ Object
165
166
167
|
# File 'lib/test_bench/output.rb', line 165
def writer
@writer ||= Writer.new
end
|
Class Method Details
.build(level = nil) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/test_bench/output.rb', line 12
def self.build level=nil
writer = Writer.build $stdout
writer.level = level if level
instance = new
instance.writer = writer
instance
end
|
Instance Method Details
#asserted ⇒ Object
21
22
23
24
|
# File 'lib/test_bench/output.rb', line 21
def asserted
file_result.asserted
run_result.asserted
end
|
26
27
28
|
# File 'lib/test_bench/output.rb', line 26
def prose
writer.normal prose, :fg => :normal
end
|
#context_entered(prose = nil) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/test_bench/output.rb', line 30
def context_entered prose=nil
return if prose.nil?
writer.normal prose, :fg => :green
writer.increase_indentation unless writer.level == :quiet
end
|
#context_exited(prose = nil) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/test_bench/output.rb', line 38
def context_exited prose=nil
return if prose.nil?
writer.decrease_indentation unless writer.level == :quiet
writer.normal ' ' if writer.indentation.zero?
end
|
#device ⇒ Object
46
47
48
|
# File 'lib/test_bench/output.rb', line 46
def device
@device ||= StringIO.new
end
|
#error_raised(error) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/test_bench/output.rb', line 50
def error_raised error
run_result.error_raised error
file_result.error_raised error
detail_summary = "#{error.backtrace[0]}: #{error.message} (#{error.class})"
lines = [detail_summary]
error.backtrace[1..-1].each do |frame|
lines << " from #{frame}"
end
lines.reverse! if reverse_backtraces
lines.each do |line|
writer.quiet line, :fg => :red
end
end
|
#file_finished(path) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/test_bench/output.rb', line 68
def file_finished path
run_result.file_finished path
file_result.finished
summary = summarize_result file_result
self.file_result = nil
writer.verbose "Finished running #{path}"
writer.verbose summary
writer.verbose ' '
end
|
#file_started(path) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/test_bench/output.rb', line 85
def file_started path
writer.normal "Running #{path}"
file_result = Result.build
self.file_result = file_result
file_result
end
|
#run_finished ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/test_bench/output.rb', line 105
def run_finished
run_result.run_finished
files_label = if run_result.files.size == 1 then 'file' else 'files' end
color = if run_result.passed? then :cyan else :red end
writer.quiet "Finished running #{run_result.files.size} #{files_label}"
summary = summarize_result run_result
writer.quiet summary, :fg => color
end
|
#run_started ⇒ Object
119
120
121
|
# File 'lib/test_bench/output.rb', line 119
def run_started
self.run_result
end
|
#summarize_result(result) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/test_bench/output.rb', line 127
def summarize_result result
minutes, seconds = result.elapsed_time.divmod 60
elapsed = String.new
elapsed << "#{minutes}m" unless minutes.zero?
elapsed << "%.3fs" % seconds
test_label = if result.tests == 1 then 'test' else 'tests' end
error_label = if result.errors == 1 then 'error' else 'errors' end
"Ran %d #{test_label} in #{elapsed} (%.3fs tests/second)\n%d passed, %d skipped, %d failed, %d total #{error_label}" %
[result.tests, result.tests_per_second, result.passes, result.skips, result.failures, result.errors]
end
|
#test_failed(prose) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/test_bench/output.rb', line 140
def test_failed prose
file_result.test_failed prose
run_result.test_failed prose
writer.quiet prose, :fg => :white, :bg => :red
end
|
#test_passed(prose) ⇒ Object
147
148
149
150
151
152
|
# File 'lib/test_bench/output.rb', line 147
def test_passed prose
file_result.test_passed prose
run_result.test_passed prose
writer.normal prose, :fg => :green
end
|
#test_skipped(prose) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/test_bench/output.rb', line 154
def test_skipped prose
file_result.test_skipped prose
run_result.test_skipped prose
writer.normal prose, :fg => :brown
end
|
#test_started(prose) ⇒ Object
161
162
163
|
# File 'lib/test_bench/output.rb', line 161
def test_started prose
writer.verbose "Started test #{prose.inspect}", :fg => :gray
end
|