changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/lib/spec/runner/formatter/profile_formatter.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require 'spec/runner/formatter/progress_bar_formatter'
2
3module Spec
4 module Runner
5 module Formatter
6 class ProfileFormatter < ProgressBarFormatter
7
8 def initialize(options, where)
9 super
10 @example_times = []
11 end
12
13 def start(count)
14 @output.puts "Profiling enabled."
15 end
16
17 def example_started(example)
18 @time = Time.now
19 end
20
21 def example_passed(example)
22 super
23 @example_times << [
24 example_group.description,
25 example.description,
26 Time.now - @time
27 ]
28 end
29
30 def start_dump
31 super
32 @output.puts "\n\nTop 10 slowest examples:\n"
33
34 @example_times = @example_times.sort_by do |description, example, time|
35 time
36 end.reverse
37
38 @example_times[0..9].each do |description, example, time|
39 @output.print red(sprintf("%.7f", time))
40 @output.puts " #{description} #{example}"
41 end
42 @output.flush
43 end
44 end
45 end
46 end
47end