class Turn::ToptenDecorator

Public Class Methods

new(reporter) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 5
def initialize(reporter)
  @reporter = reporter
end

Public Instance Methods

finish_suite(suite) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 28
def finish_suite(suite)
  @reporter.finish_suite(suite)
  io.puts
  io.puts Colorize.bold("Top 10 Longest Running Tests")
  top_ten_times.each do |(test_name, time)|
    io.print format_time(time)
    io.puts format_test_name(test_name, time)
  end
  io.puts
end
finish_test(test) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 23
def finish_test(test)
  @reporter.finish_test(test)
  test_time_data[test_key(test)][:end] = Time.now
end
method_missing(m,*args,&block) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 9
def method_missing(m,*args,&block)
  @reporter.send(m,*args,&block)
end
start_case(kase) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 13
def start_case(kase)
  @reporter.start_case(kase)
  @top_ten_current_case = kase
end
start_test(test) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 18
def start_test(test)
  @reporter.start_test(test)
  test_time_data[test_key(test)] = {:start => Time.now}
end

Private Instance Methods

format_test_name(test_name, time) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 61
def format_test_name(test_name, time)
  test_name.tabto(11-time.to_s.length)
end
format_time(time) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 57
def format_time(time)
  Colorize.blue(time)
end
test_key(test) click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 41
def test_key(test)
  "#{@top_ten_current_case.name} #{test}"
end
test_time_data() click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 53
def test_time_data
  @test_time_data ||= {}
end
test_times() click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 49
def test_times
  test_time_data.map {|(test, times)| [test, times[:end] - times[:start]]}
end
top_ten_times() click to toggle source
# File lib/turn/decorators/topten_decorator.rb, line 45
def top_ten_times
  test_times.sort_by {|(_, time)| -time}.take(10)
end