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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c674fde478dce165ef8edd3f4b5679487d1a77e9
4
- data.tar.gz: 9b61556fb514f0f12e3be7f72efc01a0f11a820c
3
+ metadata.gz: 3808cb4a1e923e7b48519a07ecb6d2acaa235da2
4
+ data.tar.gz: 93726320854a4f15bd18f5b5f485d24d4c901293
5
5
  SHA512:
6
- metadata.gz: 06040eeb88b2446118f40a8ff9ef61d27caaa0d7173bafb6d27a8f9410b7ba9fa47e106557adb728e11d3bce8ba5d2193382944473b551fe42805cd939bcd501
7
- data.tar.gz: 4fa7fd68ca0c53948622f0bc45ab230f9646864534a62ab896d47a87b3a0b1efc8c9faa52ea0b9d8907e81009924761fc2634101ed370c61f3a65bd47bab88e9
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-18 00:29:42 -0500 using RuboCop version 0.37.2.
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: 33
9
+ # Offense count: 38
10
10
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
11
11
  # URISchemes: http, https
12
12
  Metrics/LineLength:
13
- Max: 126
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: 8
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
- 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'
33
+ Enabled: false
42
34
 
43
35
  # Offense count: 36
44
36
  # Cop supports --auto-correct.
45
37
  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'
38
+ Enabled: false
56
39
 
57
- # Offense count: 3
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
- Exclude:
63
- - 'lib/bunny-mock.rb'
64
- - 'lib/bunny_mock/exceptions.rb'
65
- - 'lib/bunny_mock/version.rb'
45
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v1.2.1
2
+
3
+ * [#5](https://github.com/arempe93/bunny-mock/pull/5): Fixes `routing_key` being modified when delivering in a topic exchange - [@austinmoore](https://github.com/austinmoore)
4
+
1
5
  ## v1.2.0
2
6
 
3
7
  * Adds `with_channel` functionality to `BunnyMock::Session`
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
- # API
29
- #
30
-
31
- ##
32
- # Instantiate a new mock Bunny session
33
- #
34
- # @return [BunnyMock::Session] Session instance
35
- # @api public
36
- def self.new(*)
37
-
38
- # return new mock session
39
- BunnyMock::Session.new
40
- end
41
-
42
- # @return [String] Bunny mock version
43
- def self.version
44
- VERSION
45
- end
46
-
47
- # @return [String] AMQP protocol version
48
- def self.protocol_version
49
- AMQ::Protocol::PROTOCOL_VERSION
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
@@ -2,31 +2,34 @@
2
2
  module BunnyMock
3
3
  class Exchange
4
4
 
5
- ##
6
- # Create a new {BunnyMock::Exchange} instance
7
- #
8
- # @param [BunnyMock::Channel] channel Channel this exchange will use
9
- # @param [String] name Name of exchange
10
- # @param [Hash] opts Creation options
11
- #
12
- # @option opts [Boolean] :durable (false) Should this exchange be durable?
13
- # @option opts [Boolean] :auto_delete (false) Should this exchange be automatically deleted when it is no longer used?
14
- # @option opts [Boolean] :arguments ({}) Additional optional arguments (typically used by RabbitMQ extensions and plugins)
15
- #
16
- # @return [BunnyMock::Exchange] A new exchange
17
- # @see BunnyMock::Channel#exchange
18
- # @api public
19
- #
20
- def self.declare(channel, name = '', opts = {})
21
-
22
- # get requested type
23
- type = opts.fetch :type, :direct
24
-
25
- # get needed class type
26
- klazz = BunnyMock::Exchanges.const_get type.to_s.capitalize
27
-
28
- # create exchange of desired type
29
- klazz.new channel, name, type, opts
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
- alias has_binding? routes_to?
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!(SINGLE_WILDCARD, '(?:\w+)')
33
+ key = key.gsub(SINGLE_WILDCARD, '(?:\w+)')
34
34
 
35
35
  # replace multi wildcards with regex for many domains separated by '.'
36
- key.gsub!(MULTI_WILDCARD, '\w+\.?')
36
+ key = key.gsub(MULTI_WILDCARD, '\w+\.?')
37
37
 
38
38
  # turn key into regex
39
39
  key = Regexp.new(key)
@@ -4,5 +4,5 @@
4
4
  module BunnyMock
5
5
 
6
6
  # @return [String] Version of the library
7
- VERSION = '1.2.0'
7
+ VERSION = '1.2.1'
8
8
  end
@@ -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
- context '::declare' do
3
+ context '::declare' do
4
4
 
5
- it 'should create a direct exchange' do
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
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :direct).class).to eq(BunnyMock::Exchanges::Direct)
8
- end
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
- it 'should create a topic exchange' do
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
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :topic).class).to eq(BunnyMock::Exchanges::Topic)
13
- end
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
- it 'should create a fanout exchange' do
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
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :fanout).class).to eq(BunnyMock::Exchanges::Fanout)
18
- end
26
+ context '#bind' do
19
27
 
20
- it 'should create a header exchange' do
28
+ before do
29
+ @source = @channel.exchange 'xchg.source'
30
+ @receiver = @channel.exchange 'xchg.receiver'
31
+ end
21
32
 
22
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg', type: :header).class).to eq(BunnyMock::Exchanges::Header)
23
- end
33
+ it 'should bind by exchange instance' do
34
+ @receiver.bind @source
24
35
 
25
- it 'should default to a direct exchange' do
36
+ expect(@receiver.bound_to?(@source)).to be_truthy
37
+ expect(@source.routes_to?(@receiver)).to be_truthy
38
+ end
26
39
 
27
- expect(BunnyMock::Exchange.declare(@channel, 'testing.xchg').class).to eq(BunnyMock::Exchanges::Direct)
28
- end
29
- end
40
+ it 'should bind by exchange name' do
41
+ @receiver.bind @source.name
30
42
 
31
- context '#bind' do
43
+ expect(@receiver.bound_to?(@source)).to be_truthy
44
+ expect(@source.routes_to?(@receiver)).to be_truthy
45
+ end
32
46
 
33
- before do
34
- @source = @channel.exchange 'xchg.source'
35
- @receiver = @channel.exchange 'xchg.receiver'
36
- end
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
- it 'should bind by exchange instance' do
52
+ context '#unbind' do
39
53
 
40
- @receiver.bind @source
54
+ before do
55
+ @source = @channel.exchange 'xchg.source'
56
+ @receiver = @channel.exchange 'xchg.receiver'
41
57
 
42
- expect(@receiver.bound_to?(@source)).to be_truthy
43
- expect(@source.routes_to?(@receiver)).to be_truthy
44
- end
58
+ @receiver.bind @source
59
+ end
45
60
 
46
- it 'should bind by exchange name' do
61
+ it 'should unbind by exchange instance' do
62
+ @receiver.unbind @source
47
63
 
48
- @receiver.bind @source.name
64
+ expect(@receiver.bound_to?(@source)).to be_falsey
65
+ expect(@source.routes_to?(@receiver)).to be_falsey
66
+ end
49
67
 
50
- expect(@receiver.bound_to?(@source)).to be_truthy
51
- expect(@source.routes_to?(@receiver)).to be_truthy
52
- end
68
+ it 'should unbind by exchange name' do
69
+ @receiver.unbind @source.name
53
70
 
54
- it 'should raise error when exchange does not exists' do
71
+ expect(@receiver.bound_to?(@source)).to be_falsey
72
+ expect(@source.routes_to?(@receiver)).to be_falsey
73
+ end
55
74
 
56
- expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
57
- end
58
- end
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
- context '#unbind' do
80
+ context '#bound_to?' do
61
81
 
62
- before do
63
- @source = @channel.exchange 'xchg.source'
64
- @receiver = @channel.exchange 'xchg.receiver'
82
+ before do
83
+ @source = @channel.exchange 'xchg.source'
84
+ @receiver = @channel.exchange 'xchg.receiver'
85
+ end
65
86
 
66
- @receiver.bind @source
67
- end
87
+ context 'should return true if bound' do
68
88
 
69
- it 'should unbind by exchange instance' do
89
+ it 'by instance' do
90
+ @receiver.bind @source
91
+ expect(@receiver.bound_to?(@source)).to be_truthy
92
+ end
70
93
 
71
- @receiver.unbind @source
94
+ it 'by name' do
95
+ @receiver.bind @source
96
+ expect(@receiver.bound_to?(@source.name)).to be_truthy
97
+ end
72
98
 
73
- expect(@receiver.bound_to?(@source)).to be_falsey
74
- expect(@source.routes_to?(@receiver)).to be_falsey
75
- end
99
+ it 'by routing key' do
100
+ @receiver.bind @source, routing_key: 'xchg.route'
76
101
 
77
- it 'should unbind by exchange name' do
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
- @receiver.unbind @source.name
107
+ it 'return false otherwise' do
108
+ expect(@receiver.bound_to?(@source)).to be_falsey
109
+ end
80
110
 
81
- expect(@receiver.bound_to?(@source)).to be_falsey
82
- expect(@source.routes_to?(@receiver)).to be_falsey
83
- end
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
- it 'should raise error when exchange does not exists' do
116
+ context '#routes_to?' do
86
117
 
87
- expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
88
- end
89
- end
118
+ before do
119
+ @source = @channel.exchange 'xchg.source'
120
+ @receiver = @channel.exchange 'xchg.receiver'
90
121
 
91
- context '#bound_to?' do
122
+ @receiver.bind @source
123
+ end
92
124
 
93
- before do
94
- @source = @channel.exchange 'xchg.source'
95
- @receiver = @channel.exchange 'xchg.receiver'
96
- end
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
- context 'should return true if bound' do
130
+ it 'should return false if unbound' do
131
+ @receiver.unbind @source
99
132
 
100
- it 'by instance' do
133
+ expect(@receiver.bound_to?(@source)).to be_falsey
134
+ expect(@source.routes_to?(@receiver)).to be_falsey
135
+ end
101
136
 
102
- @receiver.bind @source
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
- expect(@receiver.bound_to?(@source)).to be_truthy
105
- end
144
+ context '#delete' do
106
145
 
107
- it 'by name' do
146
+ before do
147
+ @exchange = @channel.direct 'xchg.direct'
148
+ @exchange.delete
149
+ end
108
150
 
109
- @receiver.bind @source
110
-
111
- expect(@receiver.bound_to?(@source.name)).to be_truthy
112
- end
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::Direct do
15
15
  end
16
16
 
17
17
  it 'should only deliver to direct route match' do
18
-
19
18
  @source.publish 'Testing message', routing_key: 'queue.second'
20
19
 
21
20
  expect(@first.message_count).to eq(0)
@@ -15,7 +15,6 @@ describe BunnyMock::Exchanges::Fanout do
15
15
  end
16
16
 
17
17
  it 'should only deliver to all routes' do
18
-
19
18
  @source.publish 'Testing message', routing_key: 'queue.second'
20
19
 
21
20
  expect(@first.message_count).to eq(1)
@@ -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
- end
25
+ end
27
26
 
28
- context 'should deliver with wildcards' do
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
- before do
4
- @queue = @channel.queue 'testing.q'
5
- end
3
+ before do
4
+ @queue = @channel.queue 'testing.q'
5
+ end
6
6
 
7
- context '#publish' do
7
+ context '#publish' do
8
8
 
9
- it 'should add message' do
9
+ it 'should add message' do
10
+ @queue.publish 'This is a test message'
10
11
 
11
- @queue.publish 'This is a test message'
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
- expect(@queue.message_count).to eq(1)
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
- context '#bind' do
20
+ before do
21
+ @source = @channel.exchange 'xchg.source'
22
+ @receiver = @channel.queue 'queue.receiver'
23
+ end
20
24
 
21
- before do
22
- @source = @channel.exchange 'xchg.source'
23
- @receiver = @channel.queue 'queue.receiver'
24
- end
25
+ it 'should bind by exchange instance' do
26
+ @receiver.bind @source
25
27
 
26
- it 'should bind by exchange instance' do
28
+ expect(@receiver.bound_to?(@source)).to be_truthy
29
+ expect(@source.routes_to?(@receiver)).to be_truthy
30
+ end
27
31
 
28
- @receiver.bind @source
32
+ it 'should bind by exchange name' do
33
+ @receiver.bind @source.name
29
34
 
30
- expect(@receiver.bound_to?(@source)).to be_truthy
31
- expect(@source.routes_to?(@receiver)).to be_truthy
32
- end
35
+ expect(@receiver.bound_to?(@source)).to be_truthy
36
+ expect(@source.routes_to?(@receiver)).to be_truthy
37
+ end
33
38
 
34
- it 'should bind by exchange name' do
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
- @receiver.bind @source.name
44
+ context '#unbind' do
37
45
 
38
- expect(@receiver.bound_to?(@source)).to be_truthy
39
- expect(@source.routes_to?(@receiver)).to be_truthy
40
- end
46
+ before do
47
+ @source = @channel.exchange 'xchg.source'
48
+ @receiver = @channel.queue 'queue.receiver'
41
49
 
42
- it 'should raise error when exchange does not exists' do
50
+ @receiver.bind @source
51
+ end
43
52
 
44
- expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
45
- end
46
- end
53
+ it 'should unbind by exchange instance' do
54
+ @receiver.unbind @source
47
55
 
48
- context '#unbind' do
56
+ expect(@receiver.bound_to?(@source)).to be_falsey
57
+ expect(@source.routes_to?(@receiver)).to be_falsey
58
+ end
49
59
 
50
- before do
51
- @source = @channel.exchange 'xchg.source'
52
- @receiver = @channel.queue 'queue.receiver'
60
+ it 'should unbind by exchange name' do
61
+ @receiver.unbind @source.name
53
62
 
54
- @receiver.bind @source
55
- end
63
+ expect(@receiver.bound_to?(@source)).to be_falsey
64
+ expect(@source.routes_to?(@receiver)).to be_falsey
65
+ end
56
66
 
57
- it 'should unbind by exchange instance' do
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
- @receiver.unbind @source
72
+ context '#bound_to?' do
60
73
 
61
- expect(@receiver.bound_to?(@source)).to be_falsey
62
- expect(@source.routes_to?(@receiver)).to be_falsey
63
- end
74
+ before do
75
+ @source = @channel.exchange 'xchg.source'
76
+ @receiver = @channel.queue 'queue.receiver'
77
+ end
64
78
 
65
- it 'should unbind by exchange name' do
79
+ context 'should return true if bound' do
66
80
 
67
- @receiver.unbind @source.name
81
+ it 'by instance' do
82
+ @receiver.bind @source
83
+ expect(@receiver.bound_to?(@source)).to be_truthy
84
+ end
68
85
 
69
- expect(@receiver.bound_to?(@source)).to be_falsey
70
- expect(@source.routes_to?(@receiver)).to be_falsey
71
- end
86
+ it 'by name' do
87
+ @receiver.bind @source
88
+ expect(@receiver.bound_to?(@source.name)).to be_truthy
89
+ end
72
90
 
73
- it 'should raise error when exchange does not exists' do
91
+ it 'by routing key' do
92
+ @receiver.bind @source, routing_key: 'queue.route'
74
93
 
75
- expect { @receiver.unbind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
76
- end
77
- end
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
- context '#bound_to?' do
99
+ it 'return false otherwise' do
100
+ expect(@receiver.bound_to?(@source)).to be_falsey
101
+ end
80
102
 
81
- before do
82
- @source = @channel.exchange 'xchg.source'
83
- @receiver = @channel.queue 'queue.receiver'
84
- end
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
- context 'should return true if bound' do
108
+ context '#message_count' do
87
109
 
88
- it 'by instance' do
110
+ it 'should return number of messages in queue' do
111
+ @queue.publish 'First'
112
+ @queue.publish 'Second'
89
113
 
90
- @receiver.bind @source
114
+ expect(@queue.message_count).to eq(2)
91
115
 
92
- expect(@receiver.bound_to?(@source)).to be_truthy
93
- end
116
+ @queue.pop
94
117
 
95
- it 'by name' do
118
+ expect(@queue.message_count).to eq(1)
119
+ end
120
+ end
96
121
 
97
- @receiver.bind @source
122
+ context '#pop' do
98
123
 
99
- expect(@receiver.bound_to?(@source.name)).to be_truthy
100
- end
124
+ it 'should return oldest message in queue' do
125
+ @queue.publish 'First'
126
+ @queue.publish 'Second'
101
127
 
102
- it 'by routing key' do
128
+ expect(@queue.pop[:message]).to eq('First')
129
+ end
130
+ end
103
131
 
104
- @receiver.bind @source, routing_key: 'queue.route'
132
+ context '#purge' do
105
133
 
106
- expect(@receiver.bound_to?(@source)).to be_falsey
107
- expect(@receiver.bound_to?(@source, routing_key: 'queue.route')).to be_truthy
108
- end
109
- end
134
+ it 'should clear all messages' do
135
+ @queue.publish 'First'
136
+ @queue.publish 'Second'
110
137
 
111
- it 'return false otherwise' do
138
+ @queue.purge
112
139
 
113
- expect(@receiver.bound_to?(@source)).to be_falsey
114
- end
140
+ expect(@queue.message_count).to eq(0)
141
+ end
142
+ end
115
143
 
116
- it 'should raise error when exchange does not exists' do
144
+ context '#delete' do
117
145
 
118
- expect { @receiver.bound_to?('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
119
- end
120
- end
146
+ before do
147
+ @queue.delete
148
+ end
121
149
 
122
- context '#message_count' do
123
-
124
- it 'should return number of messages in queue' do
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.0
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-02-23 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny