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

#build_log_msg, #colorize, #log

Constructor Details

#initializeRSpecListener

Returns a new instance of RSpecListener.



15
16
17
18
19
20
# File 'lib/test_prof/rspec_stamp/rspec.rb', line 15

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

Instance Method Details

#example_failed(notification) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/test_prof/rspec_stamp/rspec.rb', line 22

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



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

def stamp!
  stamper = Stamper.new

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

  msgs = []

  msgs <<
    <<-MSG.strip_heredoc
      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