Module: BrainzLab::Testing::Helpers
- Defined in:
- lib/brainzlab/testing/helpers.rb
Overview
Test helpers for RSpec and Minitest
Include this module in your test helper to gain access to BrainzLab testing utilities.
Instance Method Summary collapse
-
#brainzlab_alert_sent?(name, message: nil, severity: nil) ⇒ Boolean
Check if a specific alert was sent.
-
#brainzlab_alerts ⇒ Array<Hash>
Access all captured Signal alerts.
-
#brainzlab_error_captured?(error_class = nil, message: nil, context: nil) ⇒ Boolean
Check if a specific error was captured.
-
#brainzlab_errors ⇒ Array<Hash>
Access all captured Reflex errors.
-
#brainzlab_event_tracked?(name, properties = nil) ⇒ Boolean
Check if a specific event was tracked.
-
#brainzlab_events ⇒ Array<Hash>
Access all captured Flux events.
-
#brainzlab_events_named(name) ⇒ Array<Hash>
Access events filtered by name.
-
#brainzlab_logged?(level, message = nil, data = nil) ⇒ Boolean
Check if a specific log message was recorded.
-
#brainzlab_logs ⇒ Array<Hash>
Access all captured Recall logs.
-
#brainzlab_logs_at_level(level) ⇒ Array<Hash>
Access logs filtered by level.
-
#brainzlab_metric_recorded?(type, name, value: nil, tags: nil) ⇒ Boolean
Check if a specific metric was recorded.
-
#brainzlab_metrics ⇒ Array<Hash>
Access all captured Flux metrics.
-
#brainzlab_notifications ⇒ Array<Hash>
Access all captured Signal notifications.
-
#brainzlab_trace_recorded?(name, opts = nil) ⇒ Boolean
Check if a specific trace was recorded.
-
#brainzlab_traces ⇒ Array<Hash>
Access all captured Pulse traces.
-
#clear_brainzlab_events! ⇒ Object
Clear all captured events, logs, errors, and metrics.
-
#expect_brainzlab_alert(name) ⇒ AlertExpectation
Create an alert expectation builder for fluent assertions.
-
#expect_brainzlab_error(error_class) ⇒ ErrorExpectation
Create an error expectation builder for fluent assertions.
-
#expect_brainzlab_event(name) ⇒ EventExpectation
Create an event expectation builder for fluent assertions.
-
#expect_brainzlab_log(level) ⇒ LogExpectation
Create a log expectation builder for fluent assertions.
-
#expect_brainzlab_metric(type, name) ⇒ MetricExpectation
Create a metric expectation builder for fluent assertions.
-
#expect_brainzlab_trace(name) ⇒ TraceExpectation
Create a trace expectation builder for fluent assertions.
-
#last_brainzlab_error ⇒ Hash?
Get the last captured error.
-
#last_brainzlab_event ⇒ Hash?
Get the last captured event.
-
#stub_brainzlab! ⇒ Object
Stub all BrainzLab SDK calls to prevent real API requests and enable event capturing for assertions.
-
#unstub_brainzlab! ⇒ Object
Restore original BrainzLab SDK behavior.
Instance Method Details
#brainzlab_alert_sent?(name, message: nil, severity: nil) ⇒ Boolean
Check if a specific alert was sent
232 233 234 |
# File 'lib/brainzlab/testing/helpers.rb', line 232 def brainzlab_alert_sent?(name, message: nil, severity: nil) BrainzLab::Testing.event_store.alert_sent?(name, message: , severity: severity) end |
#brainzlab_alerts ⇒ Array<Hash>
Access all captured Signal alerts
155 156 157 |
# File 'lib/brainzlab/testing/helpers.rb', line 155 def brainzlab_alerts BrainzLab::Testing.event_store.alerts end |
#brainzlab_error_captured?(error_class = nil, message: nil, context: nil) ⇒ Boolean
Check if a specific error was captured
211 212 213 |
# File 'lib/brainzlab/testing/helpers.rb', line 211 def brainzlab_error_captured?(error_class = nil, message: nil, context: nil) BrainzLab::Testing.event_store.error_captured?(error_class, message: , context: context) end |
#brainzlab_errors ⇒ Array<Hash>
Access all captured Reflex errors
139 140 141 |
# File 'lib/brainzlab/testing/helpers.rb', line 139 def brainzlab_errors BrainzLab::Testing.event_store.errors end |
#brainzlab_event_tracked?(name, properties = nil) ⇒ Boolean
Check if a specific event was tracked
177 178 179 |
# File 'lib/brainzlab/testing/helpers.rb', line 177 def brainzlab_event_tracked?(name, properties = nil) BrainzLab::Testing.event_store.event_tracked?(name, properties) end |
#brainzlab_events ⇒ Array<Hash>
Access all captured Flux events
81 82 83 |
# File 'lib/brainzlab/testing/helpers.rb', line 81 def brainzlab_events BrainzLab::Testing.event_store.events end |
#brainzlab_events_named(name) ⇒ Array<Hash>
Access events filtered by name
94 95 96 |
# File 'lib/brainzlab/testing/helpers.rb', line 94 def brainzlab_events_named(name) BrainzLab::Testing.event_store.events_named(name) end |
#brainzlab_logged?(level, message = nil, data = nil) ⇒ Boolean
Check if a specific log message was recorded
200 201 202 |
# File 'lib/brainzlab/testing/helpers.rb', line 200 def brainzlab_logged?(level, = nil, data = nil) BrainzLab::Testing.event_store.logged?(level, , data) end |
#brainzlab_logs ⇒ Array<Hash>
Access all captured Recall logs
118 119 120 |
# File 'lib/brainzlab/testing/helpers.rb', line 118 def brainzlab_logs BrainzLab::Testing.event_store.logs end |
#brainzlab_logs_at_level(level) ⇒ Array<Hash>
Access logs filtered by level
127 128 129 |
# File 'lib/brainzlab/testing/helpers.rb', line 127 def brainzlab_logs_at_level(level) BrainzLab::Testing.event_store.logs_at_level(level) end |
#brainzlab_metric_recorded?(type, name, value: nil, tags: nil) ⇒ Boolean
Check if a specific metric was recorded
189 190 191 |
# File 'lib/brainzlab/testing/helpers.rb', line 189 def brainzlab_metric_recorded?(type, name, value: nil, tags: nil) BrainzLab::Testing.event_store.metric_recorded?(type, name, value: value, tags: ) end |
#brainzlab_metrics ⇒ Array<Hash>
Access all captured Flux metrics
106 107 108 |
# File 'lib/brainzlab/testing/helpers.rb', line 106 def brainzlab_metrics BrainzLab::Testing.event_store.metrics end |
#brainzlab_notifications ⇒ Array<Hash>
Access all captured Signal notifications
163 164 165 |
# File 'lib/brainzlab/testing/helpers.rb', line 163 def brainzlab_notifications BrainzLab::Testing.event_store.notifications end |
#brainzlab_trace_recorded?(name, opts = nil) ⇒ Boolean
Check if a specific trace was recorded
221 222 223 |
# File 'lib/brainzlab/testing/helpers.rb', line 221 def brainzlab_trace_recorded?(name, opts = nil) BrainzLab::Testing.event_store.trace_recorded?(name, opts) end |
#brainzlab_traces ⇒ Array<Hash>
Access all captured Pulse traces
147 148 149 |
# File 'lib/brainzlab/testing/helpers.rb', line 147 def brainzlab_traces BrainzLab::Testing.event_store.traces end |
#clear_brainzlab_events! ⇒ Object
Clear all captured events, logs, errors, and metrics
Call this in your test teardown or between test scenarios to ensure a clean slate.
69 70 71 |
# File 'lib/brainzlab/testing/helpers.rb', line 69 def clear_brainzlab_events! BrainzLab::Testing.event_store.clear! end |
#expect_brainzlab_alert(name) ⇒ AlertExpectation
Create an alert expectation builder for fluent assertions
322 323 324 |
# File 'lib/brainzlab/testing/helpers.rb', line 322 def expect_brainzlab_alert(name) AlertExpectation.new(name, BrainzLab::Testing.event_store) end |
#expect_brainzlab_error(error_class) ⇒ ErrorExpectation
Create an error expectation builder for fluent assertions
273 274 275 |
# File 'lib/brainzlab/testing/helpers.rb', line 273 def expect_brainzlab_error(error_class) ErrorExpectation.new(error_class, BrainzLab::Testing.event_store) end |
#expect_brainzlab_event(name) ⇒ EventExpectation
Create an event expectation builder for fluent assertions
261 262 263 |
# File 'lib/brainzlab/testing/helpers.rb', line 261 def expect_brainzlab_event(name) EventExpectation.new(name, BrainzLab::Testing.event_store) end |
#expect_brainzlab_log(level) ⇒ LogExpectation
Create a log expectation builder for fluent assertions
285 286 287 |
# File 'lib/brainzlab/testing/helpers.rb', line 285 def expect_brainzlab_log(level) LogExpectation.new(level, BrainzLab::Testing.event_store) end |
#expect_brainzlab_metric(type, name) ⇒ MetricExpectation
Create a metric expectation builder for fluent assertions
298 299 300 |
# File 'lib/brainzlab/testing/helpers.rb', line 298 def expect_brainzlab_metric(type, name) MetricExpectation.new(type, name, BrainzLab::Testing.event_store) end |
#expect_brainzlab_trace(name) ⇒ TraceExpectation
Create a trace expectation builder for fluent assertions
310 311 312 |
# File 'lib/brainzlab/testing/helpers.rb', line 310 def expect_brainzlab_trace(name) TraceExpectation.new(name, BrainzLab::Testing.event_store) end |
#last_brainzlab_error ⇒ Hash?
Get the last captured error
248 249 250 |
# File 'lib/brainzlab/testing/helpers.rb', line 248 def last_brainzlab_error BrainzLab::Testing.event_store.last_error end |
#last_brainzlab_event ⇒ Hash?
Get the last captured event
240 241 242 |
# File 'lib/brainzlab/testing/helpers.rb', line 240 def last_brainzlab_event BrainzLab::Testing.event_store.last_event end |
#stub_brainzlab! ⇒ Object
Stub all BrainzLab SDK calls to prevent real API requests and enable event capturing for assertions.
47 48 49 |
# File 'lib/brainzlab/testing/helpers.rb', line 47 def stub_brainzlab! BrainzLab::Testing.enable! end |
#unstub_brainzlab! ⇒ Object
This is typically called automatically if you’re using clear_brainzlab_events! in your teardown, which also restores state.
Restore original BrainzLab SDK behavior
55 56 57 |
# File 'lib/brainzlab/testing/helpers.rb', line 55 def unstub_brainzlab! BrainzLab::Testing.disable! end |