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

Class Method Details

.add_event_methods(event_methods) ⇒ Object



98
99
100
# File 'lib/appmap/minitest.rb', line 98

def add_event_methods(event_methods)
  @event_methods += event_methods
end

.begin_test(test, name) ⇒ Object



80
81
82
83
84
85
# File 'lib/appmap/minitest.rb', line 80

def begin_test(test, name)
  AppMap.info 'Configuring AppMap recorder for Minitest' if first_recording?
  @recording_count += 1

  @recordings_by_test[test.object_id] = Recording.new(test, name)
end

.configObject



94
95
96
# File 'lib/appmap/minitest.rb', line 94

def config
  @config or raise 'AppMap is not configured'
end

.enabled?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/appmap/minitest.rb', line 134

def enabled?
  AppMap.recording_enabled?(:minitest)
end

.end_test(test, exception:) ⇒ Object



87
88
89
90
91
92
# File 'lib/appmap/minitest.rb', line 87

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
end

.first_recording?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/appmap/minitest.rb', line 76

def first_recording?
  @recording_count == 0
end

.initObject



72
73
74
# File 'lib/appmap/minitest.rb', line 72

def init
  FileUtils.mkdir_p APPMAP_OUTPUT_DIR
end

.metadataObject



16
17
18
# File 'lib/appmap/minitest.rb', line 16

def self.
  AppMap.
end

.runObject



138
139
140
# File 'lib/appmap/minitest.rb', line 138

def run
  init
end

.save(name:, class_map:, source_location:, test_status:, test_failure:, exception:, events:) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/appmap/minitest.rb', line 102

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
    if exception
      m[:exception] = Util.format_exception(exception)
    end
  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