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 =
File.join(AppMap.output_dir, "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
- .disabled_by_tag(test, name) ⇒ Object
- .enabled? ⇒ Boolean
- .end_test(test, exception:) ⇒ Object
- .first_recording? ⇒ Boolean
- .init ⇒ Object
- .metadata ⇒ Object
- .run ⇒ Object
- .save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:) ⇒ Object
Class Method Details
.add_event_methods(event_methods) ⇒ Object
112 113 114 |
# File 'lib/appmap/minitest.rb', line 112 def add_event_methods(event_methods) @event_methods += event_methods end |
.begin_test(test, name) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/appmap/minitest.rb', line 83 def begin_test(test, name) AppMap::DetectEnabled.discourage_conflicting_recording_methods :minitest if first_recording? @recording_count += 1 recording = if defined?(::Minitest::Tagz) && disabled_by_tag(test, name) :disabled else Recording.new(test, name) end @recordings_by_test[test.object_id] = recording end |
.config ⇒ Object
108 109 110 |
# File 'lib/appmap/minitest.rb', line 108 def config @config or raise "AppMap is not configured" end |
.disabled_by_tag(test, name) ⇒ Object
96 97 98 99 |
# File 'lib/appmap/minitest.rb', line 96 def disabled_by_tag(test, name) = ::Minitest::Tagz.tag_map[::Minitest::Tagz.serialize(test.class, name)] && .include?("noappmap") end |
.enabled? ⇒ Boolean
146 147 148 |
# File 'lib/appmap/minitest.rb', line 146 def enabled? AppMap.recording_enabled?(:minitest) end |
.end_test(test, exception:) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/appmap/minitest.rb', line 101 def end_test(test, exception:) recording = @recordings_by_test.delete(test.object_id) return warn "No recording found for #{test}" unless recording recording.finish test.failures || [], exception unless recording == :disabled end |
.first_recording? ⇒ Boolean
79 80 81 |
# File 'lib/appmap/minitest.rb', line 79 def first_recording? @recording_count == 0 end |
.init ⇒ Object
75 76 77 |
# File 'lib/appmap/minitest.rb', line 75 def init FileUtils.mkdir_p APPMAP_OUTPUT_DIR end |
.run ⇒ Object
150 151 152 |
# File 'lib/appmap/minitest.rb', line 150 def run init end |
.save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:) ⇒ Object
116 117 118 119 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 |
# File 'lib/appmap/minitest.rb', line 116 def save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:) = AppMap::Minitest..tap do |m| m[:name] = 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", type: "tests" } m[:test_status] = test_status m[:test_failure] = test_failure if test_failure m[:exception] = Util.format_exception(exception) if exception end appmap = { version: AppMap::APPMAP_FORMAT_VERSION, metadata: , classMap: class_map, events: events }.compact fname = AppMap::Util.scenario_filename(name) AppMap::Util.write_appmap(File.join(APPMAP_OUTPUT_DIR, fname), appmap) end |