Module: AppMap::RSpec
- Defined in:
- lib/appmap/rspec.rb
Overview
Integration of AppMap with RSpec. When enabled with APPMAP=true, the AppMap tracer will be activated around each scenario which has the metadata key :appmap.
Defined Under Namespace
Modules: FeatureAnnotations
Classes: Recording, ScopeExample, ScopeExampleGroup
Constant Summary
collapse
- APPMAP_OUTPUT_DIR =
'tmp/appmap/rspec'
- LOG =
false
Class Method Summary
collapse
Class Method Details
.add_event_methods(event_methods) ⇒ Object
212
213
214
|
# File 'lib/appmap/rspec.rb', line 212
def add_event_methods(event_methods)
@event_methods += event_methods
end
|
.begin_spec(example) ⇒ Object
197
198
199
|
# File 'lib/appmap/rspec.rb', line 197
def begin_spec(example)
@recordings_by_example[example.object_id] = Recording.new(example)
end
|
.config ⇒ Object
208
209
210
|
# File 'lib/appmap/rspec.rb', line 208
def config
@config or raise "AppMap is not configured"
end
|
.enabled? ⇒ Boolean
249
250
251
|
# File 'lib/appmap/rspec.rb', line 249
def enabled?
ENV['APPMAP'] == 'true'
end
|
.end_spec(example) ⇒ Object
201
202
203
204
205
206
|
# File 'lib/appmap/rspec.rb', line 201
def end_spec(example)
recording = @recordings_by_example.delete(example.object_id)
return warn "No recording found for #{example}" unless recording
recording.finish
end
|
.init ⇒ Object
187
188
189
190
191
192
193
194
195
|
# File 'lib/appmap/rspec.rb', line 187
def init
warn 'Configuring AppMap recorder for RSpec'
FileUtils.mkdir_p APPMAP_OUTPUT_DIR
require 'appmap/hook'
@config = AppMap.configure
AppMap::Hook.hook(@config)
end
|
10
11
12
13
14
15
|
# File 'lib/appmap/rspec.rb', line 10
def self.metadata
require 'appmap/command/record'
@metadata ||= AppMap::Command::Record.detect_metadata
@metadata.freeze
@metadata.deep_dup
end
|
.print_inventory ⇒ Object
244
245
246
247
|
# File 'lib/appmap/rspec.rb', line 244
def print_inventory
class_map = AppMap.class_map(@config, @event_methods)
save 'Inventory', class_map, labels: %w[inventory]
end
|
.run ⇒ Object
253
254
255
256
257
258
|
# File 'lib/appmap/rspec.rb', line 253
def run
init
at_exit do
print_inventory
end
end
|
.save(example_name, class_map, events: nil, feature_name: nil, feature_group_name: nil, labels: nil) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/appmap/rspec.rb', line 216
def save(example_name, class_map, events: nil, feature_name: nil, feature_group_name: nil, labels: nil)
metadata = RSpec.metadata.tap do |m|
m[:name] = example_name
m[:app] = @config.name
m[:feature] = feature_name if feature_name
m[:feature_group] = feature_group_name if feature_group_name
m[:labels] = labels if labels
m[:frameworks] ||= []
m[:frameworks] << {
name: 'rspec',
version: Gem.loaded_specs['rspec-core']&.version&.to_s
}
m[:recorder] = {
name: 'rspec'
}
end
appmap = {
version: AppMap::APPMAP_FORMAT_VERSION,
metadata: metadata,
classMap: class_map,
events: events
}.compact
fname = sanitize_filename(example_name)
File.write(File.join(APPMAP_OUTPUT_DIR, "#{fname}.appmap.json"), JSON.generate(appmap))
end
|