Class: TestProf::TagProf::RSpecListener

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

Overview

:nodoc:

Constant Summary collapse

NOTIFICATIONS =
%i[
  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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/test_prof/tag_prof/rspec.rb', line 15

def initialize
  @printer = (ENV["TAG_PROF_FORMAT"] == "html") ? Printers::HTML : Printers::Simple

  @result =
    if ENV["TAG_PROF_EVENT"].nil?
      Result.new ENV["TAG_PROF"].to_sym
    else
      require "test_prof/event_prof"

      @events_profiler = EventProf.build(ENV["TAG_PROF_EVENT"])

      Result.new ENV["TAG_PROF"].to_sym, @events_profiler.events
    end

  log :info, "TagProf enabled (#{result.tag})"
end

Instance Attribute Details

#printerObject (readonly)

Returns the value of attribute printer.



13
14
15
# File 'lib/test_prof/tag_prof/rspec.rb', line 13

def printer
  @printer
end

#resultObject (readonly)

Returns the value of attribute result.



13
14
15
# File 'lib/test_prof/tag_prof/rspec.rb', line 13

def result
  @result
end

Instance Method Details

#example_finished(notification) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/test_prof/tag_prof/rspec.rb', line 38

def example_finished(notification)
  tag = notification.example..fetch(result.tag, :__unknown__)

  result.track(tag, time: TestProf.now - @ts, events: fetch_events_data)

  # reset and disable event profilers
  @events_profiler&.group_started(nil)
end

#example_started(_notification) ⇒ Object



32
33
34
35
36
# File 'lib/test_prof/tag_prof/rspec.rb', line 32

def example_started(_notification)
  @ts = TestProf.now
  # enable event profiling
  @events_profiler&.group_started(true)
end

#reportObject



47
48
49
# File 'lib/test_prof/tag_prof/rspec.rb', line 47

def report
  printer.dump(result)
end