bunny-mock 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +8 -28
- data/CHANGELOG.md +4 -0
- data/README.md +5 -0
- data/lib/bunny-mock.rb +26 -23
- data/lib/bunny_mock/exchange.rb +33 -26
- data/lib/bunny_mock/exchanges/topic.rb +3 -3
- data/lib/bunny_mock/version.rb +1 -1
- data/spec/unit/bunny_mock/channel_spec.rb +0 -34
- data/spec/unit/bunny_mock/exchange_spec.rb +113 -130
- data/spec/unit/bunny_mock/exchanges/direct_spec.rb +0 -1
- data/spec/unit/bunny_mock/exchanges/fanout_spec.rb +0 -1
- data/spec/unit/bunny_mock/exchanges/topic_spec.rb +8 -6
- data/spec/unit/bunny_mock/queue_spec.rb +109 -127
- data/spec/unit/bunny_mock/session_spec.rb +0 -11
- data/spec/unit/bunny_mock_spec.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3808cb4a1e923e7b48519a07ecb6d2acaa235da2
|
4
|
+
data.tar.gz: 93726320854a4f15bd18f5b5f485d24d4c901293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 883f34380ad7b9720c1cbc8ae0f41ca71676cf82e6d9ec716778bc91710a79c3fb940a6631bf4a169182c75a74a46c255cebff97df7c30fef404f79a4981f5e4
|
7
|
+
data.tar.gz: 20406048e9c1f232892e64825fb3d7119a884623ac8457da1824d0b161614e74cc280ad17a3eb8908e9e684eae287c47384caa8175ea6a1fb9547bde7bb49599
|
data/.rubocop_todo.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-02-
|
3
|
+
# on 2016-02-24 14:28:43 -0500 using RuboCop version 0.37.2.
|
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: 38
|
10
10
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
11
11
|
# URISchemes: http, https
|
12
12
|
Metrics/LineLength:
|
13
|
-
Max:
|
13
|
+
Max: 128
|
14
14
|
|
15
15
|
# Offense count: 7
|
16
16
|
Style/Documentation:
|
@@ -25,41 +25,21 @@ Style/Documentation:
|
|
25
25
|
- 'lib/bunny_mock/exchanges/topic.rb'
|
26
26
|
- 'lib/bunny_mock/queue.rb'
|
27
27
|
|
28
|
-
# Offense count:
|
28
|
+
# Offense count: 9
|
29
29
|
# Cop supports --auto-correct.
|
30
30
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
31
31
|
# SupportedStyles: empty_lines, no_empty_lines
|
32
32
|
Style/EmptyLinesAroundClassBody:
|
33
|
-
|
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'
|
33
|
+
Enabled: false
|
42
34
|
|
43
35
|
# Offense count: 36
|
44
36
|
# Cop supports --auto-correct.
|
45
37
|
Style/EmptyLinesAroundMethodBody:
|
46
|
-
|
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'
|
38
|
+
Enabled: false
|
56
39
|
|
57
|
-
# Offense count:
|
40
|
+
# Offense count: 2
|
58
41
|
# Cop supports --auto-correct.
|
59
42
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
60
43
|
# SupportedStyles: empty_lines, no_empty_lines
|
61
44
|
Style/EmptyLinesAroundModuleBody:
|
62
|
-
|
63
|
-
- 'lib/bunny-mock.rb'
|
64
|
-
- 'lib/bunny_mock/exceptions.rb'
|
65
|
-
- 'lib/bunny_mock/version.rb'
|
45
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -127,6 +127,11 @@ it 'should bind exchanges to exchanges' do
|
|
127
127
|
end
|
128
128
|
```
|
129
129
|
|
130
|
+
## Other features
|
131
|
+
|
132
|
+
This gem was made based on my own use of Bunny in a project. If there are other uses for Bunny that this library does not cover (eg. missing methods, functionality), feel free to open an issue or pull request!
|
133
|
+
|
134
|
+
|
130
135
|
## Installation
|
131
136
|
|
132
137
|
#### With RubyGems
|
data/lib/bunny-mock.rb
CHANGED
@@ -24,28 +24,31 @@ module BunnyMock
|
|
24
24
|
# AMQP protocol version
|
25
25
|
PROTOCOL_VERSION = AMQ::Protocol::PROTOCOL_VERSION
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
27
|
+
class << self
|
28
|
+
|
29
|
+
#
|
30
|
+
# API
|
31
|
+
#
|
32
|
+
|
33
|
+
##
|
34
|
+
# Instantiate a new mock Bunny session
|
35
|
+
#
|
36
|
+
# @return [BunnyMock::Session] Session instance
|
37
|
+
# @api public
|
38
|
+
def new(*)
|
39
|
+
|
40
|
+
# return new mock session
|
41
|
+
BunnyMock::Session.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String] Bunny mock version
|
45
|
+
def version
|
46
|
+
VERSION
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String] AMQP protocol version
|
50
|
+
def protocol_version
|
51
|
+
AMQ::Protocol::PROTOCOL_VERSION
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
data/lib/bunny_mock/exchange.rb
CHANGED
@@ -2,31 +2,34 @@
|
|
2
2
|
module BunnyMock
|
3
3
|
class Exchange
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
5
|
+
class << self
|
6
|
+
|
7
|
+
##
|
8
|
+
# Create a new {BunnyMock::Exchange} instance
|
9
|
+
#
|
10
|
+
# @param [BunnyMock::Channel] channel Channel this exchange will use
|
11
|
+
# @param [String] name Name of exchange
|
12
|
+
# @param [Hash] opts Creation options
|
13
|
+
#
|
14
|
+
# @option opts [Boolean] :durable (false) Should this exchange be durable?
|
15
|
+
# @option opts [Boolean] :auto_delete (false) Should this exchange be automatically deleted when it is no longer used?
|
16
|
+
# @option opts [Boolean] :arguments ({}) Additional optional arguments (typically used by RabbitMQ extensions and plugins)
|
17
|
+
#
|
18
|
+
# @return [BunnyMock::Exchange] A new exchange
|
19
|
+
# @see BunnyMock::Channel#exchange
|
20
|
+
# @api public
|
21
|
+
#
|
22
|
+
def declare(channel, name = '', opts = {})
|
23
|
+
|
24
|
+
# get requested type
|
25
|
+
type = opts.fetch :type, :direct
|
26
|
+
|
27
|
+
# get needed class type
|
28
|
+
klazz = BunnyMock::Exchanges.const_get type.to_s.capitalize
|
29
|
+
|
30
|
+
# create exchange of desired type
|
31
|
+
klazz.new channel, name, type, opts
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
#
|
@@ -228,7 +231,11 @@ module BunnyMock
|
|
228
231
|
|
229
232
|
@routes.key? opts.fetch(:routing_key, route)
|
230
233
|
end
|
231
|
-
|
234
|
+
|
235
|
+
def has_binding?(exchange_or_queue, opts = {}) # rubocop:disable Style/PredicateName
|
236
|
+
warn '[DEPRECATED] `has_binding?` is deprecated. Please use `routes_to?` instead.'
|
237
|
+
routes_to?(exchange_or_queue, opts)
|
238
|
+
end
|
232
239
|
|
233
240
|
##
|
234
241
|
# Deliver a message to routes
|
@@ -27,13 +27,13 @@ module BunnyMock
|
|
27
27
|
def deliver(payload, opts, key)
|
28
28
|
|
29
29
|
# escape periods with backslash for regex
|
30
|
-
key.gsub
|
30
|
+
key = key.gsub('.', '\.')
|
31
31
|
|
32
32
|
# replace single wildcards with regex for a single domain
|
33
|
-
key.gsub
|
33
|
+
key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
|
34
34
|
|
35
35
|
# replace multi wildcards with regex for many domains separated by '.'
|
36
|
-
key.gsub
|
36
|
+
key = key.gsub(MULTI_WILDCARD, '\w+\.?')
|
37
37
|
|
38
38
|
# turn key into regex
|
39
39
|
key = Regexp.new(key)
|
data/lib/bunny_mock/version.rb
CHANGED
@@ -7,17 +7,14 @@ describe BunnyMock::Channel do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should store connection' do
|
10
|
-
|
11
10
|
expect(@channel.connection).to eq(@session)
|
12
11
|
end
|
13
12
|
|
14
13
|
it 'should store channel identifier' do
|
15
|
-
|
16
14
|
expect(@channel.id).to eq(1)
|
17
15
|
end
|
18
16
|
|
19
17
|
it 'should set status to opening' do
|
20
|
-
|
21
18
|
expect(@channel.status).to eq(:opening)
|
22
19
|
end
|
23
20
|
end
|
@@ -25,7 +22,6 @@ describe BunnyMock::Channel do
|
|
25
22
|
context '#open' do
|
26
23
|
|
27
24
|
it 'should set status to open' do
|
28
|
-
|
29
25
|
expect(@channel.open.status).to eq(:open)
|
30
26
|
end
|
31
27
|
end
|
@@ -33,9 +29,7 @@ describe BunnyMock::Channel do
|
|
33
29
|
context '#close' do
|
34
30
|
|
35
31
|
it 'should set status to open' do
|
36
|
-
|
37
32
|
@channel.open
|
38
|
-
|
39
33
|
expect(@channel.close.status).to eq(:closed)
|
40
34
|
end
|
41
35
|
end
|
@@ -43,16 +37,11 @@ describe BunnyMock::Channel do
|
|
43
37
|
context '#open?' do
|
44
38
|
|
45
39
|
it 'should return true if status is open' do
|
46
|
-
|
47
40
|
expect(@channel.open?).to be_truthy
|
48
41
|
end
|
49
42
|
|
50
43
|
it 'should return false otherwise' do
|
51
|
-
|
52
|
-
# opening
|
53
44
|
expect(BunnyMock::Channel.new.open?).to be_falsey
|
54
|
-
|
55
|
-
# closed
|
56
45
|
expect(@channel.close.open?).to be_falsey
|
57
46
|
end
|
58
47
|
end
|
@@ -60,16 +49,11 @@ describe BunnyMock::Channel do
|
|
60
49
|
context '#closed?' do
|
61
50
|
|
62
51
|
it 'should return true if status is closed' do
|
63
|
-
|
64
52
|
expect(@channel.close.closed?).to be_truthy
|
65
53
|
end
|
66
54
|
|
67
55
|
it 'should return false otherwise' do
|
68
|
-
|
69
|
-
# opening
|
70
56
|
expect(BunnyMock::Channel.new.closed?).to be_falsey
|
71
|
-
|
72
|
-
# open
|
73
57
|
expect(@channel.closed?).to be_falsey
|
74
58
|
end
|
75
59
|
end
|
@@ -77,23 +61,17 @@ describe BunnyMock::Channel do
|
|
77
61
|
context '#exchange' do
|
78
62
|
|
79
63
|
it 'should declare a new exchange' do
|
80
|
-
|
81
64
|
xchg = @channel.exchange 'testing.xchg', type: :fanout
|
82
|
-
|
83
65
|
expect(xchg.class).to eq(BunnyMock::Exchanges::Fanout)
|
84
66
|
end
|
85
67
|
|
86
68
|
it 'should return a cached exchange with the same name' do
|
87
|
-
|
88
69
|
xchg = @channel.exchange 'testing.xchg', type: :fanout
|
89
|
-
|
90
70
|
expect(@channel.exchange('testing.xchg', type: :fanout)).to eq(xchg)
|
91
71
|
end
|
92
72
|
|
93
73
|
it 'should register the exchange in cache' do
|
94
|
-
|
95
74
|
xchg = @channel.exchange 'testing.xchg', type: :fanout
|
96
|
-
|
97
75
|
expect(@session.exchange_exists?('testing.xchg')).to be_truthy
|
98
76
|
end
|
99
77
|
end
|
@@ -101,7 +79,6 @@ describe BunnyMock::Channel do
|
|
101
79
|
context '#direct' do
|
102
80
|
|
103
81
|
it 'should declare a new direct exchange' do
|
104
|
-
|
105
82
|
expect(@channel.direct('testing.xchg').class).to eq(BunnyMock::Exchanges::Direct)
|
106
83
|
end
|
107
84
|
end
|
@@ -109,7 +86,6 @@ describe BunnyMock::Channel do
|
|
109
86
|
context '#topic' do
|
110
87
|
|
111
88
|
it 'should declare a new topic exchange' do
|
112
|
-
|
113
89
|
expect(@channel.topic('testing.xchg').class).to eq(BunnyMock::Exchanges::Topic)
|
114
90
|
end
|
115
91
|
end
|
@@ -117,7 +93,6 @@ describe BunnyMock::Channel do
|
|
117
93
|
context '#fanout' do
|
118
94
|
|
119
95
|
it 'should declare a new fanout exchange' do
|
120
|
-
|
121
96
|
expect(@channel.fanout('testing.xchg').class).to eq(BunnyMock::Exchanges::Fanout)
|
122
97
|
end
|
123
98
|
end
|
@@ -125,7 +100,6 @@ describe BunnyMock::Channel do
|
|
125
100
|
context '#header' do
|
126
101
|
|
127
102
|
it 'should declare a new headers exchange' do
|
128
|
-
|
129
103
|
expect(@channel.header('testing.xchg').class).to eq(BunnyMock::Exchanges::Header)
|
130
104
|
end
|
131
105
|
end
|
@@ -133,7 +107,6 @@ describe BunnyMock::Channel do
|
|
133
107
|
context '#default_exchange' do
|
134
108
|
|
135
109
|
it 'should return a nameless direct exchange' do
|
136
|
-
|
137
110
|
xchg = @channel.default_exchange
|
138
111
|
|
139
112
|
expect(xchg.class).to eq(BunnyMock::Exchanges::Direct)
|
@@ -144,23 +117,17 @@ describe BunnyMock::Channel do
|
|
144
117
|
context '#queue' do
|
145
118
|
|
146
119
|
it 'should declare a new queue' do
|
147
|
-
|
148
120
|
q = @channel.queue 'testing.q'
|
149
|
-
|
150
121
|
expect(q.class).to eq(BunnyMock::Queue)
|
151
122
|
end
|
152
123
|
|
153
124
|
it 'should return a cached queue with the same name' do
|
154
|
-
|
155
125
|
q = @channel.queue 'testing.q'
|
156
|
-
|
157
126
|
expect(@channel.queue('testing.q')).to eq(q)
|
158
127
|
end
|
159
128
|
|
160
129
|
it 'should register the queue in cache' do
|
161
|
-
|
162
130
|
q = @channel.queue 'testing.q'
|
163
|
-
|
164
131
|
expect(@session.queue_exists?('testing.q')).to be_truthy
|
165
132
|
end
|
166
133
|
end
|
@@ -168,7 +135,6 @@ describe BunnyMock::Channel do
|
|
168
135
|
context '#temporary_queue' do
|
169
136
|
|
170
137
|
it 'should declare a nameless queue' do
|
171
|
-
|
172
138
|
expect(@channel.temporary_queue.class).to eq(BunnyMock::Queue)
|
173
139
|
end
|
174
140
|
end
|
@@ -1,172 +1,155 @@
|
|
1
1
|
describe BunnyMock::Exchange do
|
2
2
|
|
3
|
-
|
3
|
+
context '::declare' do
|
4
4
|
|
5
|
-
|
5
|
+
it 'should create a direct exchange' do
|
6
|
+
expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :direct).class).to eq(BunnyMock::Exchanges::Direct)
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
it 'should create a topic exchange' do
|
10
|
+
expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :topic).class).to eq(BunnyMock::Exchanges::Topic)
|
11
|
+
end
|
9
12
|
|
10
|
-
|
13
|
+
it 'should create a fanout exchange' do
|
14
|
+
expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :fanout).class).to eq(BunnyMock::Exchanges::Fanout)
|
15
|
+
end
|
11
16
|
|
12
|
-
|
13
|
-
|
17
|
+
it 'should create a header exchange' do
|
18
|
+
expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :header).class).to eq(BunnyMock::Exchanges::Header)
|
19
|
+
end
|
14
20
|
|
15
|
-
|
21
|
+
it 'should default to a direct exchange' do
|
22
|
+
expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg').class).to eq(BunnyMock::Exchanges::Direct)
|
23
|
+
end
|
24
|
+
end
|
16
25
|
|
17
|
-
|
18
|
-
end
|
26
|
+
context '#bind' do
|
19
27
|
|
20
|
-
|
28
|
+
before do
|
29
|
+
@source = @channel.exchange 'xchg.source'
|
30
|
+
@receiver = @channel.exchange 'xchg.receiver'
|
31
|
+
end
|
21
32
|
|
22
|
-
|
23
|
-
|
33
|
+
it 'should bind by exchange instance' do
|
34
|
+
@receiver.bind @source
|
24
35
|
|
25
|
-
|
36
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
37
|
+
expect(@source.routes_to?(@receiver)).to be_truthy
|
38
|
+
end
|
26
39
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
40
|
+
it 'should bind by exchange name' do
|
41
|
+
@receiver.bind @source.name
|
30
42
|
|
31
|
-
|
43
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
44
|
+
expect(@source.routes_to?(@receiver)).to be_truthy
|
45
|
+
end
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
47
|
+
it 'should raise error when exchange does not exists' do
|
48
|
+
expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
49
|
+
end
|
50
|
+
end
|
37
51
|
|
38
|
-
|
52
|
+
context '#unbind' do
|
39
53
|
|
40
|
-
|
54
|
+
before do
|
55
|
+
@source = @channel.exchange 'xchg.source'
|
56
|
+
@receiver = @channel.exchange 'xchg.receiver'
|
41
57
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
58
|
+
@receiver.bind @source
|
59
|
+
end
|
45
60
|
|
46
|
-
|
61
|
+
it 'should unbind by exchange instance' do
|
62
|
+
@receiver.unbind @source
|
47
63
|
|
48
|
-
|
64
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
65
|
+
expect(@source.routes_to?(@receiver)).to be_falsey
|
66
|
+
end
|
49
67
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
68
|
+
it 'should unbind by exchange name' do
|
69
|
+
@receiver.unbind @source.name
|
53
70
|
|
54
|
-
|
71
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
72
|
+
expect(@source.routes_to?(@receiver)).to be_falsey
|
73
|
+
end
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
|
75
|
+
it 'should raise error when exchange does not exists' do
|
76
|
+
expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
77
|
+
end
|
78
|
+
end
|
59
79
|
|
60
|
-
|
80
|
+
context '#bound_to?' do
|
61
81
|
|
62
|
-
|
63
|
-
|
64
|
-
|
82
|
+
before do
|
83
|
+
@source = @channel.exchange 'xchg.source'
|
84
|
+
@receiver = @channel.exchange 'xchg.receiver'
|
85
|
+
end
|
65
86
|
|
66
|
-
|
67
|
-
end
|
87
|
+
context 'should return true if bound' do
|
68
88
|
|
69
|
-
|
89
|
+
it 'by instance' do
|
90
|
+
@receiver.bind @source
|
91
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
92
|
+
end
|
70
93
|
|
71
|
-
|
94
|
+
it 'by name' do
|
95
|
+
@receiver.bind @source
|
96
|
+
expect(@receiver.bound_to?(@source.name)).to be_truthy
|
97
|
+
end
|
72
98
|
|
73
|
-
|
74
|
-
|
75
|
-
end
|
99
|
+
it 'by routing key' do
|
100
|
+
@receiver.bind @source, routing_key: 'xchg.route'
|
76
101
|
|
77
|
-
|
102
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
103
|
+
expect(@receiver.bound_to?(@source, routing_key: 'xchg.route')).to be_truthy
|
104
|
+
end
|
105
|
+
end
|
78
106
|
|
79
|
-
|
107
|
+
it 'return false otherwise' do
|
108
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
109
|
+
end
|
80
110
|
|
81
|
-
|
82
|
-
|
83
|
-
|
111
|
+
it 'should raise error when exchange does not exists' do
|
112
|
+
expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
113
|
+
end
|
114
|
+
end
|
84
115
|
|
85
|
-
|
116
|
+
context '#routes_to?' do
|
86
117
|
|
87
|
-
|
88
|
-
|
89
|
-
|
118
|
+
before do
|
119
|
+
@source = @channel.exchange 'xchg.source'
|
120
|
+
@receiver = @channel.exchange 'xchg.receiver'
|
90
121
|
|
91
|
-
|
122
|
+
@receiver.bind @source
|
123
|
+
end
|
92
124
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
125
|
+
it 'should return true if bound' do
|
126
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
127
|
+
expect(@source.routes_to?(@receiver)).to be_truthy
|
128
|
+
end
|
97
129
|
|
98
|
-
|
130
|
+
it 'should return false if unbound' do
|
131
|
+
@receiver.unbind @source
|
99
132
|
|
100
|
-
|
133
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
134
|
+
expect(@source.routes_to?(@receiver)).to be_falsey
|
135
|
+
end
|
101
136
|
|
102
|
-
|
137
|
+
context 'when using #has_binding?' do
|
138
|
+
it 'should output a deprecation warning' do
|
139
|
+
expect { @source.has_binding?(@receiver) }.to output(/DEPRECATED/).to_stderr
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
103
143
|
|
104
|
-
|
105
|
-
end
|
144
|
+
context '#delete' do
|
106
145
|
|
107
|
-
|
146
|
+
before do
|
147
|
+
@exchange = @channel.direct 'xchg.direct'
|
148
|
+
@exchange.delete
|
149
|
+
end
|
108
150
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
it 'by routing key' do
|
115
|
-
|
116
|
-
@receiver.bind @source, routing_key: 'xchg.route'
|
117
|
-
|
118
|
-
expect(@receiver.bound_to?(@source)).to be_falsey
|
119
|
-
expect(@receiver.bound_to?(@source, routing_key: 'xchg.route')).to be_truthy
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'return false otherwise' do
|
124
|
-
|
125
|
-
expect(@receiver.bound_to?(@source)).to be_falsey
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should raise error when exchange does not exists' do
|
129
|
-
|
130
|
-
expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
context '#routes_to?' do
|
135
|
-
|
136
|
-
before do
|
137
|
-
@source = @channel.exchange 'xchg.source'
|
138
|
-
@receiver = @channel.exchange 'xchg.receiver'
|
139
|
-
|
140
|
-
@receiver.bind @source
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should unbind by exchange instance' do
|
144
|
-
|
145
|
-
@receiver.unbind @source
|
146
|
-
|
147
|
-
expect(@receiver.bound_to?(@source)).to be_falsey
|
148
|
-
expect(@source.routes_to?(@receiver)).to be_falsey
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should unbind by exchange name' do
|
152
|
-
|
153
|
-
@receiver.unbind @source.name
|
154
|
-
|
155
|
-
expect(@receiver.bound_to?(@source)).to be_falsey
|
156
|
-
expect(@source.routes_to?(@receiver)).to be_falsey
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context '#delete' do
|
161
|
-
|
162
|
-
before do
|
163
|
-
@exchange = @channel.direct 'xchg.direct'
|
164
|
-
@exchange.delete
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should remove exchange from session' do
|
168
|
-
|
169
|
-
expect(@session.exchange_exists?(@exchange.name)).to be_falsey
|
170
|
-
end
|
171
|
-
end
|
151
|
+
it 'should remove exchange from session' do
|
152
|
+
expect(@session.exchange_exists?(@exchange.name)).to be_falsey
|
153
|
+
end
|
154
|
+
end
|
172
155
|
end
|
@@ -15,7 +15,6 @@ describe BunnyMock::Exchanges::Topic do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should deliver with no wildcards' do
|
18
|
-
|
19
18
|
@source.publish 'Testing message', routing_key: 'queue.category.second'
|
20
19
|
|
21
20
|
expect(@first.message_count).to eq(0)
|
@@ -23,12 +22,17 @@ describe BunnyMock::Exchanges::Topic do
|
|
23
22
|
|
24
23
|
expect(@second.message_count).to eq(1)
|
25
24
|
expect(@second.pop[:message]).to eq('Testing message')
|
26
|
-
|
25
|
+
end
|
27
26
|
|
28
|
-
|
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')
|
32
|
+
end
|
29
33
|
|
34
|
+
context 'should deliver with wildcards' do
|
30
35
|
it 'for single wildcards' do
|
31
|
-
|
32
36
|
@source.publish 'Testing message', routing_key: 'queue.*.sub.*'
|
33
37
|
|
34
38
|
expect(@second.message_count).to eq(0)
|
@@ -41,7 +45,6 @@ describe BunnyMock::Exchanges::Topic do
|
|
41
45
|
end
|
42
46
|
|
43
47
|
it 'for multiple wildcards' do
|
44
|
-
|
45
48
|
@source.publish 'Testing message', routing_key: 'queue.category.#'
|
46
49
|
|
47
50
|
expect(@third.message_count).to eq(0)
|
@@ -54,7 +57,6 @@ describe BunnyMock::Exchanges::Topic do
|
|
54
57
|
end
|
55
58
|
|
56
59
|
it 'for a mixed wildcards' do
|
57
|
-
|
58
60
|
@source.publish 'Testing message', routing_key: '#.sub.*'
|
59
61
|
|
60
62
|
expect(@second.message_count).to eq(0)
|
@@ -1,172 +1,154 @@
|
|
1
1
|
describe BunnyMock::Queue do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
before do
|
4
|
+
@queue = @channel.queue 'testing.q'
|
5
|
+
end
|
6
6
|
|
7
|
-
|
7
|
+
context '#publish' do
|
8
8
|
|
9
|
-
|
9
|
+
it 'should add message' do
|
10
|
+
@queue.publish 'This is a test message'
|
10
11
|
|
11
|
-
|
12
|
+
expect(@queue.message_count).to eq(1)
|
13
|
+
expect(@queue.pop[:message]).to eq('This is a test message')
|
14
|
+
expect(@queue.message_count).to eq(0)
|
15
|
+
end
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
expect(@queue.pop[:message]).to eq('This is a test message')
|
15
|
-
expect(@queue.message_count).to eq(0)
|
16
|
-
end
|
17
|
-
end
|
18
|
+
context '#bind' do
|
18
19
|
|
19
|
-
|
20
|
+
before do
|
21
|
+
@source = @channel.exchange 'xchg.source'
|
22
|
+
@receiver = @channel.queue 'queue.receiver'
|
23
|
+
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
@receiver = @channel.queue 'queue.receiver'
|
24
|
-
end
|
25
|
+
it 'should bind by exchange instance' do
|
26
|
+
@receiver.bind @source
|
25
27
|
|
26
|
-
|
28
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
29
|
+
expect(@source.routes_to?(@receiver)).to be_truthy
|
30
|
+
end
|
27
31
|
|
28
|
-
|
32
|
+
it 'should bind by exchange name' do
|
33
|
+
@receiver.bind @source.name
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
36
|
+
expect(@source.routes_to?(@receiver)).to be_truthy
|
37
|
+
end
|
33
38
|
|
34
|
-
|
39
|
+
it 'should raise error when exchange does not exists' do
|
40
|
+
expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
41
|
+
end
|
42
|
+
end
|
35
43
|
|
36
|
-
|
44
|
+
context '#unbind' do
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
46
|
+
before do
|
47
|
+
@source = @channel.exchange 'xchg.source'
|
48
|
+
@receiver = @channel.queue 'queue.receiver'
|
41
49
|
|
42
|
-
|
50
|
+
@receiver.bind @source
|
51
|
+
end
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
53
|
+
it 'should unbind by exchange instance' do
|
54
|
+
@receiver.unbind @source
|
47
55
|
|
48
|
-
|
56
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
57
|
+
expect(@source.routes_to?(@receiver)).to be_falsey
|
58
|
+
end
|
49
59
|
|
50
|
-
|
51
|
-
|
52
|
-
@receiver = @channel.queue 'queue.receiver'
|
60
|
+
it 'should unbind by exchange name' do
|
61
|
+
@receiver.unbind @source.name
|
53
62
|
|
54
|
-
|
55
|
-
|
63
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
64
|
+
expect(@source.routes_to?(@receiver)).to be_falsey
|
65
|
+
end
|
56
66
|
|
57
|
-
|
67
|
+
it 'should raise error when exchange does not exists' do
|
68
|
+
expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
69
|
+
end
|
70
|
+
end
|
58
71
|
|
59
|
-
|
72
|
+
context '#bound_to?' do
|
60
73
|
|
61
|
-
|
62
|
-
|
63
|
-
|
74
|
+
before do
|
75
|
+
@source = @channel.exchange 'xchg.source'
|
76
|
+
@receiver = @channel.queue 'queue.receiver'
|
77
|
+
end
|
64
78
|
|
65
|
-
|
79
|
+
context 'should return true if bound' do
|
66
80
|
|
67
|
-
|
81
|
+
it 'by instance' do
|
82
|
+
@receiver.bind @source
|
83
|
+
expect(@receiver.bound_to?(@source)).to be_truthy
|
84
|
+
end
|
68
85
|
|
69
|
-
|
70
|
-
|
71
|
-
|
86
|
+
it 'by name' do
|
87
|
+
@receiver.bind @source
|
88
|
+
expect(@receiver.bound_to?(@source.name)).to be_truthy
|
89
|
+
end
|
72
90
|
|
73
|
-
|
91
|
+
it 'by routing key' do
|
92
|
+
@receiver.bind @source, routing_key: 'queue.route'
|
74
93
|
|
75
|
-
|
76
|
-
|
77
|
-
|
94
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
95
|
+
expect(@receiver.bound_to?(@source, routing_key: 'queue.route')).to be_truthy
|
96
|
+
end
|
97
|
+
end
|
78
98
|
|
79
|
-
|
99
|
+
it 'return false otherwise' do
|
100
|
+
expect(@receiver.bound_to?(@source)).to be_falsey
|
101
|
+
end
|
80
102
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
103
|
+
it 'should raise error when exchange does not exists' do
|
104
|
+
expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
|
105
|
+
end
|
106
|
+
end
|
85
107
|
|
86
|
-
|
108
|
+
context '#message_count' do
|
87
109
|
|
88
|
-
|
110
|
+
it 'should return number of messages in queue' do
|
111
|
+
@queue.publish 'First'
|
112
|
+
@queue.publish 'Second'
|
89
113
|
|
90
|
-
|
114
|
+
expect(@queue.message_count).to eq(2)
|
91
115
|
|
92
|
-
|
93
|
-
end
|
116
|
+
@queue.pop
|
94
117
|
|
95
|
-
|
118
|
+
expect(@queue.message_count).to eq(1)
|
119
|
+
end
|
120
|
+
end
|
96
121
|
|
97
|
-
|
122
|
+
context '#pop' do
|
98
123
|
|
99
|
-
|
100
|
-
|
124
|
+
it 'should return oldest message in queue' do
|
125
|
+
@queue.publish 'First'
|
126
|
+
@queue.publish 'Second'
|
101
127
|
|
102
|
-
|
128
|
+
expect(@queue.pop[:message]).to eq('First')
|
129
|
+
end
|
130
|
+
end
|
103
131
|
|
104
|
-
|
132
|
+
context '#purge' do
|
105
133
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
134
|
+
it 'should clear all messages' do
|
135
|
+
@queue.publish 'First'
|
136
|
+
@queue.publish 'Second'
|
110
137
|
|
111
|
-
|
138
|
+
@queue.purge
|
112
139
|
|
113
|
-
|
114
|
-
|
140
|
+
expect(@queue.message_count).to eq(0)
|
141
|
+
end
|
142
|
+
end
|
115
143
|
|
116
|
-
|
144
|
+
context '#delete' do
|
117
145
|
|
118
|
-
|
119
|
-
|
120
|
-
|
146
|
+
before do
|
147
|
+
@queue.delete
|
148
|
+
end
|
121
149
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@queue.publish 'First'
|
127
|
-
@queue.publish 'Second'
|
128
|
-
|
129
|
-
expect(@queue.message_count).to eq(2)
|
130
|
-
|
131
|
-
@queue.pop
|
132
|
-
|
133
|
-
expect(@queue.message_count).to eq(1)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context '#pop' do
|
138
|
-
|
139
|
-
it 'should return oldest message in queue' do
|
140
|
-
|
141
|
-
@queue.publish 'First'
|
142
|
-
@queue.publish 'Second'
|
143
|
-
|
144
|
-
expect(@queue.pop[:message]).to eq('First')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context '#purge' do
|
149
|
-
|
150
|
-
it 'should clear all messages' do
|
151
|
-
|
152
|
-
@queue.publish 'First'
|
153
|
-
@queue.publish 'Second'
|
154
|
-
|
155
|
-
@queue.purge
|
156
|
-
|
157
|
-
expect(@queue.message_count).to eq(0)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context '#delete' do
|
162
|
-
|
163
|
-
before do
|
164
|
-
@queue.delete
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should remove queue from session' do
|
168
|
-
|
169
|
-
expect(@session.queue_exists?(@queue.name)).to be_falsey
|
170
|
-
end
|
171
|
-
end
|
150
|
+
it 'should remove queue from session' do
|
151
|
+
expect(@session.queue_exists?(@queue.name)).to be_falsey
|
152
|
+
end
|
153
|
+
end
|
172
154
|
end
|
@@ -7,7 +7,6 @@ describe BunnyMock::Session do
|
|
7
7
|
context '::new' do
|
8
8
|
|
9
9
|
it 'should start as not connected' do
|
10
|
-
|
11
10
|
expect(@session.status).to eq(:not_connected)
|
12
11
|
end
|
13
12
|
end
|
@@ -15,7 +14,6 @@ describe BunnyMock::Session do
|
|
15
14
|
context '#start' do
|
16
15
|
|
17
16
|
it 'should set status to connected' do
|
18
|
-
|
19
17
|
expect(@session.start.status).to eq(:connected)
|
20
18
|
end
|
21
19
|
end
|
@@ -23,9 +21,7 @@ describe BunnyMock::Session do
|
|
23
21
|
context '#stop (close)' do
|
24
22
|
|
25
23
|
it 'should set status to closed' do
|
26
|
-
|
27
24
|
@session.start
|
28
|
-
|
29
25
|
expect(@session.stop.status).to eq(:closed)
|
30
26
|
end
|
31
27
|
end
|
@@ -33,14 +29,11 @@ describe BunnyMock::Session do
|
|
33
29
|
context '#open?' do
|
34
30
|
|
35
31
|
it 'should return true if status is open' do
|
36
|
-
|
37
32
|
@session.start
|
38
|
-
|
39
33
|
expect(@session.open?).to be_truthy
|
40
34
|
end
|
41
35
|
|
42
36
|
it 'should return false otherwise' do
|
43
|
-
|
44
37
|
expect(@session.status).to eq(:not_connected)
|
45
38
|
expect(@session.open?).to be_falsey
|
46
39
|
|
@@ -55,7 +48,6 @@ describe BunnyMock::Session do
|
|
55
48
|
context '#create_channel (channel)' do
|
56
49
|
|
57
50
|
it 'should create a new channel with no arguments' do
|
58
|
-
|
59
51
|
first = @session.create_channel
|
60
52
|
second = @session.create_channel
|
61
53
|
|
@@ -66,7 +58,6 @@ describe BunnyMock::Session do
|
|
66
58
|
end
|
67
59
|
|
68
60
|
it 'should return cached channel with same identifier' do
|
69
|
-
|
70
61
|
first = @session.create_channel 1
|
71
62
|
second = @session.create_channel 1
|
72
63
|
|
@@ -74,7 +65,6 @@ describe BunnyMock::Session do
|
|
74
65
|
end
|
75
66
|
|
76
67
|
it 'should return an ArgumentError for reserved channel' do
|
77
|
-
|
78
68
|
expect { @session.create_channel(0) }.to raise_error(ArgumentError)
|
79
69
|
end
|
80
70
|
end
|
@@ -83,7 +73,6 @@ describe BunnyMock::Session do
|
|
83
73
|
|
84
74
|
it 'should close the channel after the block ends' do
|
85
75
|
channel = nil
|
86
|
-
|
87
76
|
@session.with_channel { |c| channel = c }
|
88
77
|
|
89
78
|
expect(channel.closed?).to be_truthy
|
@@ -3,7 +3,6 @@ describe BunnyMock do
|
|
3
3
|
context '::new' do
|
4
4
|
|
5
5
|
it 'should return a new session' do
|
6
|
-
|
7
6
|
expect(BunnyMock.new.class).to eq(BunnyMock::Session)
|
8
7
|
end
|
9
8
|
end
|
@@ -11,7 +10,6 @@ describe BunnyMock do
|
|
11
10
|
context '::version' do
|
12
11
|
|
13
12
|
it 'should return the current version' do
|
14
|
-
|
15
13
|
expect(BunnyMock::VERSION).to_not be_nil
|
16
14
|
expect(BunnyMock.version).to_not be_nil
|
17
15
|
end
|
@@ -20,7 +18,6 @@ describe BunnyMock do
|
|
20
18
|
context '::protocol_version' do
|
21
19
|
|
22
20
|
it 'should return the current amq protocol version' do
|
23
|
-
|
24
21
|
expect(BunnyMock::PROTOCOL_VERSION).to eq('0.9.1')
|
25
22
|
expect(BunnyMock.protocol_version).to eq('0.9.1')
|
26
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny-mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
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-
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|