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_failed
  example_passed
].freeze

Constants included from Logging

Logging::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#build_log_msg, #colorize, #log

Constructor Details

#initializeRSpecListener

Returns a new instance of RSpecListener.



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

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.



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

def printer
  @printer
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#example_finished(notification) ⇒ Object Also known as: example_passed, example_failed



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

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



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

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

#reportObject



52
53
54
# File 'lib/test_prof/tag_prof/rspec.rb', line 52

def report
  printer.dump(result)
end