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
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
161
162
163
|
# File 'lib/appmap/rspec.rb', line 161
def add_event_methods(event_methods)
@event_methods += event_methods
end
|
.begin_spec(example) ⇒ Object
146
147
148
|
# File 'lib/appmap/rspec.rb', line 146
def begin_spec(example)
@recordings_by_example[example.object_id] = Recording.new(example)
end
|
.config ⇒ Object
157
158
159
|
# File 'lib/appmap/rspec.rb', line 157
def config
@config or raise "AppMap is not configured"
end
|
.enabled? ⇒ Boolean
197
198
199
|
# File 'lib/appmap/rspec.rb', line 197
def enabled?
ENV['APPMAP'] == 'true'
end
|
.end_spec(example) ⇒ Object
150
151
152
153
154
155
|
# File 'lib/appmap/rspec.rb', line 150
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
140
141
142
143
144
|
# File 'lib/appmap/rspec.rb', line 140
def init
warn 'Configuring AppMap recorder for RSpec'
FileUtils.mkdir_p APPMAP_OUTPUT_DIR
end
|
12
13
14
|
# File 'lib/appmap/rspec.rb', line 12
def self.metadata
AppMap.detect_metadata
end
|
.print_inventory ⇒ Object
192
193
194
195
|
# File 'lib/appmap/rspec.rb', line 192
def print_inventory
class_map = AppMap.class_map(@event_methods)
save 'Inventory', class_map, labels: %w[inventory]
end
|
.run ⇒ Object
201
202
203
204
205
206
|
# File 'lib/appmap/rspec.rb', line 201
def run
init
at_exit do
print_inventory
end
end
|
.save(example_name, class_map, source_location, events: nil, labels: nil) ⇒ Object
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
|
# File 'lib/appmap/rspec.rb', line 165
def save(example_name, class_map, source_location, events: nil, labels: nil)
metadata = AppMap::RSpec.metadata.tap do |m|
m[:name] = example_name
m[:source_location] = source_location
m[:app] = AppMap.configuration.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 = AppMap::Util.scenario_filename(example_name)
File.write(File.join(APPMAP_OUTPUT_DIR, fname), JSON.generate(appmap))
end
|