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



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
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/ci/contrib/rspec/example.rb', line 21

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::Test.trace(
    tracer,
    configuration[:operation_name],
    {
      span_options: {
        app: Ext::APP,
        resource: test_name,
        service: configuration[:service_name]
      },
      framework: Ext::FRAMEWORK,
      framework_version: Datadog::CI::Contrib::RSpec::Integration.version.to_s,
      test_name: test_name,
      test_suite: file_path,
      test_type: Ext::TEST_TYPE
    }
  ) do |span|
    result = super

    case execution_result.status
    when :passed
      CI::Test.passed!(span)
    when :failed
      CI::Test.failed!(span, execution_result.exception)
    else
      CI::Test.skipped!(span, execution_result.exception) if execution_result.example_skipped?
    end

    result
  end
end