Module: Datadog::CI::Contrib::Minitest::Helpers
- Defined in:
- lib/datadog/ci/contrib/minitest/helpers.rb
Defined Under Namespace
Modules: RunnableClassMethods
Class Method Summary
collapse
Class Method Details
.ci_queue? ⇒ Boolean
103
104
105
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 103
def self.ci_queue?
!!(defined?(::Minitest::Queue) && ::Minitest.singleton_class.ancestors.include?(::Minitest::Queue))
end
|
.empty_source_location_to_nil(source_location) ⇒ Object
120
121
122
123
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 120
def self.empty_source_location_to_nil(source_location)
return nil if source_location.nil? || source_location.empty?
source_location
end
|
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 83
def self.(klass, method_name)
method_source_location = (klass, method_name)
klass_source_location = (klass)
if defined?(::Minitest::Spec) && klass&.ancestors&.include?(::Minitest::Spec)
method_source_location || klass_source_location
else
klass_source_location || method_source_location
end
end
|
113
114
115
116
117
118
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 113
def self.(klass, method_name)
return nil if klass.nil?
return nil if method_name.nil? || method_name.empty?
empty_source_location_to_nil(klass.instance_method(method_name).source_location)
end
|
.parallel?(klass) ⇒ Boolean
99
100
101
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 99
def self.parallel?(klass)
klass.ancestors.include?(::Minitest::Parallel::Test) || ci_queue?
end
|
.skip_test_suite(test_suite) ⇒ Object
94
95
96
97
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 94
def self.skip_test_suite(test_suite)
test_suite&.finish
[]
end
|
.start_test_suite(klass) ⇒ Object
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
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 35
def self.start_test_suite(klass)
method = klass.runnable_methods.first
return nil if method.nil?
test_suite_name = test_suite_name(klass, method)
source_file, line_number = (klass, method)
test_suite_tags = if source_file
{
CI::Ext::Test::TAG_SOURCE_FILE => (Git::LocalRepository.relative_to_root(source_file) if source_file),
CI::Ext::Test::TAG_SOURCE_START => line_number&.to_s
}
else
{}
end
if klass.dd_any_unskippable?
test_suite_tags[CI::Ext::Test::TAG_ITR_UNSKIPPABLE] = "true"
end
test_tracing_component = Datadog.send(:components).test_tracing
test_suite = test_tracing_component.start_test_suite(
test_suite_name,
tags: test_suite_tags
)
test_suite&.set_expected_tests!(klass.runnable_methods)
test_suite
end
|
.test_suite_name(klass, method_name) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 64
def self.test_suite_name(klass, method_name)
source_location = (klass, method_name)&.first
source_file_path = Pathname.new(source_location.to_s)
if source_file_path.absolute?
source_file_path = source_file_path.relative_path_from(Pathname.pwd).to_s
end
"#{klass.name} at #{source_file_path}"
end
|