Module: Datadog::CI::Contrib::Minitest::Helpers
- Defined in:
- lib/datadog/ci/contrib/minitest/helpers.rb
Class Method Summary collapse
- .extract_source_location_from_class(klass) ⇒ Object
- .parallel?(klass) ⇒ Boolean
- .start_test_suite(klass) ⇒ Object
- .test_suite_name(klass, method_name) ⇒ Object
Class Method Details
.extract_source_location_from_class(klass) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 51 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
46 47 48 49 |
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 46 def self.parallel?(klass) klass.ancestors.include?(::Minitest::Parallel::Test) || (defined?(::Minitest::Queue) && ::Minitest.singleton_class.ancestors.include?(::Minitest::Queue)) end |
.start_test_suite(klass) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 8 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 = extract_source_location_from_class(klass) = 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 test_visibility_component = Datadog.send(:components).test_visibility test_suite = test_visibility_component.start_test_suite( test_suite_name, tags: ) test_suite&.set_expected_tests!(klass.runnable_methods) test_suite end |
.test_suite_name(klass, method_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/datadog/ci/contrib/minitest/helpers.rb', line 34 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 |