Module: Datadog::CI::Contrib::RSpec::Example::InstanceMethods

Defined in:
lib/datadog/ci/contrib/rspec/example.rb

Overview

Instance methods for configuration

Instance Method Summary collapse

Instance Method Details

#run(example_group_instance, reporter) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/datadog/ci/contrib/rspec/example.rb', line 18

def run(example_group_instance, reporter)
  return super unless configuration[:enabled]

  test_name = full_description.strip
  if [:description].empty?
    # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
    test_name += " #{description}"
  end

  CI.trace_test(
    test_name,
    [:example_group][:rerun_file_path],
    tags: {
      CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
      CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s,
      CI::Ext::Test::TAG_TYPE => CI::Ext::Test::TEST_TYPE
    },
    service: configuration[:service_name]
  ) do |test_span|
    result = super

    case execution_result.status
    when :passed
      test_span.passed!
    when :failed
      test_span.failed!(exception: execution_result.exception)
    else
      test_span.skipped!(exception: execution_result.exception) if execution_result.example_skipped?
    end

    result
  end
end