module Sentry::TestHelper

def extract_sentry_exceptions(event)

Returns:
  • (Array) -
def extract_sentry_exceptions(event)
  event&.exception&.values || []
end

def last_sentry_event

Returns:
  • (Event, nil) -
def last_sentry_event
  sentry_events.last
end

def sentry_envelopes

Returns:
  • (Array) -
def sentry_envelopes
  sentry_transport.envelopes
end

def sentry_events

Returns:
  • (Array) -
def sentry_events
  sentry_transport.events
end

def sentry_transport

Returns:
  • (Transport) -
def sentry_transport
  Sentry.get_current_client.transport
end

def setup_sentry_test(&block)

Returns:
  • (void) -

Other tags:
    Yieldparam: config -
def setup_sentry_test(&block)
  raise "please make sure the SDK is initialized for testing" unless Sentry.initialized?
  copied_config = Sentry.configuration.dup
  # configure dummy DSN, so the events will not be sent to the actual service
  copied_config.dsn = DUMMY_DSN
  # set transport to DummyTransport, so we can easily intercept the captured events
  copied_config.transport.transport_class = Sentry::DummyTransport
  # make sure SDK allows sending under the current environment
  copied_config.enabled_environments << copied_config.environment unless copied_config.enabled_environments.include?(copied_config.environment)
  # disble async event sending
  copied_config.background_worker_threads = 0
  # user can overwrite some of the configs, with a few exceptions like:
  # - include_local_variables
  # - auto_session_tracking
  block&.call(copied_config)
  test_client = Sentry::Client.new(copied_config)
  Sentry.get_current_hub.bind_client(test_client)
  Sentry.get_current_scope.clear
end

def teardown_sentry_test

Returns:
  • (void) -
def teardown_sentry_test
  return unless Sentry.initialized?
  sentry_transport.events = []
  sentry_transport.envelopes = []
  Sentry.get_current_scope.clear
end