class Minitest::Queue::TestData
Attributes
namespace[R]
test_index[R]
Public Class Methods
new(test:, index:, namespace:, base_path:)
click to toggle source
# 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
Public Instance Methods
error_class()
click to toggle source
Error class only considers failures wheras the other error fields also consider skips
# File lib/minitest/queue/test_data.rb, line 69 def error_class return nil unless @test.failure @test.failure.error.class.name end
error_file_number()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 88 def error_file_number return nil unless @test.failure error_location(@test.failure).last end
error_file_path()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 81 def error_file_path return nil unless @test.failure path = error_location(@test.failure).first relative_path_for(path) end
error_message()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 75 def error_message return nil unless @test.failure @test.failure.message end
test_assertions()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 47 def test_assertions @test.assertions end
test_duration()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 51 def test_duration @test.time end
test_file_line_number()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 64 def test_file_line_number @test.source_location.last end
test_file_path()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 55 def test_file_path path = @test.source_location.first begin relative_path_for(path) rescue ArgumentError path # e.g. "(eval)" etc. end end
test_id()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 17 def test_id "#{test_suite}##{test_name}" end
test_name()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 21 def test_name @test.name end
test_result()
click to toggle source
# 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_retried()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 29 def test_retried @test.requeued? end
test_suite()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 25 def test_suite @test.klass end
to_h()
click to toggle source
# File lib/minitest/queue/test_data.rb, line 94 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_file_path: test_file_path, test_file_line_number: test_file_line_number, error_class: error_class, error_message: error_message, error_file_path: error_file_path, error_file_number: error_file_number, } end
Private Instance Methods
error_location(exception)
click to toggle source
# File lib/minitest/queue/test_data.rb, line 123 def error_location(exception) @error_location ||= begin last_before_assertion = '' exception.backtrace.reverse_each do |s| break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/ last_before_assertion = s end path = last_before_assertion.sub(/:in .*$/, '') # the path includes the linenumber at the end, # which is seperated by a : # rpartition splits the string at the last occurence of : result = path.rpartition(':') # We return [path, linenumber] here [result.first, result.last.to_i] end end
relative_path_for(path)
click to toggle source
# File lib/minitest/queue/test_data.rb, line 117 def relative_path_for(path) file_path = Pathname.new(path) base_path = Pathname.new(@base_path) file_path.relative_path_from(base_path) end