Class: Libhoney::MockTransmissionClient

Inherits:
Object
  • Object
show all
Defined in:
lib/libhoney/mock_transmission.rb

Overview

Note:

This class is intended for use in tests, for example if you want to verify what events your instrumented code is sending. Use in production is not recommended.

For testing use: a mock version of TransmissionClient that retains all events in an in-memory queue for inspection (and does not send them to Honeycomb, or perform any network activity).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**_) ⇒ MockTransmissionClient

Returns a new instance of MockTransmissionClient.



10
11
12
# File 'lib/libhoney/mock_transmission.rb', line 10

def initialize(**_)
  reset
end

Instance Attribute Details

#eventsArray<Event> (readonly)

Returns the recorded events.

Returns:

  • (Array<Event>)

    the recorded events



15
16
17
# File 'lib/libhoney/mock_transmission.rb', line 15

def events
  @events
end

Instance Method Details

#add(event) ⇒ Object

Records an event



18
19
20
21
22
23
# File 'lib/libhoney/mock_transmission.rb', line 18

def add(event)
  Thread.current[:libhoney_transmitting] = true
  @events.push(event)
ensure
  Thread.current[:libhoney_transmitting] = false
end

#close(drain) ⇒ Object

Does nothing.



26
# File 'lib/libhoney/mock_transmission.rb', line 26

def close(drain); end

#resetObject

Discards the recorded events



29
30
31
# File 'lib/libhoney/mock_transmission.rb', line 29

def reset
  @events = []
end