honeycombio / libhoney-rb

Ruby library for sending data to Honeycomb
Apache License 2.0
11 stars 30 forks source link

Add a "tape recorder" mode for testing instrumented code #19

Closed samstokes closed 6 years ago

samstokes commented 6 years ago

This adds support for stubbing out the TransmissionClient and capturing events for later inspection, allowing testing of instrumented code. tl;dr:

fakehoney = Libhoney::TestClient.new

my_app = MyApp.new(..., fakehoney, ...)
my_app.do_stuff

expect(fakehoney.events.size).to eq 3

first_event = fakehoney.events[0]
expect(first_event.data[:hovercraft_contents]).to eq 'Eels'

I've also moved some of the event validation (missing writekey, dataset or API host) out of Event#send and into TransmissionClient#add so as not to require a fake writekey for the fake client. We've been talking about toning down some of those validations anyway, but that's out of scope for this PR.

samstokes commented 6 years ago

Good point, thank you!