Class: Observability::Sender::Testing

Inherits:
Observability::Sender show all
Extended by:
Loggability
Defined in:
lib/observability/sender/testing.rb

Overview

A sender that just enqueues events and then lets you make assertions about the kinds of events that were sent.

Instance Attribute Summary collapse

Attributes inherited from Observability::Sender

#executor

Instance Method Summary collapse

Methods inherited from Observability::Sender

configured_type, inherited

Constructor Details

#initializeTesting

Create a new testing sender.



20
21
22
# File 'lib/observability/sender/testing.rb', line 20

def initialize( * )
	@enqueued_events = []
end

Instance Attribute Details

#enqueued_eventsObject (readonly)

The Array of events which were queued.



27
28
29
# File 'lib/observability/sender/testing.rb', line 27

def enqueued_events
  @enqueued_events
end

Instance Method Details

#enqueue(*events) ⇒ Object

Sender API – add the specified events to the queue.



36
37
38
# File 'lib/observability/sender/testing.rb', line 36

def enqueue( *events )
	@enqueued_events.concat( events )
end

#event_was_sent?(type) ⇒ Boolean

Returns true if at least one event of the specified type was enqueued.

Returns:

  • (Boolean)


50
51
52
# File 'lib/observability/sender/testing.rb', line 50

def event_was_sent?( type )
	return !self.find_events( type ).empty?
end

#find_events(type) ⇒ Object

Return any enqueued events that are of the specified type.



42
43
44
45
46
# File 'lib/observability/sender/testing.rb', line 42

def find_events( type )
	return @enqueued_events.find_all do |event|
		event.type == type
	end
end

#startObject

No-ops; there is no sending thread, so nothing to start/stop.



31
# File 'lib/observability/sender/testing.rb', line 31

def start( * ); end

#stopObject



32
# File 'lib/observability/sender/testing.rb', line 32

def stop( * ); end