Class: TrackRelay::Subscribers::Test
- Defined in:
- lib/track_relay/subscribers/test.rb
Overview
In-memory capture subscriber for use in test suites.
Plan 07 will wire this into ‘TrackRelay.test_mode!`, which swaps the configured subscriber list for a single Test instance for the duration of an example so consumer tests can assert against fired events without sending them to real adapters.
Per-instance state — no class-level globals — so multiple instances do not crosstalk. #clear! resets the buffer; #find filters by event name.
Instance Attribute Summary collapse
-
#events ⇒ Array<EventPayload>
readonly
Captured payloads in insertion order.
Instance Method Summary collapse
-
#clear! ⇒ Array
Clear the captured events buffer.
-
#deliver(payload) ⇒ Array<EventPayload>
Append the payload to #events.
-
#find(name) ⇒ Array<EventPayload>
Return only the captured payloads whose ‘name` equals `name`.
-
#initialize ⇒ Test
constructor
A new instance of Test.
Methods inherited from Base
coerce_event_set, #except_events, filter, #handle, #only_events, #safe_deliver, #set_filter_overrides!, synchronous!
Constructor Details
#initialize ⇒ Test
Returns a new instance of Test.
30 31 32 33 |
# File 'lib/track_relay/subscribers/test.rb', line 30 def initialize super @events = [] end |
Instance Attribute Details
#events ⇒ Array<EventPayload> (readonly)
Returns captured payloads in insertion order.
28 29 30 |
# File 'lib/track_relay/subscribers/test.rb', line 28 def events @events end |
Instance Method Details
#clear! ⇒ Array
Clear the captured events buffer.
47 48 49 |
# File 'lib/track_relay/subscribers/test.rb', line 47 def clear! @events.clear end |
#deliver(payload) ⇒ Array<EventPayload>
Append the payload to #events. Called inline by Base#handle because Base.synchronous! is set.
40 41 42 |
# File 'lib/track_relay/subscribers/test.rb', line 40 def deliver(payload) @events << payload end |
#find(name) ⇒ Array<EventPayload>
Return only the captured payloads whose ‘name` equals `name`.
55 56 57 |
# File 'lib/track_relay/subscribers/test.rb', line 55 def find(name) @events.select { |e| e.name == name } end |