bunny-mock 1.6.0 → 1.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 884e4998df1d5701f0384a2cb1c009d80ed81b67
4
- data.tar.gz: 198414bf1eabff599a44310c514cbfa9ce770b0d
3
+ metadata.gz: ef8cbde025836118928a61e3d8d0b63f736c8b4c
4
+ data.tar.gz: d88bdce511227d6f4fd7dd4a3b70a38c363374cc
5
5
  SHA512:
6
- metadata.gz: 868c41d0849c0ea46f2049b15e6ee9122d662f4953089baefc7e35efc37114baff7ea09c6f66bb322a03252820513115526f27e40e2c71c30f312a9526c34e7a
7
- data.tar.gz: ee9f02bc843c883b4df2780a3373219bf283d9780219eccea3edc6e7bcfebca177c53806f6a379dba35469c22d2dfc1dc9dec7a2d8462eb8fbad34cc99d69f26
6
+ metadata.gz: 836978ddc5b9220044e6a3628631e8915e64995099fb86cbb5fe61a11bd9441057d8482919907a4c46c2de4f8b63719cb896f8c4526aae4fb21bcb70f588dec5
7
+ data.tar.gz: 45658e28e7d45880a424ac9a5132c962757820f74ee6d0f0a2b6e87f8584e23289cf0ea880e47db2e23620189104dbd295622583399a93c271a4a96f1d3d169e
@@ -2,6 +2,12 @@
2
2
 
3
3
  _Add contribution here_
4
4
 
5
+ ## v1.7.0
6
+
7
+ * [#32](https://github.com/arempe93/bunny-mock/pull/32): Implement reject functionality - [@binaryberry](https://github.com/binaryberry)
8
+ * [#31](https://github.com/arempe93/bunny-mock/pull/31): Add `generate_consumer_tag` to `BunnyMock::Channel` - [@Jakenberg](https://github.com/Jakenberg)
9
+ * [#23](https://github.com/arempe93/bunny-mock/pull/23): Fix queue bind returning an array instead of self - [@fugufish](https://github.com/fugufish)
10
+
5
11
  ## v1.6.0
6
12
 
7
13
  * [#27](https://github.com/arempe93/bunny-mock/pull/27): Allow `Session#create_channel` to accept additional args - [@eebs](https://github.com/eebs)
@@ -35,7 +35,7 @@ module BunnyMock
35
35
  # initialize exchange and queue storage
36
36
  @exchanges = {}
37
37
  @queues = {}
38
- @acknowledged_state = { pending: {}, acked: {}, nacked: {} }
38
+ @acknowledged_state = { pending: {}, acked: {}, nacked: {}, rejected: {} }
39
39
 
40
40
  # set status to opening
41
41
  @status = :opening
@@ -103,6 +103,14 @@ module BunnyMock
103
103
  @connection.register_exchange xchg_find_or_create(name, opts)
104
104
  end
105
105
 
106
+ # Unique string supposed to be used as a consumer tag.
107
+ #
108
+ # @return [String] Unique string.
109
+ # @api plugin
110
+ def generate_consumer_tag(name = 'bunny')
111
+ "#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
112
+ end
113
+
106
114
  ##
107
115
  # Mocks a fanout exchange
108
116
  #
@@ -303,13 +311,21 @@ module BunnyMock
303
311
  end
304
312
 
305
313
  ##
306
- # Does nothing atm.
314
+ # Rejects a message. A rejected message can be requeued or
315
+ # dropped by RabbitMQ.
316
+ #
317
+ # @param [Integer] delivery_tag Delivery tag to reject
318
+ # @param [Boolean] requeue Should this message be requeued instead of dropping it?
307
319
  #
308
320
  # @return nil
309
321
  # @api public
310
322
  #
311
- def reject(*)
312
- # noop
323
+ def reject(delivery_tag, requeue = false)
324
+ if @acknowledged_state[:pending].key?(delivery_tag)
325
+ delivery, header, body = update_acknowledgement_state(delivery_tag, :rejected)
326
+ delivery.queue.publish(body, header.to_hash) if requeue
327
+ end
328
+ nil
313
329
  end
314
330
 
315
331
  # @endgroup
@@ -123,6 +123,7 @@ module BunnyMock
123
123
  # we need the channel to lookup the exchange
124
124
  @channel.queue_bind self, opts.fetch(:routing_key, @name), exchange
125
125
  end
126
+ self
126
127
  end
127
128
 
128
129
  ##
@@ -3,5 +3,5 @@
3
3
 
4
4
  module BunnyMock
5
5
  # @return [String] Version of the library
6
- VERSION = '1.6.0'.freeze
6
+ VERSION = '1.7.0'.freeze
7
7
  end
@@ -27,61 +27,88 @@ describe BunnyMock::Channel, 'acknowledgement' do
27
27
  expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
28
28
  end
29
29
 
30
- it 'should allow messages which have been nacked to be identified' do
31
- queue.publish 'Message to nack'
32
- delivery_tag = delivery_tags['Message to nack']
33
- @channel.nack delivery_tag
30
+ context 'when using nack to negatively acknowledge' do
31
+ it 'should allow messages which have been nacked to be identified' do
32
+ queue.publish 'Message to nack'
33
+ delivery_tag = delivery_tags['Message to nack']
34
+ @channel.nack delivery_tag
35
+
36
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
37
+ expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
38
+ expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
39
+ end
34
40
 
35
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
36
- expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
37
- expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
38
- end
41
+ it 'should requeue messages with have been nacked with `requeue` = true' do
42
+ queue.publish 'Message to nack'
43
+ delivery_tag = delivery_tags['Message to nack']
44
+ @channel.nack delivery_tag, false, true
45
+ new_delivery_tag = delivery_tags['Message to nack']
39
46
 
40
- it 'should requeue messages with have been nacked with `requeue` = true' do
41
- queue.publish 'Message to nack'
42
- delivery_tag = delivery_tags['Message to nack']
43
- @channel.nack delivery_tag, false, true
44
- new_delivery_tag = delivery_tags['Message to nack']
47
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
48
+ expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
49
+ expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
45
50
 
46
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
47
- expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
48
- expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag)
51
+ expect(@channel.acknowledged_state[:pending]).to include(new_delivery_tag)
52
+ end
49
53
 
50
- expect(@channel.acknowledged_state[:pending]).to include(new_delivery_tag)
51
- end
54
+ it 'should allow multiple messages to be acked when `multiple` = true' do
55
+ queue.publish 'Message to be automatically acked'
56
+ delivery_tag_1 = delivery_tags['Message to be automatically acked']
57
+ queue.publish 'Message to acked'
58
+ delivery_tag_2 = delivery_tags['Message to acked']
59
+ queue.publish 'Message to be left as pending'
60
+ delivery_tag_3 = delivery_tags['Message to be left as pending']
61
+
62
+ @channel.ack delivery_tag_2, true
63
+
64
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
65
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
66
+ expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
67
+ expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_1)
68
+ expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_2)
69
+ end
52
70
 
53
- it 'should allow multiple messages to be acked when `multiple` = true' do
54
- queue.publish 'Message to be automatically acked'
55
- delivery_tag_1 = delivery_tags['Message to be automatically acked']
56
- queue.publish 'Message to acked'
57
- delivery_tag_2 = delivery_tags['Message to acked']
58
- queue.publish 'Message to be left as pending'
59
- delivery_tag_3 = delivery_tags['Message to be left as pending']
60
-
61
- @channel.ack delivery_tag_2, true
62
-
63
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
64
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
65
- expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
66
- expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_1)
67
- expect(@channel.acknowledged_state[:acked]).to include(delivery_tag_2)
71
+ it 'should allow multiple messages to be nacked when `multiple` = true' do
72
+ queue.publish 'Message to be automatically nacked'
73
+ delivery_tag_1 = delivery_tags['Message to be automatically nacked']
74
+ queue.publish 'Message to nacked'
75
+ delivery_tag_2 = delivery_tags['Message to nacked']
76
+ queue.publish 'Message to be left as pending'
77
+ delivery_tag_3 = delivery_tags['Message to be left as pending']
78
+
79
+ @channel.nack delivery_tag_2, true
80
+
81
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
82
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
83
+ expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
84
+ expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_1)
85
+ expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_2)
86
+ end
68
87
  end
69
88
 
70
- it 'should allow multiple messages to be nacked when `multiple` = true' do
71
- queue.publish 'Message to be automatically nacked'
72
- delivery_tag_1 = delivery_tags['Message to be automatically nacked']
73
- queue.publish 'Message to nacked'
74
- delivery_tag_2 = delivery_tags['Message to nacked']
75
- queue.publish 'Message to be left as pending'
76
- delivery_tag_3 = delivery_tags['Message to be left as pending']
77
-
78
- @channel.nack delivery_tag_2, true
79
-
80
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_1)
81
- expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag_2)
82
- expect(@channel.acknowledged_state[:pending]).to include(delivery_tag_3)
83
- expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_1)
84
- expect(@channel.acknowledged_state[:nacked]).to include(delivery_tag_2)
89
+ context 'when using reject to negatively acknowledge' do
90
+ it 'should allow messages which have been nacked to be identified' do
91
+ queue.publish 'Message to reject'
92
+ delivery_tag = delivery_tags['Message to reject']
93
+ @channel.reject delivery_tag
94
+
95
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
96
+ expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
97
+ expect(@channel.acknowledged_state[:rejected]).to include(delivery_tag)
98
+ end
99
+
100
+ it 'should requeue messages with have been rejected with `requeue` = true' do
101
+ queue.publish 'Message to reject'
102
+ delivery_tag = delivery_tags['Message to reject']
103
+ @channel.reject delivery_tag, true
104
+ new_delivery_tag = delivery_tags['Message to reject']
105
+
106
+ expect(@channel.acknowledged_state[:pending]).not_to include(delivery_tag)
107
+ expect(@channel.acknowledged_state[:acked]).not_to include(delivery_tag)
108
+ expect(@channel.acknowledged_state[:rejected]).to include(delivery_tag)
109
+
110
+ expect(@channel.acknowledged_state[:pending]).to include(new_delivery_tag)
111
+ end
85
112
  end
86
113
  end
87
114
  end
@@ -39,6 +39,11 @@ describe BunnyMock::Queue do
39
39
  it 'should raise error when exchange does not exists' do
40
40
  expect { @receiver.bind('this.xchg.does.not.exist') }.to raise_exception(Bunny::NotFound)
41
41
  end
42
+
43
+ it 'should return self' do
44
+ expect(@receiver.bind(@source)).to eq @receiver
45
+ end
46
+
42
47
  end
43
48
 
44
49
  context '#unbind' do
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.6.0
4
+ version: 1.7.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: 2017-04-10 00:00:00.000000000 Z
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project:
191
- rubygems_version: 2.6.4
191
+ rubygems_version: 2.5.1
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Mocking for the popular Bunny client for RabbitMQ