Class: TestProf::EventProf::RSpecListener

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/test_prof/event_prof/rspec.rb

Overview

:nodoc:

Constant Summary collapse

NOTIFICATIONS =
i[
  example_group_started
  example_group_finished
  example_started
  example_finished
].freeze

Constants included from Logging

Logging::COLORS

Instance Method Summary collapse

Methods included from Logging

#build_log_msg, #colorize, #log

Constructor Details

#initializeRSpecListener

Returns a new instance of RSpecListener.



22
23
24
# File 'lib/test_prof/event_prof/rspec.rb', line 22

def initialize
  @profiler = EventProf.build
end

Instance Method Details

#example_finished(notification) ⇒ Object



40
41
42
# File 'lib/test_prof/event_prof/rspec.rb', line 40

def example_finished(notification)
  @profiler.example_finished notification.example
end

#example_group_finished(notification) ⇒ Object



31
32
33
34
# File 'lib/test_prof/event_prof/rspec.rb', line 31

def example_group_finished(notification)
  return unless notification.group.top_level?
  @profiler.group_finished notification.group
end

#example_group_started(notification) ⇒ Object



26
27
28
29
# File 'lib/test_prof/event_prof/rspec.rb', line 26

def example_group_started(notification)
  return unless notification.group.top_level?
  @profiler.group_started notification.group
end

#example_started(notification) ⇒ Object



36
37
38
# File 'lib/test_prof/event_prof/rspec.rb', line 36

def example_started(notification)
  @profiler.example_started notification.example
end


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/test_prof/event_prof/rspec.rb', line 44

def print
  result = @profiler.results

  msgs = []

  msgs <<
    "      EventProf results for \#{@profiler.event}\n\n      Total time: \#{@profiler.total_time.duration}\n      Total events: \#{@profiler.total_count}\n\n      Top \#{@profiler.top_count} slowest suites (by \#{@profiler.rank_by}):\n\n    MSG\n\n  result[:groups].each do |group|\n    description = group[:id].top_level_description\n    location = group[:id].metadata[:location]\n\n    msgs <<\n      <<-GROUP.strip_heredoc\n        \#{description.truncate} (\#{location}) \u2013 \#{group[:time].duration} (\#{group[:count]} / \#{group[:examples]})\n      GROUP\n  end\n\n  if result[:examples]\n    msgs << \"\\nTop \#{@profiler.top_count} slowest tests (by \#{@profiler.rank_by}):\\n\\n\"\n\n    result[:examples].each do |example|\n      description = example[:id].description\n      location = example[:id].metadata[:location]\n      msgs <<\n        <<-GROUP.strip_heredoc\n          \#{description.truncate} (\#{location}) \u2013 \#{example[:time].duration} (\#{example[:count]})\n        GROUP\n    end\n  end\n\n  log :info, msgs.join\nend\n".strip_heredoc