Module: Datadog::CI::Contrib::Minitest::Helpers

Defined in:
lib/datadog/ci/contrib/minitest/helpers.rb

Class Method Summary collapse

Class Method Details

.extract_source_location_from_class(klass) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 25

def self.extract_source_location_from_class(klass)
  return [] if klass.nil? || klass.name.nil?

  klass.const_source_location(klass.name)
rescue
  []
end

.parallel?(klass) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 20

def self.parallel?(klass)
  klass.ancestors.include?(::Minitest::Parallel::Test) ||
    (defined?(::Minitest::Queue) && ::Minitest.singleton_class.ancestors.include?(::Minitest::Queue))
end

.test_suite_name(klass, method_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 8

def self.test_suite_name(klass, method_name)
  source_location = extract_source_location_from_class(klass)&.first
  # if we are in anonymous class, fallback to the method source location
  if source_location.nil?
    source_location, = klass.instance_method(method_name).source_location
  end

  source_file_path = Pathname.new(source_location.to_s).relative_path_from(Pathname.pwd).to_s

  "#{klass.name} at #{source_file_path}"
end