Class: Minitest::Queue::TestData

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/queue/test_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test:, index:, namespace:, base_path:) ⇒ TestData

Returns a new instance of TestData.



10
11
12
13
14
15
# File 'lib/minitest/queue/test_data.rb', line 10

def initialize(test:, index:, namespace:, base_path:)
  @test = test
  @base_path = base_path
  @namespace = namespace
  @test_index = index
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/minitest/queue/test_data.rb', line 8

def namespace
  @namespace
end

#test_indexObject (readonly)

Returns the value of attribute test_index.



8
9
10
# File 'lib/minitest/queue/test_data.rb', line 8

def test_index
  @test_index
end

Instance Method Details

#error_classObject

Error class only considers failures wheras the other error fields also consider skips



93
94
95
96
97
# File 'lib/minitest/queue/test_data.rb', line 93

def error_class
  return nil unless @test.failure

  @test.failure.error.class.name
end

#error_file_numberObject



116
117
118
119
120
# File 'lib/minitest/queue/test_data.rb', line 116

def error_file_number
  return nil unless @test.failure

  error_location(@test.failure).last
end

#error_file_pathObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/minitest/queue/test_data.rb', line 105

def error_file_path
  return nil unless @test.failure

  path = error_location(@test.failure).first
  begin
    relative_path_for(path)
  rescue ArgumentError
    path # e.g. "(eval)" etc.
  end
end

#error_messageObject



99
100
101
102
103
# File 'lib/minitest/queue/test_data.rb', line 99

def error_message
  return nil unless @test.failure

  @test.failure.message
end

#parallel_worker_idObject

The parallel_worker_* fields are stamped by Minitest::Queue.stamp_parallel_worker_metadata in the worker process that ran the test. They are nil for embedders that don't produce them (results lacking the accessors, or no worker id configured).



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

def parallel_worker_id
  @test.parallel_worker_id if @test.respond_to?(:parallel_worker_id)
end

#parallel_worker_pidObject



88
89
90
# File 'lib/minitest/queue/test_data.rb', line 88

def parallel_worker_pid
  @test.parallel_worker_pid if @test.respond_to?(:parallel_worker_pid)
end

#parallel_worker_test_indexObject



84
85
86
# File 'lib/minitest/queue/test_data.rb', line 84

def parallel_worker_test_index
  @test.parallel_worker_test_index if @test.respond_to?(:parallel_worker_test_index)
end

#test_assertionsObject



47
48
49
# File 'lib/minitest/queue/test_data.rb', line 47

def test_assertions
  @test.assertions
end

#test_durationObject



51
52
53
# File 'lib/minitest/queue/test_data.rb', line 51

def test_duration
  @test.time || 0.0
end

#test_file_line_numberObject



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

def test_file_line_number
  @test.source_location.last
end

#test_file_pathObject



63
64
65
66
67
68
69
70
# File 'lib/minitest/queue/test_data.rb', line 63

def test_file_path
  path = @test.source_location.first
  begin
    relative_path_for(path)
  rescue ArgumentError
    path # e.g. "(eval)" etc.
  end
end

#test_finish_timestampObject



59
60
61
# File 'lib/minitest/queue/test_data.rb', line 59

def test_finish_timestamp
  @test.finish_timestamp
end

#test_idObject



17
18
19
# File 'lib/minitest/queue/test_data.rb', line 17

def test_id
  "#{test_suite}##{test_name}"
end

#test_nameObject



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

def test_name
  @test.name
end

#test_resultObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/minitest/queue/test_data.rb', line 33

def test_result
  if @test.passed?
    'success'
  elsif !@test.requeued? && @test.skipped?
    'skipped'
  elsif @test.error?
    'error'
  elsif @test.failure
    'failure'
  else
    'undefined'
  end
end

#test_retriedObject



29
30
31
# File 'lib/minitest/queue/test_data.rb', line 29

def test_retried
  @test.requeued?
end

#test_start_timestampObject



55
56
57
# File 'lib/minitest/queue/test_data.rb', line 55

def test_start_timestamp
  @test.start_timestamp
end

#test_suiteObject



25
26
27
# File 'lib/minitest/queue/test_data.rb', line 25

def test_suite
  @test.klass
end

#to_hObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/minitest/queue/test_data.rb', line 122

def to_h
  {
    namespace: namespace,
    test_id: test_id,
    test_name: test_name,
    test_suite: test_suite,
    test_result: test_result,
    test_index: test_index,
    test_result_ignored: @test.flaked?,
    test_retried: test_retried,
    test_assertions: test_assertions,
    test_duration: test_duration,
    test_start_timestamp: test_start_timestamp,
    test_finish_timestamp: test_finish_timestamp,
    test_file_path: test_file_path,
    test_file_line_number: test_file_line_number,
    parallel_worker_id: parallel_worker_id,
    parallel_worker_test_index: parallel_worker_test_index,
    parallel_worker_pid: parallel_worker_pid,
    error_class: error_class,
    error_message: error_message,
    error_file_path: error_file_path,
    error_file_number: error_file_number,
  }
end