Module: BrainzLab::Testing::Matchers

Defined in:
lib/brainzlab/testing/matchers.rb

Overview

Custom RSpec matchers for BrainzLab SDK

These matchers provide a clean, expressive syntax for testing BrainzLab event tracking, error capture, logging, and metrics.

Examples:

Usage in RSpec

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

describe UserService do
  it 'tracks user signup' do
    subject.register(email: 'test@example.com')
    expect('user.signup').to have_been_tracked.with(email: 'test@example.com')
  end
end

Defined Under Namespace

Classes: HaveBeenCapturedMatcher, HaveBeenLoggedMatcher, HaveBeenRecordedMatcher, HaveBeenTracedMatcher, HaveBeenTrackedMatcher, HaveSentAlertMatcher

Instance Method Summary collapse

Instance Method Details

#have_been_capturedObject

RSpec matcher for capturing errors

Examples:

expect(RuntimeError).to have_been_captured
expect(RuntimeError).to have_been_captured.with_message(/something went wrong/i)
expect('MyCustomError').to have_been_captured.with_context(user_id: 1)


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

def have_been_captured
  HaveBeenCapturedMatcher.new
end

#have_been_loggedObject

RSpec matcher for recording logs

Examples:

expect(:info).to have_been_logged.with_message('User created')
expect(:error).to have_been_logged.with_message(/failed/i).with_data(user_id: 1)


51
52
53
# File 'lib/brainzlab/testing/matchers.rb', line 51

def have_been_logged
  HaveBeenLoggedMatcher.new
end

#have_been_recordedObject

RSpec matcher for recording metrics

Examples:

expect(['increment', 'orders.count']).to have_been_recorded
expect(['gauge', 'memory.usage']).to have_been_recorded.with_value(1024)
expect(['distribution', 'response.time']).to have_been_recorded.with_tags(endpoint: '/api/users')


62
63
64
# File 'lib/brainzlab/testing/matchers.rb', line 62

def have_been_recorded
  HaveBeenRecordedMatcher.new
end

#have_been_tracedObject

RSpec matcher for recording traces

Examples:

expect('db.query').to have_been_traced
expect('http.request').to have_been_traced.with(method: 'GET')


72
73
74
# File 'lib/brainzlab/testing/matchers.rb', line 72

def have_been_traced
  HaveBeenTracedMatcher.new
end

#have_been_trackedObject

RSpec matcher for tracking events

Examples:

expect('user.signup').to have_been_tracked
expect('user.signup').to have_been_tracked.with(user_id: 1)
expect('order.completed').to have_been_tracked.with(order_id: 42, total: 99.99)


30
31
32
# File 'lib/brainzlab/testing/matchers.rb', line 30

def have_been_tracked
  HaveBeenTrackedMatcher.new
end

#have_sent_alertObject

RSpec matcher for sending alerts

Examples:

expect('high_error_rate').to have_sent_alert
expect('low_disk_space').to have_sent_alert.with_severity(:critical)


82
83
84
# File 'lib/brainzlab/testing/matchers.rb', line 82

def have_sent_alert
  HaveSentAlertMatcher.new
end