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 =
false

Class Method Summary collapse

Class Method Details

.add_event_methods(event_methods) ⇒ Object



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

def add_event_methods(event_methods)
  @event_methods += event_methods
end

.begin_test(test) ⇒ Object



58
59
60
# File 'lib/appmap/minitest.rb', line 58

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

.configObject



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

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

.enabled?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/appmap/minitest.rb', line 109

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

.end_test(test) ⇒ Object



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

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

  recording.finish
end

.initObject



52
53
54
55
56
# File 'lib/appmap/minitest.rb', line 52

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


104
105
106
107
# File 'lib/appmap/minitest.rb', line 104

def print_inventory
  class_map = AppMap.class_map(@event_methods)
  save 'Inventory', class_map, labels: %w[inventory]
end

.runObject



113
114
115
116
117
118
# File 'lib/appmap/minitest.rb', line 113

def run
  init
  at_exit do
    print_inventory
  end
end

.save(example_name, class_map, events: nil, feature_name: nil, feature_group_name: nil, labels: nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/appmap/minitest.rb', line 77

def save(example_name, class_map, events: nil, feature_name: nil, feature_group_name: nil, labels: nil)
   = AppMap::Minitest..tap do |m|
    m[:name] = example_name
    m[:app] = AppMap.configuration.name
    m[:feature] = feature_name if feature_name
    m[:feature_group] = feature_group_name if feature_group_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