@@ -150,7 +150,7 @@ module Spec
150
150
end
151
151
152
152
def run
153
- print_order_message
153
+ print_order_message(cli.stdout)
154
154
155
155
internal_run
156
156
end
@@ -174,17 +174,17 @@ module Spec
174
174
def finish (elapsed_time, aborted = false )
175
175
cli.formatters.each(& .finish(elapsed_time, aborted))
176
176
if cli.formatters.any?(& .should_print_summary?)
177
- print_summary(elapsed_time, aborted)
177
+ print_summary(cli.stdout, elapsed_time, aborted)
178
178
end
179
179
end
180
180
181
- def print_summary (elapsed_time, aborted = false )
181
+ def print_summary (io : IO , elapsed_time, aborted = false )
182
182
pendings = results_for(:pending )
183
183
unless pendings.empty?
184
- puts
185
- puts " Pending:"
184
+ io. puts
185
+ io. puts " Pending:"
186
186
pendings.each do |pending |
187
- puts Spec .color(" #{ pending.description } " , :pending )
187
+ io. puts Spec .color(" #{ pending.description } " , :pending )
188
188
end
189
189
end
190
190
@@ -195,50 +195,50 @@ module Spec
195
195
196
196
failures_and_errors = failures + errors
197
197
unless failures_and_errors.empty?
198
- puts
199
- puts " Failures:"
198
+ io. puts
199
+ io. puts " Failures:"
200
200
failures_and_errors.each_with_index do |fail , i |
201
201
if ex = fail.exception
202
- puts
203
- puts " #{ (i + 1 ).to_s.rjust(3 , ' ' ) } ) #{ fail.description } "
202
+ io. puts
203
+ io. puts " #{ (i + 1 ).to_s.rjust(3 , ' ' ) } ) #{ fail.description } "
204
204
205
205
if ex.is_a?(SpecError )
206
206
source_line = Spec .read_line(ex.file, ex.line)
207
207
if source_line
208
- puts Spec .color(" Failure/Error: #{ source_line.strip } " , :error )
208
+ io. puts Spec .color(" Failure/Error: #{ source_line.strip } " , :error )
209
209
end
210
210
end
211
- puts
211
+ io. puts
212
212
213
213
message = ex.is_a?(SpecError ) ? ex.to_s : ex.inspect_with_backtrace
214
214
message.split('\n' ) do |line |
215
- print " "
216
- puts Spec .color(line, :error )
215
+ io. print " "
216
+ io. puts Spec .color(line, :error )
217
217
end
218
218
219
219
if ex.is_a?(SpecError )
220
- puts
221
- puts Spec .color(" # #{ Path [ex.file].relative_to(cwd)} :#{ ex.line } " , :comment )
220
+ io. puts
221
+ io. puts Spec .color(" # #{ Path [ex.file].relative_to(cwd)} :#{ ex.line } " , :comment )
222
222
end
223
223
end
224
224
end
225
225
end
226
226
227
227
if cli.slowest
228
- puts
228
+ io. puts
229
229
results = results_for(:success ) + results_for(:fail )
230
230
top_n = results.sort_by { |res | - res.elapsed.not_nil!.to_f }[0 ..cli.slowest.not_nil!]
231
231
top_n_time = top_n.sum & .elapsed.not_nil!.total_seconds
232
232
percent = (top_n_time * 100 ) / elapsed_time.total_seconds
233
- puts " Top #{ cli.slowest } slowest examples (#{ top_n_time.humanize } seconds, #{ percent.round(2 ) } % of total time):"
233
+ io. puts " Top #{ cli.slowest } slowest examples (#{ top_n_time.humanize } seconds, #{ percent.round(2 ) } % of total time):"
234
234
top_n.each do |res |
235
- puts " #{ res.description } "
235
+ io. puts " #{ res.description } "
236
236
res_elapsed = res.elapsed.not_nil!.total_seconds.humanize
237
- puts " #{ res_elapsed.colorize.bold } seconds #{ Path [res.file].relative_to(cwd)} :#{ res.line } "
237
+ io. puts " #{ res_elapsed.colorize.bold } seconds #{ Path [res.file].relative_to(cwd)} :#{ res.line } "
238
238
end
239
239
end
240
240
241
- puts
241
+ io. puts
242
242
243
243
success = results_for(:success )
244
244
total = pendings.size + failures.size + errors.size + success.size
@@ -250,27 +250,27 @@ module Spec
250
250
else Status ::Success
251
251
end
252
252
253
- puts " Aborted!" .colorize.red if aborted
254
- puts " Finished in #{ Spec .to_human(elapsed_time)} "
255
- puts Spec .color(" #{ total } examples, #{ failures.size } failures, #{ errors.size } errors, #{ pendings.size } pending" , final_status)
256
- puts Spec .color(" Only running `focus: true`" , :focus ) if cli.focus?
253
+ io. puts " Aborted!" .colorize.red if aborted
254
+ io. puts " Finished in #{ Spec .to_human(elapsed_time)} "
255
+ io. puts Spec .color(" #{ total } examples, #{ failures.size } failures, #{ errors.size } errors, #{ pendings.size } pending" , final_status)
256
+ io. puts Spec .color(" Only running `focus: true`" , :focus ) if cli.focus?
257
257
258
258
unless failures_and_errors.empty?
259
- puts
260
- puts " Failed examples:"
261
- puts
259
+ io. puts
260
+ io. puts " Failed examples:"
261
+ io. puts
262
262
failures_and_errors.each do |fail |
263
- print Spec .color(" crystal spec #{ Path [fail.file].relative_to(cwd)} :#{ fail.line } " , :error )
264
- puts Spec .color(" # #{ fail.description } " , :comment )
263
+ io. print Spec .color(" crystal spec #{ Path [fail.file].relative_to(cwd)} :#{ fail.line } " , :error )
264
+ io. puts Spec .color(" # #{ fail.description } " , :comment )
265
265
end
266
266
end
267
267
268
- print_order_message
268
+ print_order_message(io)
269
269
end
270
270
271
- def print_order_message
271
+ def print_order_message (io : IO )
272
272
if randomizer_seed = cli.randomizer_seed
273
- puts Spec .color(" Randomized with seed: #{ randomizer_seed } " , :order )
273
+ io. puts Spec .color(" Randomized with seed: #{ randomizer_seed } " , :order )
274
274
end
275
275
end
276
276
0 commit comments