1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
# frozen_string_literal: true
module TestProf
module RSpecStamp
class RSpecListener # :nodoc:
include Logging
NOTIFICATIONS = %i[
example_failed
].freeze
def initialize
@failed = 0
@ignored = 0
@total = 0
@examples = Hash.new { |h, k| h[k] = [] }
end
def example_failed(notification)
return if notification.example.pending?
location = notification.example.metadata[:location]
file, line = location.split(":")
@examples[file] << line.to_i
end
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
end
end
end
# Register EventProf listener
TestProf.activate("RSTAMP") do
RSpec.configure do |config|
listener = nil
config.before(:suite) do
listener = TestProf::RSpecStamp::RSpecListener.new
config.reporter.register_listener(
listener, *TestProf::RSpecStamp::RSpecListener::NOTIFICATIONS
)
end
config.after(:suite) { listener&.stamp! }
end
end
|