stuffed_bunny 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +1 -0
- data/lib/stuffed_bunny/bunny_overrides.rb +63 -0
- data/lib/stuffed_bunny/version.rb +3 -0
- data/lib/stuffed_bunny.rb +11 -0
- data/stuffed_bunny.gemspec +19 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 CustomInk, LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# StuffedBunny
|
2
|
+
|
3
|
+
Provides stubbing of the Bunny gem.
|
4
|
+
|
5
|
+
To faciliate testing, exchanges are represented as a class-level hash. This
|
6
|
+
allows all bunny instances access to the same exchanges.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'stuffed_bunny'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install stuffed_bunny
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### RSpec Example
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# spec/spec_helper.rb
|
28
|
+
require 'stuffed_bunny'
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
|
32
|
+
config.after(:each) do
|
33
|
+
StuffedBunny.reset!
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Minitest Example
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'stuffed_bunny'
|
43
|
+
|
44
|
+
class MiniTest::Spec
|
45
|
+
|
46
|
+
after :each do
|
47
|
+
StuffedBunny.reset!
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### TestUnit Example
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require 'stuffed_bunny'
|
57
|
+
|
58
|
+
class SomeTest < TestUnit::TestCase
|
59
|
+
|
60
|
+
def teardown
|
61
|
+
StuffedBunny.reset!
|
62
|
+
|
63
|
+
@bunny = Bunny::Client.new
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
# Overriding the Bunny gem's modules and classes.
|
4
|
+
#
|
5
|
+
# NOTE: Not everything is stubbed yet. We've only stubbed the method calls we
|
6
|
+
# are using in our projects.
|
7
|
+
module Bunny
|
8
|
+
def self.run(options = {})
|
9
|
+
bunny = Bunny::Client.new(options)
|
10
|
+
yield bunny
|
11
|
+
end
|
12
|
+
|
13
|
+
# Resets the class-level exchanges.
|
14
|
+
def self.reset_exchanges
|
15
|
+
Bunny::Client.send(:class_variable_set, :@@exchanges, {})
|
16
|
+
end
|
17
|
+
|
18
|
+
class Client
|
19
|
+
@@exchanges = {} # class variable simulating exchanges in the message broker
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
end
|
23
|
+
|
24
|
+
def exchange(name, options = {})
|
25
|
+
@@exchanges[name] ||= Bunny::Exchange.new(self, name, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Expose the exchanges.
|
29
|
+
def exchanges
|
30
|
+
@@exchanges
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Exchange
|
35
|
+
attr_accessor :client, :type, :name, :routed_messages
|
36
|
+
|
37
|
+
def initialize(client, name, options = {})
|
38
|
+
@client, @name = client, name
|
39
|
+
@routed_messages = []
|
40
|
+
@type = options[:type]
|
41
|
+
end
|
42
|
+
|
43
|
+
# To facilite testing this adds an OpenStruct containing the data
|
44
|
+
# +message+ and routing +key+ to the +routed_messages+.
|
45
|
+
#
|
46
|
+
# Example usage:
|
47
|
+
# Bunny.run do |b|
|
48
|
+
# topic = b.exchange("some_topic_name", MH::Exchange::OPTIONS)
|
49
|
+
# options = { :key => "some.routing.key" }.merge(MH::Exchange::PUBLISH_OPTIONS)
|
50
|
+
# topic.publish("some message", options)
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# Testing:
|
54
|
+
# ...
|
55
|
+
# routed_message = @bunny.exchanges["some_topic_name"].routed_messages[0]
|
56
|
+
# assert_equal "some message", routed_message.message
|
57
|
+
# assert_equal "some.routing.key", routed_message.key
|
58
|
+
def publish(data, options = {})
|
59
|
+
@routed_messages << OpenStruct.new(:message => data,
|
60
|
+
:key => options[:key])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stuffed_bunny/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'stuffed_bunny'
|
8
|
+
gem.version = StuffedBunny::VERSION
|
9
|
+
gem.authors = ['Chris Murphy', 'Derek Lindahl']
|
10
|
+
gem.email = ["cmurphy@customink.com"]
|
11
|
+
gem.description = %q{Provides stubbing of the Bunny gem.}
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = 'https://github.com/customink/stuffed_bunny'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stuffed_bunny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Murphy
|
9
|
+
- Derek Lindahl
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Provides stubbing of the Bunny gem.
|
16
|
+
email:
|
17
|
+
- cmurphy@customink.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/stuffed_bunny.rb
|
28
|
+
- lib/stuffed_bunny/bunny_overrides.rb
|
29
|
+
- lib/stuffed_bunny/version.rb
|
30
|
+
- stuffed_bunny.gemspec
|
31
|
+
homepage: https://github.com/customink/stuffed_bunny
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.24
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Provides stubbing of the Bunny gem.
|
55
|
+
test_files: []
|