Class: TestProf::RSpecDissect::Listener
- Inherits:
-
Object
- Object
- TestProf::RSpecDissect::Listener
show all
- Includes:
- Logging
- Defined in:
- lib/test_prof/rspec_dissect/rspec.rb
Overview
Constant Summary
collapse
- NOTIFICATIONS =
%i[
example_group_finished
example_finished
].freeze
Constants included
from Logging
Logging::COLORS
Instance Method Summary
collapse
Methods included from Logging
#build_log_msg, #colorize, #log
Constructor Details
Returns a new instance of Listener.
Instance Method Details
#example_finished(notification) ⇒ Object
32
33
34
35
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 32
def example_finished(notification)
@examples_count += 1
@examples_time += notification.example.execution_result.run_time
end
|
#example_group_finished(notification) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 37
def example_group_finished(notification)
return unless notification.group.top_level?
data = {}
data[:total] = @examples_time
data[:count] = @examples_count
data[:desc] = notification.group.top_level_description
data[:loc] = notification.group.metadata[:location]
collectors.each { |c| c.populate!(data) }
collectors.each { |c| c << data }
@total_examples_time += @examples_time
@examples_count = 0
@examples_time = 0.0
RSpecDissect.reset!
end
|
#print ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 56
def print
msgs = []
msgs <<
<<~MSG
RSpecDissect report
Total time: #{@total_examples_time.duration}
MSG
collectors.each do |c|
msgs << c.total_time_message
end
msgs << "\n"
collectors.each do |c|
msgs << c.print_results
end
log :info, msgs.join
stamp! if RSpecDissect.config.stamp?
end
|
#stamp! ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 81
def stamp!
stamper = RSpecStamp::Stamper.new
examples = Hash.new { |h, k| h[k] = [] }
all_results = collectors.inject([]) { |acc, c| acc + c.results.to_a }
all_results
.map { |obj| obj[:loc] }.each do |location|
file, line = location.split(":")
examples[file] << line.to_i
end
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
|