141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/appmap/rspec.rb', line 141
def finish
warn "Finishing recording of example #{example}" if AppMap::RSpec::LOG
events = []
AppMap.tracing.delete @trace
events << @trace.next_event.to_h while @trace.event?
AppMap::RSpec.add_event_methods @trace.event_methods
class_map = AppMap.class_map(@trace.event_methods, include_source: false)
description = []
scope = ScopeExample.new(example)
feature_group = feature = nil
labels = []
while scope
labels += scope.labels
description << scope.description
feature ||= scope.feature
feature_group ||= scope.feature_group
scope = scope.parent
end
labels = labels.map(&:to_s).map(&:strip).reject(&:blank?).map(&:downcase).uniq
description.reject!(&:nil?).reject!(&:blank?)
default_description = description.last
description.reverse!
normalize = lambda do |desc|
desc.gsub('it should behave like', '')
.gsub(/Controller$/, '')
.gsub(/\s+/, ' ')
.strip
end
full_description = normalize.call(description.join(' '))
compute_feature_name = lambda do
return 'unknown' if description.empty?
feature_description = description.dup
num_tokens = [2, feature_description.length - 1].min
feature_description[0...num_tokens].map(&:strip).join(' ')
end
feature_group ||= normalize.call(default_description).underscore.gsub('/', '_').humanize
feature_name = feature || compute_feature_name.call if feature_group
feature_name = normalize.call(feature_name) if feature_name
AppMap::RSpec.save full_description,
class_map,
events: events,
feature_name: feature_name,
feature_group_name: feature_group,
labels: labels.blank? ? nil : labels
end
|