Class: TestProf::RSpecDissect::Listener
- Inherits:
-
Object
- Object
- TestProf::RSpecDissect::Listener
show all
- Includes:
- Logging
- Defined in:
- lib/test_prof/rspec_dissect/rspec.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
collapse
- NOTIFICATIONS =
i[
example_finished
example_group_finished
example_passed
example_failed
example_pending
].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.
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 25
def initialize
@before_results = Utils::SizedOrderedSet.new(
top_count, sort_by: :before
)
@memo_results = Utils::SizedOrderedSet.new(
top_count, sort_by: :memo
)
@examples_count = 0
@examples_time = 0.0
@total_examples_time = 0.0
end
|
Instance Method Details
#example_finished(notification) ⇒ Object
Also known as:
example_passed, example_failed, example_pending
37
38
39
40
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 37
def example_finished(notification)
@examples_count += 1
@examples_time += notification.example.execution_result.run_time
end
|
#example_group_finished(notification) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 47
def example_group_finished(notification)
return unless notification.group.top_level?
data = {}
data[:total] = @examples_time
data[:count] = @examples_count
data[:before] = RSpecDissect.before_time
data[:memo] = RSpecDissect.memo_time
data[:desc] = notification.group.top_level_description
data[:loc] = notification.group.metadata[:location]
@before_results << data
@memo_results << data
@total_examples_time += @examples_time
@examples_count = 0
@examples_time = 0.0
RSpecDissect.reset!
end
|
#print ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
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
113
114
115
116
117
118
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 68
def print
msgs = []
msgs <<
" RSpecDissect report\n\n Total time: \#{@total_examples_time.duration}\n Total `before(:each)` time: \#{RSpecDissect.total_before_time.duration}\n MSG\n\n msgs <<\n if RSpecDissect.memoization_available?\n \"Total `let` time: \#{RSpecDissect.total_memo_time.duration}\\n\\n\"\n else\n \"Total `let` time: NOT SUPPORTED (requires RSpec >= 3.3.0)\\n\\n\"\n end\n\n msgs <<\n <<-MSG.strip_heredoc\n Top \#{top_count} slowest suites (by `before(:each)` time):\n\n MSG\n\n @before_results.each do |group|\n msgs <<\n <<-GROUP.strip_heredoc\n \#{group[:desc].truncate} (\#{group[:loc]}) \u2013 \#{group[:before].duration} of \#{group[:total].duration} (\#{group[:count]})\n GROUP\n end\n\n if RSpecDissect.memoization_available?\n msgs <<\n <<-MSG.strip_heredoc\n\n Top \#{top_count} slowest suites (by `let` time):\n\n MSG\n\n @memo_results.each do |group|\n msgs <<\n <<-GROUP.strip_heredoc\n \#{group[:desc].truncate} (\#{group[:loc]}) \u2013 \#{group[:memo].duration} of \#{group[:total].duration} (\#{group[:count]})\n GROUP\n end\n end\n\n log :info, msgs.join\n\n stamp! if RSpecDissect.config.stamp?\nend\n".strip_heredoc
|
#stamp! ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/test_prof/rspec_dissect/rspec.rb', line 120
def stamp!
stamper = RSpecStamp::Stamper.new
examples = Hash.new { |h, k| h[k] = [] }
(@before_results.to_a + @memo_results.to_a)
.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 <<
" RSpec Stamp results\n\n Total patches: \#{stamper.total}\n Total files: \#{examples.keys.size}\n\n Failed patches: \#{stamper.failed}\n Ignored files: \#{stamper.ignored}\n MSG\n\n log :info, msgs.join\nend\n".strip_heredoc
|