Class: XSpec::Notifier::TimingsAtEnd

Inherits:
Object
  • Object
show all
Includes:
Composable, EmptyFormatter
Defined in:
lib/xspec/notifiers.rb

Overview

Renders a histogram of test durations after the entire run is complete.

Constant Summary collapse

DEFAULT_SPLITS =
[0.001, 0.005, 0.01, 0.1, 1.0, Float::INFINITY]

Instance Method Summary collapse

Methods included from Composable

#+

Methods included from EmptyFormatter

#evaluate_start, #run_start

Constructor Details

#initialize(out: $stdout, splits: DEFAULT_SPLITS, width: 20) ⇒ TimingsAtEnd

Returns a new instance of TimingsAtEnd.



93
94
95
96
97
98
99
100
101
# File 'lib/xspec/notifiers.rb', line 93

def initialize(out:    $stdout,
               splits: DEFAULT_SPLITS,
               width:  20)

  @timings = {}
  @splits  = splits
  @width   = width
  @out     = out
end

Instance Method Details

#evaluate_finish(result) ⇒ Object



103
104
105
# File 'lib/xspec/notifiers.rb', line 103

def evaluate_finish(result)
  timings[result] = result.duration
end

#run_finishObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/xspec/notifiers.rb', line 107

def run_finish
  buckets = bucket_from_splits(timings, splits)
  max     = buckets.values.max

  out.puts "           Timings:"
  buckets.each do |(split, count)|
    label = split.infinite? ? "" : split

    out.puts "    %6s %-#{width}s %i" % [
      label,
      '#' * (count / max.to_f * width.to_f).ceil,
      count
    ]
  end
  out.puts

  true
end