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



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

def add_event_methods(event_methods)
  @event_methods += event_methods
end

.begin_test(test, name) ⇒ Object



65
66
67
# File 'lib/appmap/minitest.rb', line 65

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

.configObject



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

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

.enabled?Boolean



117
118
119
# File 'lib/appmap/minitest.rb', line 117

def enabled?
  ENV['APPMAP'] == 'true'
end

.end_test(test, exception:) ⇒ Object



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

def end_test(test, exception:)
  recording = @recordings_by_test.delete(test.object_id)
  return warn "No recording found for #{test}" unless recording

  recording.finish exception
end

.initObject



59
60
61
62
63
# File 'lib/appmap/minitest.rb', line 59

def init
  warn 'Configuring AppMap recorder for Minitest'

  FileUtils.mkdir_p APPMAP_OUTPUT_DIR
end

.metadataObject



12
13
14
# File 'lib/appmap/minitest.rb', line 12

def self.
  AppMap.
end

.runObject



121
122
123
# File 'lib/appmap/minitest.rb', line 121

def run
  init
end

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/appmap/minitest.rb', line 84

def save(name:, class_map:, source_location:, test_status:, 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'
    }
    m[:test_status] = test_status
    if exception
      m[:exception] = {
        class: exception.class.name,
        message: AppMap::Event::MethodEvent.display_string(exception.to_s)
      }
    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), JSON.generate(appmap))
end