Class: AppMap::Minitest::Recording

Inherits:
Struct
  • Object
show all
Defined in:
lib/appmap/minitest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test, test_name) ⇒ Recording

Returns a new instance of Recording.



22
23
24
25
26
27
# File 'lib/appmap/minitest.rb', line 22

def initialize(test, test_name)
  super

  warn "Starting recording of test #{test.class}.#{test.name}@#{source_location}" if AppMap::Minitest::LOG
  @trace = AppMap.tracing.trace
end

Instance Attribute Details

#testObject

Returns the value of attribute test

Returns:

  • (Object)

    the current value of test



21
22
23
# File 'lib/appmap/minitest.rb', line 21

def test
  @test
end

#test_nameObject

Returns the value of attribute test_name

Returns:

  • (Object)

    the current value of test_name



21
22
23
# File 'lib/appmap/minitest.rb', line 21

def test_name
  @test_name
end

Instance Method Details

#finish(failures, exception) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/appmap/minitest.rb', line 34

def finish(failures, exception)
  failed = failures.any? || exception
  if AppMap::Minitest::LOG
    warn "Finishing recording of #{failed ? "failed " : ""} test #{test.class}.#{test.name}"
  end
  warn "Exception: #{exception}" if exception && AppMap::Minitest::LOG

  if failed
    failure_exception = failures.first || exception
    warn "Failure exception: #{failure_exception}" if AppMap::Minitest::LOG
    test_failure = Util.extract_test_failure(failure_exception)
  end

  events = []
  AppMap.tracing.delete @trace

  events << @trace.next_event.to_h while @trace.event?

  AppMap::Minitest.add_event_methods @trace.event_methods

  class_map = AppMap.class_map(@trace.event_methods)

  feature_group = test.class.name.underscore.split("_")[0...-1].join("_").capitalize
  feature_name = test.name.split("_")[1..-1].join(" ")
  scenario_name = [feature_group, feature_name].join(" ")

  AppMap::Minitest.save name: scenario_name,
    class_map: class_map,
    source_location: source_location,
    test_status: failed ? "failed" : "succeeded",
    test_failure: test_failure,
    exception: exception,
    events: events
end

#source_locationObject



29
30
31
32
# File 'lib/appmap/minitest.rb', line 29

def source_location
  location = test.method(test_name).source_location
  [Util.normalize_path(location.first), location.last].join(":")
end