Class: TestProf::RSpecStamp::RSpecListener

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

Overview

:nodoc:

Constant Summary collapse

NOTIFICATIONS =
%i[
  example_failed
].freeze

Constants included from Logging

Logging::COLORS

Instance Method Summary collapse

Methods included from Logging

#log

Constructor Details

#initializeRSpecListener

Returns a new instance of RSpecListener.



12
13
14
15
16
17
# File 'lib/test_prof/rspec_stamp/rspec.rb', line 12

def initialize
  @failed = 0
  @ignored = 0
  @total = 0
  @examples = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#example_failed(notification) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/test_prof/rspec_stamp/rspec.rb', line 19

def example_failed(notification)
  return if notification.example.pending?

  location = notification.example.[:location]

  file, line = location.split(":")

  @examples[file] << line.to_i
end

#stamp!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/test_prof/rspec_stamp/rspec.rb', line 29

def stamp!
  stamper = Stamper.new

  @examples.each do |file, lines|
    stamper.stamp_file(file, lines.uniq)
  end

  msgs = []

  msgs <<
    <<~MSG
      RSpec Stamp results

      Total patches: #{stamper.total}
      Total files: #{@examples.keys.size}

      Failed patches: #{stamper.failed}
      Ignored files: #{stamper.ignored}
    MSG

  log :info, msgs.join
end