Module: Datadog::CI::Contrib::RSpec::Runner::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#run_specs(*args) ⇒ 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
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/ci/contrib/rspec/runner.rb', line 18

def run_specs(*args)
  return super unless datadog_configuration[:enabled]

  discovery_component = test_discovery_component

  if discovery_component&.enabled?
    discover_tests(discovery_component)

    # don't run the tests, we just needed to discover them and now we can return
    return
  end

  return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled]

  test_session = test_visibility_component.start_test_session(
    tags: {
      CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
      CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_integration.version.to_s
    },
    service: datadog_configuration[:service_name],
    estimated_total_tests_count: ::RSpec.world.example_count
  )

  test_module = test_visibility_component.start_test_module(Ext::FRAMEWORK)

  result = super
  return result unless test_module && test_session
  # distributed test session must end in the parent process (for RSpec it would be parallel_tests CLI)
  return result if test_session.distributed

  if result != 0
    test_module.failed!
    test_session.failed!
  else
    test_module.passed!
    test_session.passed!
  end
  test_module.finish
  test_session.finish

  result
end