Class: TestProf::TPSProf::RSpecListener

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/test_prof/tps_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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log

Constructor Details

#initializeRSpecListener

Returns a new instance of RSpecListener.



17
18
19
20
21
22
# File 'lib/test_prof/tps_prof/rspec.rb', line 17

def initialize
  @profiler = Profiler.new(TPSProf.config.top_count, threshold: TPSProf.config.threshold)
  @reporter = TPSProf.config.reporter

  log :info, "TPSProf enabled (top-#{TPSProf.config.top_count})"
end

Instance Attribute Details

#profilerObject (readonly)

Returns the value of attribute profiler.



15
16
17
# File 'lib/test_prof/tps_prof/rspec.rb', line 15

def profiler
  @profiler
end

#reporterObject (readonly)

Returns the value of attribute reporter.



15
16
17
# File 'lib/test_prof/tps_prof/rspec.rb', line 15

def reporter
  @reporter
end

Instance Method Details

#example_finished(notification) ⇒ Object



38
39
40
# File 'lib/test_prof/tps_prof/rspec.rb', line 38

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

#example_group_finished(notification) ⇒ Object



29
30
31
32
# File 'lib/test_prof/tps_prof/rspec.rb', line 29

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

#example_group_started(notification) ⇒ Object



24
25
26
27
# File 'lib/test_prof/tps_prof/rspec.rb', line 24

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

#example_started(notification) ⇒ Object



34
35
36
# File 'lib/test_prof/tps_prof/rspec.rb', line 34

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


42
43
44
# File 'lib/test_prof/tps_prof/rspec.rb', line 42

def print
  reporter.print(profiler)
end