bunny-mock 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +6 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -2
- data/README.md +2 -2
- data/UPGRADING.md +10 -0
- data/bunny-mock.gemspec +9 -2
- data/lib/bunny-mock.rb +10 -0
- data/lib/bunny_mock/exchange.rb +1 -1
- data/lib/bunny_mock/exchanges/topic.rb +9 -11
- data/lib/bunny_mock/get_response.rb +76 -0
- data/lib/bunny_mock/message_properties.rb +113 -0
- data/lib/bunny_mock/queue.rb +28 -2
- data/lib/bunny_mock/version.rb +1 -1
- data/spec/integration/queue_pop_spec.rb +71 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/bunny_mock/channel_spec.rb +3 -3
- data/spec/unit/bunny_mock/exchanges/direct_spec.rb +1 -1
- data/spec/unit/bunny_mock/exchanges/fanout_spec.rb +3 -3
- data/spec/unit/bunny_mock/exchanges/topic_spec.rb +28 -61
- data/spec/unit/bunny_mock/queue_spec.rb +40 -5
- data/spec/unit/bunny_mock_spec.rb +0 -14
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d54d4507d1c57efad12f4d1525154cde983b98b7
|
4
|
+
data.tar.gz: d5986217aed023311d8ac3903627d36cbead2a10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a3e975090251bcbe4dcf40d4534e1c2382e151b50280a59d2524a20485a30c9bfff7ed34af448f3a5fbce9c481aa0fcc0f4184568c98caa73eac06bf013905
|
7
|
+
data.tar.gz: 81960ae54b49872107f122ed8c681934392940dd3698fe0c20a3736fbf3aafd8244925edae01858b3b0133af99a1cb880c3759ae730076bd7873f105f52a2208
|
data/.rubocop_todo.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-
|
3
|
+
# on 2016-05-17 11:57:32 -0400 using RuboCop version 0.39.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 45
|
10
10
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
11
11
|
# URISchemes: http, https
|
12
12
|
Metrics/LineLength:
|
13
|
-
Max:
|
13
|
+
Max: 145
|
14
14
|
|
15
|
-
# Offense count:
|
15
|
+
# Offense count: 9
|
16
16
|
Style/Documentation:
|
17
17
|
Exclude:
|
18
18
|
- 'spec/**/*'
|
@@ -23,4 +23,6 @@ Style/Documentation:
|
|
23
23
|
- 'lib/bunny_mock/exchanges/fanout.rb'
|
24
24
|
- 'lib/bunny_mock/exchanges/headers.rb'
|
25
25
|
- 'lib/bunny_mock/exchanges/topic.rb'
|
26
|
+
- 'lib/bunny_mock/get_response.rb'
|
27
|
+
- 'lib/bunny_mock/message_properties.rb'
|
26
28
|
- 'lib/bunny_mock/queue.rb'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## v1.4.0
|
2
|
+
|
3
|
+
* [#19](https://github.com/arempe93/bunny-mock/pull/12): Adds support for JRuby with Bunny 1.7.0 - [@TimothyMDean](https://github.com/TimothyMDean)
|
4
|
+
* [#16](https://github.com/arempe93/bunny-mock/issues/16): Fixes wildcard implementation for topic exchanges - [@arempe93](https://github.com/arempe93)
|
5
|
+
* [#15](https://github.com/arempe93/bunny-mock/issues/15): Changes to `Queue#pop` api to match Bunny - [@arempe93](https://github.com/arempe93)
|
6
|
+
|
1
7
|
## v1.3.0
|
2
8
|
|
3
9
|
* [#12](https://github.com/arempe93/bunny-mock/pull/12): Adds `basic_publish` functionality to `Channel` - [@podung](https://github.com/podung)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -80,8 +80,8 @@ it 'should route messages from exchanges' do
|
|
80
80
|
xchg = channel.topic 'xchg.topic'
|
81
81
|
queue = channel.queue 'queue.test'
|
82
82
|
|
83
|
-
queue.bind xchg
|
84
|
-
xchg.publish 'Routed message', routing_key: '
|
83
|
+
queue.bind xchg, routing_key: '*.test'
|
84
|
+
xchg.publish 'Routed message', routing_key: 'foo.test'
|
85
85
|
|
86
86
|
expect(queue.message_count).to eq(1)
|
87
87
|
expect(queue.pop[:message]).to eq('Routed message')
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
Upgrading BunnyMock
|
2
2
|
===================
|
3
3
|
|
4
|
+
## Upgrading to >= 1.4.0
|
5
|
+
|
6
|
+
#### Changes to `Queue#pop` api
|
7
|
+
|
8
|
+
The implmentation of `BunnyMock::Queue#pop` has changed to support the same return value as `Bunny`. The old functionality is still enabled by default. To use the new functionality that matches `Bunny`, place the following in your `spec_helper.rb` or etc.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
BunnyMock.use_bunny_queue_pop_api = true
|
12
|
+
```
|
13
|
+
|
4
14
|
## Upgrading to >= 1.2.0
|
5
15
|
|
6
16
|
#### Changes `has_binding?` to `routes_to?` in `BunnyMock::Exchange`
|
data/bunny-mock.gemspec
CHANGED
@@ -14,9 +14,16 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.description = 'Easy to use mocking for testing the Bunny client for RabbitMQ'
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
17
|
-
s.required_ruby_version = Gem::Requirement.new '>=
|
17
|
+
s.required_ruby_version = Gem::Requirement.new '>= 1.9'
|
18
18
|
|
19
|
-
|
19
|
+
# Bunny 1.7.0 is known to work with JRuby, but unsupported after that.
|
20
|
+
# Other Ruby platforms are expected to work on any 1.7.x version or later.
|
21
|
+
if RUBY_PLATFORM == 'java'
|
22
|
+
s.add_dependency 'amq-protocol', '<= 1.9.2'
|
23
|
+
s.add_dependency 'bunny', '1.7.0'
|
24
|
+
else
|
25
|
+
s.add_dependency 'bunny', '>= 1.7'
|
26
|
+
end
|
20
27
|
|
21
28
|
s.add_development_dependency 'rake', '~> 10.5.0'
|
22
29
|
s.add_development_dependency 'rubocop'
|
data/lib/bunny-mock.rb
CHANGED
@@ -4,6 +4,9 @@ require 'bunny_mock/version'
|
|
4
4
|
require 'bunny/exceptions'
|
5
5
|
require 'amq/protocol/client'
|
6
6
|
|
7
|
+
require 'bunny_mock/get_response'
|
8
|
+
require 'bunny_mock/message_properties'
|
9
|
+
|
7
10
|
require 'bunny_mock/session'
|
8
11
|
require 'bunny_mock/channel'
|
9
12
|
require 'bunny_mock/exchange'
|
@@ -24,6 +27,8 @@ module BunnyMock
|
|
24
27
|
PROTOCOL_VERSION = AMQ::Protocol::PROTOCOL_VERSION
|
25
28
|
|
26
29
|
class << self
|
30
|
+
attr_writer :use_bunny_queue_pop_api
|
31
|
+
|
27
32
|
#
|
28
33
|
# API
|
29
34
|
#
|
@@ -38,6 +43,11 @@ module BunnyMock
|
|
38
43
|
BunnyMock::Session.new
|
39
44
|
end
|
40
45
|
|
46
|
+
# @return [Boolean] Use Bunny API for Queue#pop (default: false)
|
47
|
+
def use_bunny_queue_pop_api
|
48
|
+
@use_bunny_queue_pop_api.nil? ? false : @use_bunny_queue_pop_api
|
49
|
+
end
|
50
|
+
|
41
51
|
# @return [String] Bunny mock version
|
42
52
|
def version
|
43
53
|
VERSION
|
data/lib/bunny_mock/exchange.rb
CHANGED
@@ -114,7 +114,7 @@ module BunnyMock
|
|
114
114
|
#
|
115
115
|
def publish(payload, opts = {})
|
116
116
|
# handle message sending, varies by type
|
117
|
-
deliver
|
117
|
+
deliver(payload, opts.merge(exchange: name), opts.fetch(:routing_key, ''))
|
118
118
|
|
119
119
|
self
|
120
120
|
end
|
@@ -24,21 +24,19 @@ module BunnyMock
|
|
24
24
|
# @api public
|
25
25
|
#
|
26
26
|
def deliver(payload, opts, key)
|
27
|
-
|
28
|
-
|
27
|
+
delivery_routes = @routes.dup.keep_if { |route, _| key =~ route_to_regex(route) }
|
28
|
+
delivery_routes.values.each { |dest| dest.publish(payload, opts) }
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
|
31
|
+
private
|
32
32
|
|
33
|
-
|
33
|
+
# @private
|
34
|
+
def route_to_regex(key)
|
35
|
+
key = key.gsub('.', '\.')
|
36
|
+
key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
|
34
37
|
key = key.gsub(MULTI_WILDCARD, '\w+\.?')
|
35
38
|
|
36
|
-
|
37
|
-
key = Regexp.new(key)
|
38
|
-
|
39
|
-
@routes.each do |route, destination|
|
40
|
-
destination.publish(payload, opts) if route =~ key
|
41
|
-
end
|
39
|
+
Regexp.new(key)
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BunnyMock
|
3
|
+
class GetResponse
|
4
|
+
#
|
5
|
+
# Behavior
|
6
|
+
#
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
#
|
11
|
+
# API
|
12
|
+
#
|
13
|
+
|
14
|
+
# @return [BunnyMock::Channel] Channel the response is from
|
15
|
+
attr_reader :channel
|
16
|
+
|
17
|
+
# @private
|
18
|
+
def initialize(channel, queue, opts = {})
|
19
|
+
@channel = channel
|
20
|
+
@hash = {
|
21
|
+
delivery_tag: '',
|
22
|
+
redelivered: false,
|
23
|
+
exchange: opts.fetch(:exchange, ''),
|
24
|
+
routing_key: opts.fetch(:routing_key, queue.name)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Iterates over the delivery properties
|
29
|
+
# @see Enumerable#each
|
30
|
+
def each(*args, &block)
|
31
|
+
@hash.each(*args, &block)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Accesses delivery properties by key
|
35
|
+
# @see Hash#[]
|
36
|
+
def [](k)
|
37
|
+
@hash[k]
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash] Hash representation of this delivery info
|
41
|
+
def to_hash
|
42
|
+
@hash
|
43
|
+
end
|
44
|
+
|
45
|
+
# @private
|
46
|
+
def to_s
|
47
|
+
to_hash.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
# @private
|
51
|
+
def inspect
|
52
|
+
to_hash.inspect
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] Delivery identifier that is used to acknowledge, reject and nack deliveries
|
56
|
+
def delivery_tag
|
57
|
+
@hash[:delivery_tag]
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Boolean] true if this delivery is a redelivery (the message was requeued at least once)
|
61
|
+
def redelivered
|
62
|
+
@hash[:redelivered]
|
63
|
+
end
|
64
|
+
alias redelivered? redelivered
|
65
|
+
|
66
|
+
# @return [String] Name of the exchange this message was published to
|
67
|
+
def exchange
|
68
|
+
@hash[:exchange]
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [String] Routing key this message was published with
|
72
|
+
def routing_key
|
73
|
+
@hash[:routing_key]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module BunnyMock
|
3
|
+
class MessageProperties
|
4
|
+
#
|
5
|
+
# Behaviors
|
6
|
+
#
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
#
|
11
|
+
# API
|
12
|
+
#
|
13
|
+
|
14
|
+
# @private
|
15
|
+
def initialize(properties)
|
16
|
+
properties.delete :exchange
|
17
|
+
@properties = properties
|
18
|
+
end
|
19
|
+
|
20
|
+
# Iterate over the properties
|
21
|
+
# @see Enumerable#each
|
22
|
+
def each(*args, &block)
|
23
|
+
@properties.each(*args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Access properties by key
|
27
|
+
# @see Hash#[]
|
28
|
+
def [](key)
|
29
|
+
@properties[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Hash] Hash of message properties
|
33
|
+
def to_hash
|
34
|
+
@properties
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String] String representation of message properties
|
38
|
+
def to_s
|
39
|
+
to_hash.to_s
|
40
|
+
end
|
41
|
+
alias inspect to_s
|
42
|
+
|
43
|
+
# @return [String] (Optional) content type of the message, as set by the publisher
|
44
|
+
def content_type
|
45
|
+
@properties[:content_type]
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] (Optional) content encoding of the message, as set by the publisher
|
49
|
+
def content_encoding
|
50
|
+
@properties[:content_encoding]
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [String] Message headers
|
54
|
+
def headers
|
55
|
+
@properties[:headers]
|
56
|
+
end
|
57
|
+
|
58
|
+
# @return [Integer] Delivery mode (persistent or transient)
|
59
|
+
def delivery_mode
|
60
|
+
@properties[:delivery_mode]
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Integer] Message priority, as set by the publisher
|
64
|
+
def priority
|
65
|
+
@properties[:priority]
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [String] What message this message is a reply to (or corresponds to), as set by the publisher
|
69
|
+
def correlation_id
|
70
|
+
@properties[:correlation_id]
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [String] (Optional) How to reply to the publisher (usually a reply queue name)
|
74
|
+
def reply_to
|
75
|
+
@properties[:reply_to]
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [String] Message expiration, as set by the publisher
|
79
|
+
def expiration
|
80
|
+
@properties[:expiration]
|
81
|
+
end
|
82
|
+
|
83
|
+
# @return [String] Message ID, as set by the publisher
|
84
|
+
def message_id
|
85
|
+
@properties[:message_id]
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Time] Message timestamp, as set by the publisher
|
89
|
+
def timestamp
|
90
|
+
@properties[:timestamp]
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [String] Message type, as set by the publisher
|
94
|
+
def type
|
95
|
+
@properties[:type]
|
96
|
+
end
|
97
|
+
|
98
|
+
# @return [String] Publishing user, as set by the publisher
|
99
|
+
def user_id
|
100
|
+
@properties[:user_id]
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [String] Publishing application, as set by the publisher
|
104
|
+
def app_id
|
105
|
+
@properties[:app_id]
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [String] Cluster ID, as set by the publisher
|
109
|
+
def cluster_id
|
110
|
+
@properties[:cluster_id]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
data/lib/bunny_mock/queue.rb
CHANGED
@@ -160,9 +160,15 @@ module BunnyMock
|
|
160
160
|
# @return [Hash] Message data
|
161
161
|
# @api public
|
162
162
|
#
|
163
|
-
def pop
|
164
|
-
|
163
|
+
def pop(opts = { manual_ack: false }, &block)
|
164
|
+
if BunnyMock.use_bunny_queue_pop_api
|
165
|
+
bunny_pop(opts, &block)
|
166
|
+
else
|
167
|
+
warn '[DEPRECATED] This behavior is deprecated - please set `BunnyMock::use_bunny_queue_pop_api` to true to use Bunny Queue#pop behavior'
|
168
|
+
@messages.shift
|
169
|
+
end
|
165
170
|
end
|
171
|
+
alias get pop
|
166
172
|
|
167
173
|
##
|
168
174
|
# Clear all messages in queue
|
@@ -171,6 +177,8 @@ module BunnyMock
|
|
171
177
|
#
|
172
178
|
def purge
|
173
179
|
@messages = []
|
180
|
+
|
181
|
+
self
|
174
182
|
end
|
175
183
|
|
176
184
|
##
|
@@ -193,9 +201,27 @@ module BunnyMock
|
|
193
201
|
@deleted = true
|
194
202
|
end
|
195
203
|
|
204
|
+
private
|
205
|
+
|
196
206
|
# @private
|
197
207
|
def check_queue_deleted!
|
198
208
|
raise 'Queue has been deleted' if @deleted
|
199
209
|
end
|
210
|
+
|
211
|
+
# @private
|
212
|
+
def bunny_pop(*)
|
213
|
+
response = pop_response(@messages.shift)
|
214
|
+
block_given? ? yield(*response) : response
|
215
|
+
end
|
216
|
+
|
217
|
+
# @private
|
218
|
+
def pop_response(message)
|
219
|
+
return [nil, nil, nil] unless message
|
220
|
+
|
221
|
+
di = GetResponse.new(@channel, self, message[:options])
|
222
|
+
mp = MessageProperties.new(message[:options])
|
223
|
+
|
224
|
+
[di, mp, message[:message]]
|
225
|
+
end
|
200
226
|
end
|
201
227
|
end
|
data/lib/bunny_mock/version.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
describe BunnyMock::Queue, '#pop' do
|
2
|
+
let(:queue) { @channel.queue('test.q') }
|
3
|
+
let(:exchange) { @channel.topic('test.exchange') }
|
4
|
+
let(:options) { { priority: 1, persistent: true, routing_key: 'test.q' } }
|
5
|
+
|
6
|
+
before { queue.bind(exchange, routing_key: '*.q') }
|
7
|
+
|
8
|
+
context 'when published through an exchange' do
|
9
|
+
before do
|
10
|
+
exchange.publish('Message', options)
|
11
|
+
@di, @mp, @pl = queue.pop
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have exchange name set in delivery info' do
|
15
|
+
expect(@di.exchange).to eql exchange.name
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have message properties persisted' do
|
19
|
+
expect(@mp.to_hash).to eql options
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should have routing key set in delivery info' do
|
23
|
+
expect(@di.routing_key).to eql options[:routing_key]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when published through many exchanges' do
|
28
|
+
let(:options) { { priority: 1, persistent: true, routing_key: 'test.q' } }
|
29
|
+
|
30
|
+
before do
|
31
|
+
exchange2 = @channel.topic 'test.exchange2'
|
32
|
+
exchange.bind(exchange2, routing_key: 'test.*')
|
33
|
+
|
34
|
+
exchange2.publish('Message', options)
|
35
|
+
@di, @mp, @pl = queue.pop
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have last exchange name set in delivery info' do
|
39
|
+
expect(@di.exchange).to eql exchange.name
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have message properties persisted' do
|
43
|
+
expect(@mp.to_hash).to eql options
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should have routing key set in delivery info' do
|
47
|
+
expect(@di.routing_key).to eql options[:routing_key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when published directly' do
|
52
|
+
let(:options) { { priority: 1, persistent: true, routing_key: 'something.random' } }
|
53
|
+
|
54
|
+
before do
|
55
|
+
queue.publish('Message', options)
|
56
|
+
@di, @mp, @pl = queue.pop
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should not have exchange name set in delivery info' do
|
60
|
+
expect(@di.exchange).to eql ''
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should have message properties persisted' do
|
64
|
+
expect(@mp.to_hash).to eql options
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have routing key set in delivery info' do
|
68
|
+
expect(@di.routing_key).to eql options[:routing_key]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -135,19 +135,19 @@ describe BunnyMock::Channel do
|
|
135
135
|
it 'should publish to the exchange' do
|
136
136
|
@channel.basic_publish(data, xchg_name, key)
|
137
137
|
|
138
|
-
expect(queue.pop[
|
138
|
+
expect(queue.pop[2]).to eq data
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'accepts exchange object for exchange param' do
|
142
142
|
@channel.basic_publish(data, xchg, key)
|
143
143
|
|
144
|
-
expect(queue.pop[
|
144
|
+
expect(queue.pop[2]).to eq data
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'passes opts down to exchange' do
|
148
148
|
@channel.basic_publish(data, xchg, key, extra: 'opts')
|
149
149
|
|
150
|
-
expect(queue.pop[
|
150
|
+
expect(queue.pop[1].to_hash).to include(extra: 'opts')
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'creates exchange if it does not exist' do
|
@@ -18,13 +18,13 @@ describe BunnyMock::Exchanges::Fanout do
|
|
18
18
|
@source.publish 'Testing message', routing_key: 'queue.second'
|
19
19
|
|
20
20
|
expect(@first.message_count).to eq(1)
|
21
|
-
expect(@first.pop[
|
21
|
+
expect(@first.pop[2]).to eq('Testing message')
|
22
22
|
|
23
23
|
expect(@second.message_count).to eq(1)
|
24
|
-
expect(@second.pop[
|
24
|
+
expect(@second.pop[2]).to eq('Testing message')
|
25
25
|
|
26
26
|
expect(@third.message_count).to eq(1)
|
27
|
-
expect(@third.pop[
|
27
|
+
expect(@third.pop[2]).to eq('Testing message')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,72 +1,39 @@
|
|
1
1
|
describe BunnyMock::Exchanges::Topic do
|
2
|
+
context '#deliver' do
|
3
|
+
before do
|
4
|
+
@source = @channel.topic 'xchg.source'
|
2
5
|
|
3
|
-
|
6
|
+
@first = @channel.queue 'queue.#'
|
7
|
+
@second = @channel.queue 'queue.*.sub'
|
8
|
+
@third = @channel.queue 'queue.*.sub.#'
|
4
9
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@first = @channel.queue 'queue.category.sub.first'
|
9
|
-
@second = @channel.queue 'queue.category.second'
|
10
|
-
@third = @channel.queue 'queue.topic.sub.third'
|
11
|
-
|
12
|
-
@first.bind @source
|
13
|
-
@second.bind @source
|
14
|
-
@third.bind @source
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should deliver with no wildcards' do
|
18
|
-
@source.publish 'Testing message', routing_key: 'queue.category.second'
|
19
|
-
|
20
|
-
expect(@first.message_count).to eq(0)
|
21
|
-
expect(@third.message_count).to eq(0)
|
22
|
-
|
23
|
-
expect(@second.message_count).to eq(1)
|
24
|
-
expect(@second.pop[:message]).to eq('Testing message')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'does not modify the routing key' do
|
28
|
-
@source.publish 'Testing message',
|
29
|
-
routing_key: 'queue.category.sub.first'.freeze
|
30
|
-
expect(message = @first.pop).to_not be_nil
|
31
|
-
expect(message[:options][:routing_key]).to eq('queue.category.sub.first')
|
10
|
+
@first.bind @source
|
11
|
+
@second.bind @source
|
12
|
+
@third.bind @source
|
32
13
|
end
|
33
14
|
|
34
|
-
|
35
|
-
|
36
|
-
@source.publish 'Testing message', routing_key: 'queue.*.sub.*'
|
37
|
-
|
38
|
-
expect(@second.message_count).to eq(0)
|
15
|
+
it 'should deliver to multiple wildcard' do
|
16
|
+
@source.publish 'Test', routing_key: 'queue.anything.after.here'
|
39
17
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
expect(@third.pop[:message]).to eq('Testing message')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'for multiple wildcards' do
|
48
|
-
@source.publish 'Testing message', routing_key: 'queue.category.#'
|
49
|
-
|
50
|
-
expect(@third.message_count).to eq(0)
|
51
|
-
|
52
|
-
expect(@first.message_count).to eq(1)
|
53
|
-
expect(@first.pop[:message]).to eq('Testing message')
|
54
|
-
|
55
|
-
expect(@second.message_count).to eq(1)
|
56
|
-
expect(@second.pop[:message]).to eq('Testing message')
|
57
|
-
end
|
18
|
+
expect(@first.message_count).to eql 1
|
19
|
+
expect(@second.message_count).to eql 0
|
20
|
+
expect(@third.message_count).to eql 0
|
21
|
+
end
|
58
22
|
|
59
|
-
|
60
|
-
|
23
|
+
it 'should deliver to single wildcards' do
|
24
|
+
@source.publish 'Test', routing_key: 'queue.category.sub'
|
61
25
|
|
62
|
-
|
26
|
+
expect(@first.message_count).to eql 1
|
27
|
+
expect(@second.message_count).to eql 1
|
28
|
+
expect(@third.message_count).to eql 0
|
29
|
+
end
|
63
30
|
|
64
|
-
|
65
|
-
|
31
|
+
it 'should deliver for mixed wildcards' do
|
32
|
+
@source.publish 'Test', routing_key: 'queue.category.sub.third'
|
66
33
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
34
|
+
expect(@first.message_count).to eql 1
|
35
|
+
expect(@second.message_count).to eql 1
|
36
|
+
expect(@third.message_count).to eql 1
|
37
|
+
end
|
38
|
+
end
|
72
39
|
end
|
@@ -10,7 +10,7 @@ describe BunnyMock::Queue do
|
|
10
10
|
@queue.publish 'This is a test message'
|
11
11
|
|
12
12
|
expect(@queue.message_count).to eq(1)
|
13
|
-
expect(@queue.pop[
|
13
|
+
expect(@queue.pop[2]).to eq('This is a test message')
|
14
14
|
expect(@queue.message_count).to eq(0)
|
15
15
|
end
|
16
16
|
end
|
@@ -120,12 +120,47 @@ describe BunnyMock::Queue do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
context '#pop' do
|
123
|
+
context 'when using old api' do
|
124
|
+
before { BunnyMock::use_bunny_queue_pop_api = false }
|
125
|
+
after { BunnyMock::use_bunny_queue_pop_api = true }
|
123
126
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
+
it 'should return a Hash' do
|
128
|
+
@queue.publish 'First', priority: 1
|
129
|
+
response = @queue.pop
|
130
|
+
|
131
|
+
expect(response[:message]).to eql 'First'
|
132
|
+
expect(response[:options][:priority]).to eql 1
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should output a deprecation warning' do
|
136
|
+
expect { @queue.pop }.to output(/DEPRECATED/).to_stderr
|
137
|
+
end
|
138
|
+
end
|
127
139
|
|
128
|
-
|
140
|
+
context 'when using Bunny api' do
|
141
|
+
before { BunnyMock::use_bunny_queue_pop_api = true }
|
142
|
+
after { BunnyMock::use_bunny_queue_pop_api = false }
|
143
|
+
|
144
|
+
context 'when queue if empty' do
|
145
|
+
it 'should return a nil triplet' do
|
146
|
+
expect(@queue.pop).to eql [nil, nil, nil]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when queue has messages' do
|
151
|
+
before { @queue.publish('First') }
|
152
|
+
|
153
|
+
it 'should return triplet of GetResponse, MessageProperties, and payload' do
|
154
|
+
response = @queue.pop
|
155
|
+
expect(response.map(&:class)).to eql [BunnyMock::GetResponse, BunnyMock::MessageProperties, String]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when using block' do
|
160
|
+
it 'should yield' do
|
161
|
+
expect { |b| @queue.pop(&b) }.to yield_control
|
162
|
+
end
|
163
|
+
end
|
129
164
|
end
|
130
165
|
end
|
131
166
|
|
@@ -1,14 +1,11 @@
|
|
1
1
|
describe BunnyMock do
|
2
|
-
|
3
2
|
context '::new' do
|
4
|
-
|
5
3
|
it 'should return a new session' do
|
6
4
|
expect(BunnyMock.new.class).to eq(BunnyMock::Session)
|
7
5
|
end
|
8
6
|
end
|
9
7
|
|
10
8
|
context '::version' do
|
11
|
-
|
12
9
|
it 'should return the current version' do
|
13
10
|
expect(BunnyMock::VERSION).to_not be_nil
|
14
11
|
expect(BunnyMock.version).to_not be_nil
|
@@ -16,20 +13,9 @@ describe BunnyMock do
|
|
16
13
|
end
|
17
14
|
|
18
15
|
context '::protocol_version' do
|
19
|
-
|
20
16
|
it 'should return the current amq protocol version' do
|
21
17
|
expect(BunnyMock::PROTOCOL_VERSION).to eq('0.9.1')
|
22
18
|
expect(BunnyMock.protocol_version).to eq('0.9.1')
|
23
19
|
end
|
24
20
|
end
|
25
|
-
|
26
|
-
it 'should route messages from exchanges' do
|
27
|
-
channel = BunnyMock.new.start.channel
|
28
|
-
|
29
|
-
xchg = channel.topic 'xchg.topic'
|
30
|
-
queue = channel.queue 'queue.test'
|
31
|
-
|
32
|
-
queue.bind xchg
|
33
|
-
xchg.publish('Routed message', routing_key: '*.test')
|
34
|
-
end
|
35
21
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Rempe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,9 +123,12 @@ files:
|
|
123
123
|
- lib/bunny_mock/exchanges/fanout.rb
|
124
124
|
- lib/bunny_mock/exchanges/headers.rb
|
125
125
|
- lib/bunny_mock/exchanges/topic.rb
|
126
|
+
- lib/bunny_mock/get_response.rb
|
127
|
+
- lib/bunny_mock/message_properties.rb
|
126
128
|
- lib/bunny_mock/queue.rb
|
127
129
|
- lib/bunny_mock/session.rb
|
128
130
|
- lib/bunny_mock/version.rb
|
131
|
+
- spec/integration/queue_pop_spec.rb
|
129
132
|
- spec/spec_helper.rb
|
130
133
|
- spec/unit/bunny_mock/channel_spec.rb
|
131
134
|
- spec/unit/bunny_mock/exchange_spec.rb
|
@@ -147,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
150
|
requirements:
|
148
151
|
- - ">="
|
149
152
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
153
|
+
version: '1.9'
|
151
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
155
|
requirements:
|
153
156
|
- - ">="
|
@@ -160,6 +163,7 @@ signing_key:
|
|
160
163
|
specification_version: 4
|
161
164
|
summary: Mocking for the popular Bunny client for RabbitMQ
|
162
165
|
test_files:
|
166
|
+
- spec/integration/queue_pop_spec.rb
|
163
167
|
- spec/spec_helper.rb
|
164
168
|
- spec/unit/bunny_mock/channel_spec.rb
|
165
169
|
- spec/unit/bunny_mock/exchange_spec.rb
|