README.md in delivery_boy-0.2.0.beta1 vs README.md in delivery_boy-0.2.0

- old
+ new

@@ -165,9 +165,46 @@ ##### `ssl_client_cert_key` A PEM encoded client cert key to use with an SSL connection. Must be used in combination with `ssl_client_cert`. +### Testing + +DeliveryBoy provides a test mode out of the box. When this mode is enabled, messages will be stored in memory rather than being sent to Kafka. If you use RSpec, enabling test mode is as easy as adding this to your spec helper: + +```ruby +# spec/spec_helper.rb +require "delivery_boy/rspec" +``` + +Now your application can use DeliveryBoy in tests without connecting to an actual Kafka cluster. Asserting that messages have been delivered is simple: + +```ruby +describe PostsController do + describe "#show" do + it "emits an event to Kafka" do + post = Post.create!(body: "hello") + + get :show, id: post.id + + # Use this API to extract all messages written to a Kafka topic. + messages = DeliveryBoy.testing.messages_for("post_views") + + expect(messages.count).to eq 1 + + # In addition to #value, you can also pull out #key and #partition_key. + event = JSON.parse(messages.first.value) + + expect(event["post_id"]).to eq post.id + end + end +end +``` + +This takes care of clearing messages after each example, as well. + +If you're not using RSpec, you can easily replicate the functionality yourself. Call `DeliveryBoy.test_mode` at load time, and make sure that `DeliveryBoy.testing.clear` is called after each test. + ### Instrumentation & monitoring Since DeliveryBoy is just an opinionated API on top of ruby-kafka, you can use all the [instrumentation made available by that library](https://github.com/zendesk/ruby-kafka#instrumentation). You can also use the [existing monitoring solutions](https://github.com/zendesk/ruby-kafka#monitoring) that integrate with various monitoring services. ## Contributing