Module: AppMap::Minitest
- Defined in:
- lib/appmap/minitest.rb
Overview
Integration of AppMap with Minitest. When enabled with APPMAP=true, the AppMap tracer will be activated around each test.
Defined Under Namespace
Classes: Recording
Constant Summary collapse
- APPMAP_OUTPUT_DIR =
'tmp/appmap/minitest'- LOG =
( ENV['APPMAP_DEBUG'] == 'true' || ENV['DEBUG'] == 'true' )
Class Method Summary collapse
- .add_event_methods(event_methods) ⇒ Object
- .begin_test(test, name) ⇒ Object
- .config ⇒ Object
- .enabled? ⇒ Boolean
- .end_test(test) ⇒ Object
- .init ⇒ Object
- .metadata ⇒ Object
- .print_inventory ⇒ Object
- .run ⇒ Object
- .save(example_name, class_map, source_location, events: nil, labels: nil) ⇒ Object
Class Method Details
.add_event_methods(event_methods) ⇒ Object
77 78 79 |
# File 'lib/appmap/minitest.rb', line 77 def add_event_methods(event_methods) @event_methods += event_methods end |
.begin_test(test, name) ⇒ Object
62 63 64 |
# File 'lib/appmap/minitest.rb', line 62 def begin_test(test, name) @recordings_by_test[test.object_id] = Recording.new(test, name) end |
.config ⇒ Object
73 74 75 |
# File 'lib/appmap/minitest.rb', line 73 def config @config or raise "AppMap is not configured" end |
.enabled? ⇒ Boolean
112 113 114 |
# File 'lib/appmap/minitest.rb', line 112 def enabled? ENV['APPMAP'] == 'true' end |
.end_test(test) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/appmap/minitest.rb', line 66 def end_test(test) recording = @recordings_by_test.delete(test.object_id) return warn "No recording found for #{test}" unless recording recording.finish end |
.init ⇒ Object
56 57 58 59 60 |
# File 'lib/appmap/minitest.rb', line 56 def init warn 'Configuring AppMap recorder for Minitest' FileUtils.mkdir_p APPMAP_OUTPUT_DIR end |
.metadata ⇒ Object
12 13 14 |
# File 'lib/appmap/minitest.rb', line 12 def self. AppMap. end |
.print_inventory ⇒ Object
107 108 109 110 |
# File 'lib/appmap/minitest.rb', line 107 def print_inventory class_map = AppMap.class_map(@event_methods) save 'Inventory', class_map, labels: %w[inventory] end |
.run ⇒ Object
116 117 118 119 120 121 |
# File 'lib/appmap/minitest.rb', line 116 def run init at_exit do print_inventory end end |
.save(example_name, class_map, source_location, events: nil, labels: nil) ⇒ Object
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 |
# File 'lib/appmap/minitest.rb', line 81 def save(example_name, class_map, source_location, events: nil, labels: nil) = AppMap::Minitest..tap do |m| m[:name] = example_name m[:source_location] = source_location m[:app] = AppMap.configuration.name m[:frameworks] ||= [] m[:frameworks] << { name: 'minitest', version: Gem.loaded_specs['minitest']&.version&.to_s } m[:recorder] = { name: 'minitest' } end appmap = { version: AppMap::APPMAP_FORMAT_VERSION, 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 |