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_passed
example_failed
].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
Also known as:
example_passed, example_failed
33
34
35
36
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 33
def example_finished(notification)
@examples_count += 1
@examples_time += notification.example.execution_result.run_time
end
|
#example_group_finished(notification) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 41
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 60
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
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
113
114
115
116
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 85
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
|