Module: BrainzLab::Testing

Defined in:
lib/brainzlab/testing.rb,
lib/brainzlab/testing/helpers.rb,
lib/brainzlab/testing/matchers.rb,
lib/brainzlab/testing/event_store.rb

Overview

Testing utilities for BrainzLab SDK

Provides helpers for stubbing SDK calls, capturing events, and custom matchers for RSpec/Minitest.

Examples:

Usage in RSpec

# spec/rails_helper.rb or spec/spec_helper.rb
require 'brainzlab/testing'

RSpec.configure do |config|
  config.include BrainzLab::Testing::Helpers
end

Usage in Minitest

# test/test_helper.rb
require 'brainzlab/testing'

class ActiveSupport::TestCase
  include BrainzLab::Testing::Helpers
end

Defined Under Namespace

Modules: Helpers, Matchers Classes: AlertExpectation, ErrorExpectation, EventExpectation, EventStore, LogExpectation, MetricExpectation, TraceExpectation

Class Method Summary collapse

Class Method Details

.disable!Object

Disable testing mode



55
56
57
58
59
60
# File 'lib/brainzlab/testing.rb', line 55

def disable!
  return unless @enabled

  @enabled = false
  remove_stubs!
end

.enable!Object

Enable testing mode (stubs all SDK calls)



47
48
49
50
51
52
# File 'lib/brainzlab/testing.rb', line 47

def enable!
  return if @enabled

  @enabled = true
  install_stubs!
end

.enabled?Boolean

Check if testing mode is active

Returns:

  • (Boolean)


42
43
44
# File 'lib/brainzlab/testing.rb', line 42

def enabled?
  @enabled == true
end

.event_storeObject

Global event store for capturing events during tests



32
33
34
# File 'lib/brainzlab/testing.rb', line 32

def event_store
  @event_store ||= EventStore.new
end

.reset!Object

Reset the event store (called between tests)



37
38
39
# File 'lib/brainzlab/testing.rb', line 37

def reset!
  @event_store = EventStore.new
end