README.md in pwwka-0.1.0 vs README.md in pwwka-0.2.0

- old
+ new

@@ -37,15 +37,15 @@ ### Adding it to your app Add to your `Gemfile`: ```ruby -gem 'pwwka', require: false, git: 'https://github.com/stitchfix/pwwka.git' +gem 'pwwka' ``` -### Set up your message_handler configration +### Set up your pwwka configration Connect to your RabbitMQ instance using the url and choose a name for your topic exchange. In `config/initializers/pwwka`: @@ -107,11 +107,11 @@ * `ROUTING_KEY` (optional) defaults to `#.#` (all messages) You'll also need to bring the Rake task into your app. For Rails, you'll need to edit the top-level `Rakefile`: ```ruby -require 'stitch_fix/message_handler/tasks' +require 'pwwka/tasks' ``` ### Queues - what messages will your queue receive It depends on your `routing_key`. If you set your routing key to `#.#` (the default) it will receive all the messages. The `#` is a wildcard so if you set it to `client.#` it will receive any message with `client.` at the beginning. The exchange registers the queue's name and routing key so it knows what messages the queue is supposed to receive. A named queue will receive each message it expects to get once and only once. @@ -175,10 +175,50 @@ ![RabbitMQ Management 1](docs/images/RabbitMQ_Management.png) ![RabbitMQ Management 2](docs/images/RabbitMQ_Management-2.png) ![RabbitMQ Management 3](docs/images/RabbitMQ_Management-3.png) ## Testing -The message_handler gem has tests for all its functionality so app testing is best done with expectations. However, if you want to test the message bus end-to-end in your app you can use some helpers in `lib/stitch_fix/message_handler/test_handler.rb`. See the gem specs for examples of how to use them. + +This gem has test coverage of interacting with RabbitMQ, so for unit tests, your best +strategy is to simply mock calls to `Pwwka::Transmitter`. + +For integration tests, however, you can examine the actual message bus by setting up +the provided `Pwwka::TestHandler` like so: + +```ruby +require 'pwwka/test_handler' + +describe "my integration test" do + + before(:all) do + @test_handler = Pwwka::TestHandler.new + @test_handler.test_setup + end + + after(:all) do + # this clears out any messages, so you have a clean test environment next time + @test_handler.test_teardown + end + + it "uses the message bus" do + post "/items", item: { size: "L" } + + message = @test_handler.pop_message + + expect(message.delivery_info.routing_key).to eq("my-company.items.created") + expect(message.payload).to eq({ item: { id: 42, size: "L" } }) + end + + it "can splat the values as well" do + post "/items", item: { size: "L" } + + delivery_info, payload = @test_handler.pop_message + + expect(delivery_info.routing_key).to eq("my-company.items.created") + expect(payload).to eq({ item: { id: 42, size: "L" } }) + end +end +``` ## TODO * automated monitoring * forking * resending