bunny-mock 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a5612c89a3f3570ab35b3bf6b56edb8e898ba11
4
- data.tar.gz: e9d0d142ca7ef7bdd3ef2eb193097118550d2b62
3
+ metadata.gz: c674fde478dce165ef8edd3f4b5679487d1a77e9
4
+ data.tar.gz: 9b61556fb514f0f12e3be7f72efc01a0f11a820c
5
5
  SHA512:
6
- metadata.gz: ee490d3e0ec271a295f8c802d34d568e9f8b17bdc702c083b3ab84943cfcbbd5b98fe278f0f79e432609abac19e0f8264986a043cce62f7cd182dd7ebb7c4fbe
7
- data.tar.gz: ee1bdd4f57f0f8b8b7c7a4cf8a8e48857c63251e4d35ddd9207fc473ccafcc651d3d2089aed61c1d83053a570c12527497b3e2117e0648fdc8f5652952eb6cbe
6
+ metadata.gz: 06040eeb88b2446118f40a8ff9ef61d27caaa0d7173bafb6d27a8f9410b7ba9fa47e106557adb728e11d3bce8ba5d2193382944473b551fe42805cd939bcd501
7
+ data.tar.gz: 4fa7fd68ca0c53948622f0bc45ab230f9646864534a62ab896d47a87b3a0b1efc8c9faa52ea0b9d8907e81009924761fc2634101ed370c61f3a65bd47bab88e9
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.{sh,markdown}]
12
+ indent_size = 4
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayCopNames: true
4
+ Include:
5
+ - 'lib/**/*'
6
+ Exclude:
7
+ - 'spec/**/*'
8
+
9
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,65 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-02-18 00:29:42 -0500 using RuboCop version 0.37.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 33
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 126
14
+
15
+ # Offense count: 7
16
+ Style/Documentation:
17
+ Exclude:
18
+ - 'spec/**/*'
19
+ - 'test/**/*'
20
+ - 'lib/bunny_mock/channel.rb'
21
+ - 'lib/bunny_mock/exchange.rb'
22
+ - 'lib/bunny_mock/exchanges/direct.rb'
23
+ - 'lib/bunny_mock/exchanges/fanout.rb'
24
+ - 'lib/bunny_mock/exchanges/headers.rb'
25
+ - 'lib/bunny_mock/exchanges/topic.rb'
26
+ - 'lib/bunny_mock/queue.rb'
27
+
28
+ # Offense count: 8
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
31
+ # SupportedStyles: empty_lines, no_empty_lines
32
+ Style/EmptyLinesAroundClassBody:
33
+ Exclude:
34
+ - 'lib/bunny_mock/channel.rb'
35
+ - 'lib/bunny_mock/exchange.rb'
36
+ - 'lib/bunny_mock/exchanges/direct.rb'
37
+ - 'lib/bunny_mock/exchanges/fanout.rb'
38
+ - 'lib/bunny_mock/exchanges/headers.rb'
39
+ - 'lib/bunny_mock/exchanges/topic.rb'
40
+ - 'lib/bunny_mock/queue.rb'
41
+ - 'lib/bunny_mock/session.rb'
42
+
43
+ # Offense count: 36
44
+ # Cop supports --auto-correct.
45
+ Style/EmptyLinesAroundMethodBody:
46
+ Exclude:
47
+ - 'lib/bunny-mock.rb'
48
+ - 'lib/bunny_mock/channel.rb'
49
+ - 'lib/bunny_mock/exchange.rb'
50
+ - 'lib/bunny_mock/exchanges/direct.rb'
51
+ - 'lib/bunny_mock/exchanges/fanout.rb'
52
+ - 'lib/bunny_mock/exchanges/headers.rb'
53
+ - 'lib/bunny_mock/exchanges/topic.rb'
54
+ - 'lib/bunny_mock/queue.rb'
55
+ - 'lib/bunny_mock/session.rb'
56
+
57
+ # Offense count: 3
58
+ # Cop supports --auto-correct.
59
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
60
+ # SupportedStyles: empty_lines, no_empty_lines
61
+ Style/EmptyLinesAroundModuleBody:
62
+ Exclude:
63
+ - 'lib/bunny-mock.rb'
64
+ - 'lib/bunny_mock/exceptions.rb'
65
+ - 'lib/bunny_mock/version.rb'
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
- bundler_args: --without development
3
- script: bundle exec rspec
2
+ sudo: false
3
+
4
4
  rvm:
5
- - "2.0.0"
6
- - "2.1.8"
7
- - "2.3.0"
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
8
+
8
9
  branches:
9
10
  only:
10
11
  - master
data/.yardopts CHANGED
@@ -5,3 +5,4 @@
5
5
  --hide-tag todo
6
6
  -
7
7
  LICENSE
8
+ CHANGELOG.md
@@ -0,0 +1,14 @@
1
+ ## v1.2.0
2
+
3
+ * Adds `with_channel` functionality to `BunnyMock::Session`
4
+ * Renames `BunnyMock::Exchange#has_binding?` to `BunnyMock::Exchange#routes_to?`
5
+ * Adds `Bunny` as a dependency to use its exceptions
6
+
7
+ ## v1.1.0
8
+
9
+ * Moves queue and exchange storage to `BunnyMock::Session`
10
+ * Adds `queue_exists?` and `exchange_exists?` methods to `BunnyMock::Session`
11
+
12
+ ## v1.0.0
13
+
14
+ First stable release!
data/Gemfile CHANGED
@@ -1,15 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'amq-protocol'
4
-
5
- group :development do
6
-
7
- gem 'yard'
8
- end
9
-
10
- group :test do
11
- gem 'coveralls'
12
- gem 'rspec', '~> 3.4.0'
13
- end
3
+ gem 'bunny', '>= 2.0'
14
4
 
15
5
  gemspec
data/README.md CHANGED
@@ -10,70 +10,43 @@ A mock client for RabbitMQ, modeled after the popular [Bunny client](https://git
10
10
 
11
11
  ## Usage
12
12
 
13
- BunnyMock can be injected into your RabbitMQ application in place of Bunny for testing. Consider the following example of an RabibtMQ helper module, in Rails
13
+ BunnyMock can be injected into your RabbitMQ application in place of Bunny for testing. For example, if you have a helper module named `AMQFactory`, some code similar to the following placed in `spec_helper` or `test_helper` or what have you is all you need to start using BunnyMock to test your RabbitMQ application
14
14
 
15
15
  ```ruby
16
- require 'bunny'
16
+ require 'bunny-mock'
17
17
 
18
- module AMQP
19
- module Factory
20
-
21
- ## Connection, can be mocked for tests
22
- mattr_accessor :connection
23
-
24
- ####################################################
25
- # Connection Management
26
- ####################################################
27
-
28
- def self.connect
29
-
30
- # create bunny rmq client
31
- @connection = Bunny.new Global.amqp.to_hash
32
-
33
- # make connection
34
- @connection.start
35
-
36
- # return connection
37
- @connection
38
- end
39
-
40
- def self.get_channel
41
-
42
- # make connection if not connected
43
- connect unless defined?(@connection) and @connection.open?
44
-
45
- # get channel
46
- @connection.channel
47
- end
48
-
49
- ...
50
- end
18
+ RSpec.configure do |config|
19
+ config.before(:each) do
20
+ AMQFactory.connection = BunnyMock.new.start
21
+ end
51
22
  end
52
23
  ```
53
24
 
54
- In this case, to set up your tests, you can simply set `AMQP::Factory.connection = BunnyMock.new.start` to inject the mock library. Then you can use the mock helpers in your tests.
25
+ For an example, easy to mock setup, check out [this helper](https://gist.github.com/arempe93/8143edb17c57666e738f)
55
26
 
56
27
  ## Examples
57
28
 
29
+ Here are some examples showcasing what BunnyMock can do
30
+
58
31
  #### Declaration
59
32
 
60
33
  ```ruby
61
34
  it 'should create queues and exchanges' do
62
35
 
63
- session = BunnyMock.new.start
64
- channel = session.channel
36
+ session = BunnyMock.new.start
37
+ channel = session.channel
65
38
 
66
- queue = channel.queue 'queue.test'
67
- expect(session.queue_exists?('queue.test')).to be_truthy
39
+ queue = channel.queue 'queue.test'
40
+ expect(session.queue_exists?('queue.test')).to be_truthy
68
41
 
69
- queue.delete
70
- expect(session.queue_exists?('queue.test')).to be_falsey
42
+ queue.delete
43
+ expect(session.queue_exists?('queue.test')).to be_falsey
71
44
 
72
- xchg = channel.exchange 'xchg.test'
73
- expect(session.exchange_exists?('exchange.test')).to be_truthy
45
+ xchg = channel.exchange 'xchg.test'
46
+ expect(session.exchange_exists?('exchange.test')).to be_truthy
74
47
 
75
- xchg.delete
76
- expect(session.exchange_exists?('exchange.test')).to be_falsey
48
+ xchg.delete
49
+ expect(session.exchange_exists?('exchange.test')).to be_falsey
77
50
  end
78
51
  ```
79
52
 
@@ -82,31 +55,31 @@ end
82
55
  ```ruby
83
56
  it 'should publish messages to queues' do
84
57
 
85
- channel = BunnyMock.new.start.channel
86
- queue = channel.queue 'queue.test'
58
+ channel = BunnyMock.new.start.channel
59
+ queue = channel.queue 'queue.test'
87
60
 
88
- queue.publish 'Testing message', priority: 5
61
+ queue.publish 'Testing message', priority: 5
89
62
 
90
- expect(queue.message_count).to eq(1)
63
+ expect(queue.message_count).to eq(1)
91
64
 
92
- payload = queue.pop
93
- expect(queue.message_count).to eq(0)
65
+ payload = queue.pop
66
+ expect(queue.message_count).to eq(0)
94
67
 
95
- expect(payload[:message]).to eq('Testing message')
96
- expect(payload[:options][:priority]).to eq(5)
68
+ expect(payload[:message]).to eq('Testing message')
69
+ expect(payload[:options][:priority]).to eq(5)
97
70
  end
98
71
 
99
72
  it 'should route messages from exchanges' do
100
73
 
101
- channel = BunnyMock.new.start.channel
74
+ channel = BunnyMock.new.start.channel
102
75
 
103
- xchg = channel.topic 'xchg.topic'
104
- queue = channel.queue 'queue.test'
76
+ xchg = channel.topic 'xchg.topic'
77
+ queue = channel.queue 'queue.test'
105
78
 
106
- xchg.publish 'Routed message', routing_key: '*.test'
79
+ xchg.publish 'Routed message', routing_key: '*.test'
107
80
 
108
- expect(queue.message_count).to eq(1)
109
- expect(queue.pop[:message]).to eq('Routed message')
81
+ expect(queue.message_count).to eq(1)
82
+ expect(queue.pop[:message]).to eq('Routed message')
110
83
  end
111
84
  ```
112
85
 
@@ -115,48 +88,48 @@ end
115
88
  ```ruby
116
89
  it 'should bind queues to exchanges' do
117
90
 
118
- channel = BunnyMock.new.start.channel
91
+ channel = BunnyMock.new.start.channel
119
92
 
120
- queue = channel.queue 'queue.test'
121
- xchg = channel.exchange 'xchg.test'
93
+ queue = channel.queue 'queue.test'
94
+ xchg = channel.exchange 'xchg.test'
122
95
 
123
- queue.bind xchg
124
- expect(queue.bound_to?(xchg)).to be_truthy
125
- expect(xchg.has_binding?(queue)).to be_truthy
96
+ queue.bind xchg
97
+ expect(queue.bound_to?(xchg)).to be_truthy
98
+ expect(xchg.routes_to?(queue)).to be_truthy
126
99
 
127
- queue.unbind xchg
128
- expect(queue.bound_to?(xchg)).to be_falsey
129
- expect(xchg.has_binding?(queue)).to be_falsey
100
+ queue.unbind xchg
101
+ expect(queue.bound_to?(xchg)).to be_falsey
102
+ expect(xchg.routes_to?(queue)).to be_falsey
130
103
 
131
- queue.bind 'xchg.test'
132
- expect(queue.bound_to?(xchg)).to be_truthy
133
- expect(xchg.has_binding?(queue)).to be_truthy
104
+ queue.bind 'xchg.test'
105
+ expect(queue.bound_to?(xchg)).to be_truthy
106
+ expect(xchg.routes_to?(queue)).to be_truthy
134
107
  end
135
108
 
136
109
  it 'should bind exchanges to exchanges' do
137
110
 
138
- channel = BunnyMock.new.start.channel
111
+ channel = BunnyMock.new.start.channel
139
112
 
140
- source = channel.exchange 'xchg.source'
141
- receiver = channel.exchange 'xchg.receiver'
113
+ source = channel.exchange 'xchg.source'
114
+ receiver = channel.exchange 'xchg.receiver'
142
115
 
143
- receiver.bind source
144
- expect(receiver.bound_to?(source)).to be_truthy
145
- expect(source.has_binding?(receiver)).to be_truthy
116
+ receiver.bind source
117
+ expect(receiver.bound_to?(source)).to be_truthy
118
+ expect(source.routes_to?(receiver)).to be_truthy
146
119
 
147
- receiver.unbind source
148
- expect(receiver.bound_to?(source)).to be_falsey
149
- expect(xchg.has_binding?(receiver)).to be_falsey
120
+ receiver.unbind source
121
+ expect(receiver.bound_to?(source)).to be_falsey
122
+ expect(xchg.routes_to?(receiver)).to be_falsey
150
123
 
151
- receiver.bind 'xchg.source'
152
- expect(receiver.bound_to?(source)).to be_truthy
153
- expect(source.has_binding?(receiver)).to be_truthy
124
+ receiver.bind 'xchg.source'
125
+ expect(receiver.bound_to?(source)).to be_truthy
126
+ expect(source.routes_to?(receiver)).to be_truthy
154
127
  end
155
128
  ```
156
129
 
157
130
  ## Installation
158
131
 
159
- ### With RubyGems
132
+ #### With RubyGems
160
133
 
161
134
  To install BunnyMock with RubyGems:
162
135
 
@@ -164,7 +137,7 @@ To install BunnyMock with RubyGems:
164
137
  gem install bunny-mock
165
138
  ```
166
139
 
167
- ### With Bundler
140
+ #### With Bundler
168
141
 
169
142
  To use BunnyMock with a Bundler managed project:
170
143
 
@@ -178,9 +151,9 @@ View the documentation on [RubyDoc](http://www.rubydoc.info/github/arempe93/bunn
178
151
 
179
152
  ## Dependencies
180
153
 
181
- * Ruby version >= 2.0
154
+ * [Bunny](https://github.com/ruby-amqp/bunny) - To use original exception classes
182
155
 
183
- * [AMQ Protocol](https://github.com/ruby-amqp/amq-protocol) - Also a dependency of Bunny
156
+ * Ruby version >= 2.0 (A requirement of Bunny)
184
157
 
185
158
  ## License
186
159
 
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup :default, :test, :development
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec) do |spec|
9
+ spec.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
13
+ spec.pattern = 'spec/**/*_spec.rb'
14
+ spec.rcov = true
15
+ end
16
+
17
+ task :spec
18
+
19
+ require 'rubocop/rake_task'
20
+ RuboCop::RakeTask.new
21
+
22
+ task default: [:rubocop, :spec]
23
+
24
+ require 'yard'
25
+ DOC_FILES = ['lib/**/*.rb', 'README.md']
26
+
27
+ YARD::Rake::YardocTask.new(:doc) do |t|
28
+ t.files = DOC_FILES
29
+ end
@@ -0,0 +1,12 @@
1
+ Upgrading BunnyMock
2
+ ===================
3
+
4
+ ## Upgrading to >= 1.2.0
5
+
6
+ #### Changes `has_binding?` to `routes_to?` in `BunnyMock::Exchange`
7
+
8
+ The `has_binding?` helper has been name changed to `routes_to?`. For now, an alias exists for `has_binding?`, but this may be deprecated in version 2.
9
+
10
+ #### Changes to use `Bunny` exceptions, instead of custom
11
+
12
+ Now all exceptions thrown will be the original `Bunny` exceptions
@@ -5,23 +5,26 @@ require 'base64'
5
5
  require File.expand_path("../lib/bunny_mock/version", __FILE__)
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = 'bunny-mock'
9
- s.version = BunnyMock::VERSION.dup
10
- s.summary = 'Mocking for the popular Bunny client for RabbitMQ'
11
- s.description = 'Easy to use mocking for testing the Bunny client for RabbitMQ'
12
- s.license = 'MIT'
13
- s.required_ruby_version = Gem::Requirement.new '>= 2.0'
8
+ s.name = 'bunny-mock'
9
+ s.version = BunnyMock::VERSION.dup
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ['Andrew Rempe']
12
+ s.email = [Base64.decode64('YW5kcmV3cmVtcGVAZ21haWwuY29t\n')]
13
+ s.summary = 'Mocking for the popular Bunny client for RabbitMQ'
14
+ s.description = 'Easy to use mocking for testing the Bunny client for RabbitMQ'
15
+ s.license = 'MIT'
14
16
 
15
- s.authors = [ 'Andrew Rempe' ]
16
- s.email = [ Base64.encode64('YW5kcmV3cmVtcGVAZ21haWwuY29t\n') ]
17
+ s.required_ruby_version = Gem::Requirement.new '>= 2.0'
17
18
 
18
- # Dependencies
19
- s.add_dependency 'amq-protocol', '>= 2.0.1'
19
+ s.add_dependency 'bunny', '~> 2.0'
20
20
 
21
- # Files
22
- s.has_rdoc = true
23
- s.extra_rdoc_files = [ 'README.md' ]
24
- s.files = `git ls-files`.split "\n"
25
- s.test_files = `git ls-files -- spec/*`.split "\n"
26
- s.require_paths = [ 'lib' ]
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'rubocop'
23
+ s.add_development_dependency 'yard'
24
+ s.add_development_dependency 'rspec', '~> 3.4.0'
25
+ s.add_development_dependency 'coveralls'
26
+
27
+ s.files = `git ls-files`.split "\n"
28
+ s.test_files = `git ls-files -- spec/*`.split "\n"
29
+ s.require_paths = [ 'lib' ]
27
30
  end