Skip to content

Commit

Permalink
Merge pull request #4 from customink/improve_documentation
Browse files Browse the repository at this point in the history
Improve documentation
  • Loading branch information
chmurph2 committed Jan 8, 2016
2 parents b391852 + 6f17dce commit e782640
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 52 deletions.
9 changes: 9 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.0.0

* Updated Queue constructor because bunny 1.1 requires a channel.

# 1.0.1

* Initialized routed_messages to be an Array to avoid nil errors in
some scenarios.

# 1.0.2

* Improved the readme by focusing on `routed_messages`.
78 changes: 33 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
# StuffedBunny

Provides stubbing of the Bunny gem.
Provides stubbing of the Bunny gem to faciliate testing.

To faciliate testing, exchanges are represented as a class-level hash. This
allows all bunny instances access to the same exchanges.
A `routed_messages` array captures any publised messages on a topic exchange.

## Installation

Add this line to your application's Gemfile:

gem 'stuffed_bunny'

And then execute:

$ bundle

Or install it yourself as:

$ gem install stuffed_bunny

## Usage

### RSpec Example
## Example Usage

```ruby
# spec/spec_helper.rb
require 'stuffed_bunny'
require 'stuffed_bunny' # Bunny is overriden once this is required

RSpec.configure do |config|
class SomeTest < TestUnit::TestCase

config.after(:each) do
StuffedBunny.reset!
def setup
@bunny = Bunny::Client.new
end

end
```

### Minitest Example

```ruby
require 'stuffed_bunny'

class MiniTest::Spec
def teardown
StuffedBunny.reset! # resets the routed_messages
end

after :each do
StuffedBunny.reset!
def test_that_a_message_is_published_to_an_exchange
exchange_options = { } # set it to be a topic exchange, etc.
Bunny.run do |b|
topic_exchange = b.exchange( "a_topic_exchange", exchange_options)
publish_options = { :key => "a.routing.key" }
topic_exchange.publish("a message", publish_options)
end

routed_message = @bunny.exchanges["a_topic_exchange"].routed_messages[0]
assert_equal "a.routing.key", routed_message.key
assert_equal "a message", routed_message.message
end

end
```

### TestUnit Example
## Installation

```ruby
require 'stuffed_bunny'
Add this line to your application's Gemfile:

class SomeTest < TestUnit::TestCase
group :test do
# Note that as soon as the gem is required, Bunny is overridden.
gem 'stuffed_bunny', :require => false
end

def teardown
StuffedBunny.reset!
end
And then execute:

end
```
$ bundle

Or install it yourself as:

$ gem install stuffed_bunny

## Contributing

Expand Down
12 changes: 6 additions & 6 deletions lib/stuffed_bunny/bunny_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

# Overriding the Bunny gem's modules and classes.
#
# NOTE: Not everything is stubbed yet. We've only stubbed the method calls we
# are using in our projects.
# NOTE: Not everything in Bunny is stubbed here. Pull requests are welcome.
module Bunny
def self.run(options = {})
bunny = Bunny::Client.new(options)
Expand Down Expand Up @@ -42,18 +41,18 @@ def initialize(client, name, options = {})
@client, @name = client, name
@type = options[:type]
end

def routed_messages
@routed_messaged ||= []
@routed_messaged ||= []
end

# To facilite testing this adds a Struct containing the data
# +message+ and routing +key+ to the +routed_messages+.
#
# Example usage:
# Bunny.run do |b|
# topic = b.exchange("some_topic_name", MH::Exchange::OPTIONS)
# options = { :key => "some.routing.key" }.merge(MH::Exchange::PUBLISH_OPTIONS)
# topic = b.exchange("some_topic_name", SOME_EXCHANGE_OPTIONS)
# options = { :key => "some.routing.key" }.merge(SOME_PUBLISH_OPTIONS)
# topic.publish("some message", options)
# end
#
Expand All @@ -70,6 +69,7 @@ def publish(data, options = {})
class Queue
def initialize(channel_or_connection, name = nil, opts = {})
end

def delete(*args)
:delete_ok
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stuffed_bunny/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module StuffedBunny
VERSION = '1.0.1'
VERSION = '1.0.2'
end

0 comments on commit e782640

Please sign in to comment.