message-driver 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.rubocop.yml +26 -2
  4. data/.rubocop_todo.yml +15 -123
  5. data/.travis.yml +2 -1
  6. data/CHANGELOG.md +10 -1
  7. data/Gemfile +15 -6
  8. data/Rakefile +23 -12
  9. data/ci/reset_vhost +8 -3
  10. data/ci/travis_setup +0 -3
  11. data/features/.nav +6 -1
  12. data/features/CHANGELOG.md +10 -1
  13. data/features/amqp_specific_features/binding_amqp_destinations.feature +1 -0
  14. data/features/amqp_specific_features/declaring_amqp_exchanges.feature +1 -0
  15. data/features/amqp_specific_features/server_named_destinations.feature +1 -0
  16. data/features/destination_metadata.feature +26 -0
  17. data/features/logging.feature +1 -1
  18. data/features/middleware/middleware_basics.feature +91 -0
  19. data/features/middleware/middleware_ordering.feature +60 -0
  20. data/features/middleware/middleware_parameters.feature +43 -0
  21. data/features/middleware/middleware_with_blocks.feature +85 -0
  22. data/features/step_definitions/dynamic_destinations_steps.rb +1 -1
  23. data/features/step_definitions/message_consumers_steps.rb +5 -0
  24. data/features/step_definitions/middleware_steps.rb +10 -0
  25. data/features/step_definitions/steps.rb +10 -2
  26. data/features/support/env.rb +4 -3
  27. data/features/support/firewall_helper.rb +1 -1
  28. data/features/support/message_table_matcher.rb +3 -2
  29. data/features/support/no_error_matcher.rb +2 -2
  30. data/features/support/test_runner.rb +11 -57
  31. data/features/support/transforms.rb +12 -10
  32. data/lib/message_driver.rb +3 -1
  33. data/lib/message_driver/adapters/base.rb +11 -11
  34. data/lib/message_driver/adapters/bunny_adapter.rb +189 -132
  35. data/lib/message_driver/adapters/in_memory_adapter.rb +51 -34
  36. data/lib/message_driver/adapters/stomp_adapter.rb +22 -23
  37. data/lib/message_driver/broker.rb +21 -16
  38. data/lib/message_driver/client.rb +15 -16
  39. data/lib/message_driver/destination.rb +26 -8
  40. data/lib/message_driver/message.rb +5 -4
  41. data/lib/message_driver/middleware.rb +8 -0
  42. data/lib/message_driver/middleware/base.rb +19 -0
  43. data/lib/message_driver/middleware/block_middleware.rb +33 -0
  44. data/lib/message_driver/middleware/middleware_stack.rb +61 -0
  45. data/lib/message_driver/subscription.rb +2 -2
  46. data/lib/message_driver/version.rb +1 -1
  47. data/message-driver.gemspec +3 -4
  48. data/spec/integration/bunny/amqp_integration_spec.rb +21 -82
  49. data/spec/integration/bunny/bunny_adapter_spec.rb +288 -268
  50. data/spec/integration/in_memory/in_memory_adapter_spec.rb +93 -90
  51. data/spec/integration/stomp/stomp_adapter_spec.rb +126 -93
  52. data/spec/spec_helper.rb +11 -9
  53. data/spec/support/shared/adapter_examples.rb +1 -1
  54. data/spec/support/shared/client_ack_examples.rb +4 -4
  55. data/spec/support/shared/context_examples.rb +6 -4
  56. data/spec/support/shared/destination_examples.rb +54 -14
  57. data/spec/support/shared/subscription_examples.rb +33 -26
  58. data/spec/support/shared/transaction_examples.rb +12 -12
  59. data/spec/support/utils.rb +1 -1
  60. data/spec/units/message_driver/adapters/base_spec.rb +42 -40
  61. data/spec/units/message_driver/broker_spec.rb +38 -38
  62. data/spec/units/message_driver/client_spec.rb +87 -87
  63. data/spec/units/message_driver/destination_spec.rb +16 -11
  64. data/spec/units/message_driver/message_spec.rb +96 -70
  65. data/spec/units/message_driver/middleware/base_spec.rb +30 -0
  66. data/spec/units/message_driver/middleware/block_middleware_spec.rb +82 -0
  67. data/spec/units/message_driver/middleware/middleware_stack_spec.rb +165 -0
  68. data/spec/units/message_driver/subscription_spec.rb +18 -16
  69. data/test_lib/broker_config.rb +21 -5
  70. data/test_lib/coverage.rb +11 -0
  71. data/test_lib/provider/base.rb +59 -0
  72. data/test_lib/provider/in_memory.rb +6 -0
  73. data/test_lib/provider/rabbitmq.rb +67 -0
  74. metadata +46 -35
@@ -2,15 +2,15 @@ require 'spec_helper'
2
2
  require 'message_driver/adapters/in_memory_adapter'
3
3
 
4
4
  module MessageDriver
5
- describe Broker do
5
+ RSpec.describe Broker do
6
6
  let(:broker_name) { described_class::DEFAULT_BROKER_NAME }
7
7
  let(:options) { { adapter: :in_memory } }
8
8
 
9
9
  describe '.configure and .broker' do
10
10
  it 'calls new, passing in the options and saves the instance' do
11
- options = {foo: :bar}
11
+ options = { foo: :bar }
12
12
  result = double(described_class).as_null_object
13
- described_class.should_receive(:new).with(described_class::DEFAULT_BROKER_NAME, options).and_return(result)
13
+ expect(described_class).to receive(:new).with(described_class::DEFAULT_BROKER_NAME, options).and_return(result)
14
14
 
15
15
  described_class.configure(options)
16
16
 
@@ -20,15 +20,15 @@ module MessageDriver
20
20
 
21
21
  it "doesn't allow you to configure the same broker twice" do
22
22
  described_class.configure(broker_name, options)
23
- expect {
23
+ expect do
24
24
  described_class.configure(broker_name, options)
25
- }.to raise_error MessageDriver::BrokerAlreadyConfigured, match('default')
25
+ end.to raise_error MessageDriver::BrokerAlreadyConfigured, /default/
26
26
  end
27
27
 
28
28
  context 'when configurating multiple brokers' do
29
29
  it 'allows you to fetch each configured broker through .broker' do
30
- options1 = {foo: :bar}
31
- options2 = {bar: :baz}
30
+ options1 = { foo: :bar }
31
+ options2 = { bar: :baz }
32
32
  result1 = double('result1').as_null_object
33
33
  result2 = double('result2').as_null_object
34
34
  allow(described_class).to receive(:new).with(:result1, options1).and_return(result1)
@@ -44,9 +44,9 @@ module MessageDriver
44
44
 
45
45
  context "when you try to access a broker that isn't configured" do
46
46
  it 'should raise an error' do
47
- expect {
47
+ expect do
48
48
  described_class.broker(:not_an_adapter)
49
- }.to raise_error BrokerNotConfigured
49
+ end.to raise_error BrokerNotConfigured
50
50
  end
51
51
  end
52
52
  end
@@ -64,13 +64,13 @@ module MessageDriver
64
64
  expect(broker1).to have_received(:stop)
65
65
  expect(broker2).to have_received(:stop)
66
66
 
67
- expect {
67
+ expect do
68
68
  described_class.broker(:broker1)
69
- }.to raise_error BrokerNotConfigured
69
+ end.to raise_error BrokerNotConfigured
70
70
 
71
- expect {
71
+ expect do
72
72
  described_class.broker(:broker2)
73
- }.to raise_error BrokerNotConfigured
73
+ end.to raise_error BrokerNotConfigured
74
74
  end
75
75
 
76
76
  context 'when one of the brokers raises and error' do
@@ -81,20 +81,20 @@ module MessageDriver
81
81
  allow(broker1).to receive(:stop).and_raise 'error stopping broker1!'
82
82
  allow(broker2).to receive(:stop).and_call_original
83
83
 
84
- expect {
84
+ expect do
85
85
  described_class.reset
86
- }.not_to raise_error
86
+ end.not_to raise_error
87
87
 
88
88
  expect(broker1).to have_received(:stop)
89
89
  expect(broker2).to have_received(:stop)
90
90
 
91
- expect {
91
+ expect do
92
92
  described_class.broker(:broker1)
93
- }.to raise_error BrokerNotConfigured
93
+ end.to raise_error BrokerNotConfigured
94
94
 
95
- expect {
95
+ expect do
96
96
  described_class.broker(:broker2)
97
- }.to raise_error BrokerNotConfigured
97
+ end.to raise_error BrokerNotConfigured
98
98
  end
99
99
  end
100
100
  end
@@ -123,9 +123,9 @@ module MessageDriver
123
123
 
124
124
  describe '#initialize' do
125
125
  it "raises an error if you don't specify an adapter" do
126
- expect {
126
+ expect do
127
127
  described_class.new({})
128
- }.to raise_error(/must specify an adapter/)
128
+ end.to raise_error(/must specify an adapter/)
129
129
  end
130
130
 
131
131
  it 'if you provide an adapter instance, it uses that one' do
@@ -152,9 +152,9 @@ module MessageDriver
152
152
  it "raises and error if you don't provide a MessageDriver::Adapters::Base" do
153
153
  adapter = Hash.new
154
154
 
155
- expect {
155
+ expect do
156
156
  described_class.new(adapter: adapter)
157
- }.to raise_error(/adapter must be a MessageDriver::Adapters::Base/)
157
+ end.to raise_error(/adapter must be a MessageDriver::Adapters::Base/)
158
158
  end
159
159
 
160
160
  it 'starts off with the adapter not stopped' do
@@ -194,9 +194,9 @@ module MessageDriver
194
194
  end
195
195
 
196
196
  it 'marks the broker as stopped' do
197
- expect {
197
+ expect do
198
198
  subject.stop
199
- }.to change { subject.stopped? }.from(false).to(true)
199
+ end.to change { subject.stopped? }.from(false).to(true)
200
200
  end
201
201
 
202
202
  it 'invalidates the contexts' do
@@ -215,9 +215,9 @@ module MessageDriver
215
215
  end
216
216
 
217
217
  it 'reconfigures the adapter' do
218
- expect {
218
+ expect do
219
219
  subject.restart
220
- }.to change { subject.adapter }
220
+ end.to change { subject.adapter }
221
221
  end
222
222
 
223
223
  it "stops the adapter if it hasn't already been stopped" do
@@ -228,16 +228,16 @@ module MessageDriver
228
228
  it 'does not stop the adapter again if it has already been stopped' do
229
229
  expect(subject.adapter).to be original_adapter
230
230
  subject.stop
231
- expect {
231
+ expect do
232
232
  subject.restart
233
- }.to change { subject.stopped? }.from(true).to(false)
233
+ end.to change { subject.stopped? }.from(true).to(false)
234
234
  expect(original_adapter).to have_received(:stop).once
235
235
  end
236
236
  end
237
237
 
238
238
  describe '#configuration' do
239
239
  it 'returns the configuration hash you passed to .configure' do
240
- config = {adapter: :in_memory, foo: :bar, baz: :boz}
240
+ config = { adapter: :in_memory, foo: :bar, baz: :boz }
241
241
  instance = described_class.new(config)
242
242
  expect(instance.configuration).to be config
243
243
  end
@@ -259,15 +259,15 @@ module MessageDriver
259
259
  context "when the destination can't be found" do
260
260
  let(:bad_dest_name) { :not_a_queue }
261
261
  it 'raises a MessageDriver:NoSuchDestinationError' do
262
- expect {
262
+ expect do
263
263
  broker.find_destination(bad_dest_name)
264
- }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
264
+ end.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
265
265
  end
266
266
  end
267
267
  end
268
268
 
269
269
  describe '#consumer' do
270
- let(:consumer_double) { lambda do |_| end }
270
+ let(:consumer_double) { ->(_) {} }
271
271
  it 'saves the provided consumer' do
272
272
  broker.consumer(:my_consumer, &consumer_double)
273
273
  expect(broker.consumers[:my_consumer]).to be(consumer_double)
@@ -275,15 +275,15 @@ module MessageDriver
275
275
 
276
276
  context 'when no consumer is provided' do
277
277
  it 'raises an error' do
278
- expect {
278
+ expect do
279
279
  broker.consumer(:my_consumer)
280
- }.to raise_error(MessageDriver::Error, 'you must provide a block')
280
+ end.to raise_error(MessageDriver::Error, 'you must provide a block')
281
281
  end
282
282
  end
283
283
  end
284
284
 
285
285
  describe '#find_consumer' do
286
- let(:consumer_double) { lambda do |_| end }
286
+ let(:consumer_double) { ->(_) {} }
287
287
  it 'finds the previously defined consumer' do
288
288
  my_consumer = broker.consumer(:my_consumer, &consumer_double)
289
289
  expect(broker.find_consumer(:my_consumer)).to be(my_consumer)
@@ -292,9 +292,9 @@ module MessageDriver
292
292
  context "when the consumer can't be found" do
293
293
  let(:bad_consumer_name) { :not_a_queue }
294
294
  it 'raises a MessageDriver:NoSuchConsumerError' do
295
- expect {
295
+ expect do
296
296
  broker.find_consumer(bad_consumer_name)
297
- }.to raise_error(MessageDriver::NoSuchConsumerError, /#{bad_consumer_name}/)
297
+ end.to raise_error(MessageDriver::NoSuchConsumerError, /#{bad_consumer_name}/)
298
298
  end
299
299
  end
300
300
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'message_driver/adapters/in_memory_adapter'
4
4
 
5
5
  module MessageDriver
6
- describe Client do
6
+ RSpec.describe Client do
7
7
  class TestPublisher
8
8
  include Client
9
9
  end
@@ -41,66 +41,66 @@ module MessageDriver
41
41
  end
42
42
 
43
43
  context 'with a given adapter_context' do
44
- around(:each) do |example|
44
+ around(:example) do |example|
45
45
  subject.with_adapter_context(adapter_context, &example)
46
46
  end
47
47
 
48
48
  describe '#dynamic_destination' do
49
49
  let(:dest_name) { 'my_new_queue' }
50
- let(:dest_options) { {type: 2} }
51
- let(:message_props) { {expires: 'soon'} }
50
+ let(:dest_options) { { type: 2 } }
51
+ let(:message_props) { { expires: 'soon' } }
52
52
  let(:created_dest) { double('created destination') }
53
53
  before do
54
- adapter_context.stub(:create_destination) { created_dest }
54
+ allow(adapter_context).to receive(:create_destination) { created_dest }
55
55
  end
56
56
 
57
57
  it 'delegates to the adapter_context' do
58
58
  result = subject.dynamic_destination(dest_name, dest_options, message_props)
59
59
  expect(result).to be(created_dest)
60
60
 
61
- adapter_context.should have_received(:create_destination).with(dest_name, dest_options, message_props)
61
+ expect(adapter_context).to have_received(:create_destination).with(dest_name, dest_options, message_props)
62
62
  end
63
63
 
64
64
  it 'only requires destination name' do
65
65
  result = subject.dynamic_destination(dest_name)
66
66
  expect(result).to be(created_dest)
67
67
 
68
- adapter_context.should have_received(:create_destination).with(dest_name, {}, {})
68
+ expect(adapter_context).to have_received(:create_destination).with(dest_name, {}, {})
69
69
  end
70
70
  end
71
71
 
72
72
  describe '#publish' do
73
73
  let(:destination) { broker.destination(:my_queue, 'my_queue', exclusive: true) }
74
74
  let(:body) { 'my message' }
75
- let(:headers) { {foo: :bar} }
76
- let(:properties) { {bar: :baz} }
75
+ let(:headers) { { foo: :bar } }
76
+ let(:properties) { { bar: :baz } }
77
77
  before do
78
- adapter_context.stub(:publish)
78
+ allow(destination).to receive(:publish)
79
79
  end
80
80
 
81
- it 'delegates to the adapter_context' do
81
+ it 'delegates to the destination' do
82
82
  subject.publish(destination, body, headers, properties)
83
- adapter_context.should have_received(:publish).with(destination, body, headers, properties)
83
+ expect(destination).to have_received(:publish).with(body, headers, properties)
84
84
  end
85
85
 
86
- it 'only requires destination and body' do
86
+ it 'only requires the body' do
87
87
  subject.publish(destination, body)
88
- adapter_context.should have_received(:publish).with(destination, body, {}, {})
88
+ expect(destination).to have_received(:publish).with(body, {}, {})
89
89
  end
90
90
 
91
91
  it 'looks up the destination if necessary' do
92
92
  destination
93
93
  subject.publish(:my_queue, body, headers, properties)
94
- adapter_context.should have_received(:publish).with(destination, body, headers, properties)
94
+ expect(destination).to have_received(:publish).with(body, headers, properties)
95
95
  end
96
96
 
97
97
  context "when the destination can't be found" do
98
98
  let(:bad_dest_name) { :not_a_queue }
99
99
  it 'raises a MessageDriver:NoSuchDestinationError' do
100
- expect {
100
+ expect do
101
101
  subject.publish(bad_dest_name, body, headers, properties)
102
- }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
103
- adapter_context.should_not have_received(:publish)
102
+ end.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
103
+ expect(destination).not_to have_received(:publish)
104
104
  end
105
105
  end
106
106
  end
@@ -108,34 +108,34 @@ module MessageDriver
108
108
  describe '#pop_message' do
109
109
  let(:expected) { double(MessageDriver::Message) }
110
110
  let(:destination) { broker.destination(:my_queue, 'my_queue', exclusive: true) }
111
- let(:options) { {foo: :bar} }
111
+ let(:options) { { foo: :bar } }
112
112
  before do
113
- adapter_context.stub(:pop_message)
113
+ allow(destination).to receive(:pop_message)
114
114
  end
115
115
 
116
116
  it 'delegates to the adapter_context' do
117
117
  subject.pop_message(destination, options)
118
- adapter_context.should have_received(:pop_message).with(destination, options)
118
+ expect(destination).to have_received(:pop_message).with(options)
119
119
  end
120
120
 
121
121
  it 'looks up the destination if necessary' do
122
122
  destination
123
123
  subject.pop_message(:my_queue, options)
124
- adapter_context.should have_received(:pop_message).with(destination, options)
124
+ expect(destination).to have_received(:pop_message).with(options)
125
125
  end
126
126
 
127
127
  context "when the destination can't be found" do
128
128
  let(:bad_dest_name) { :not_a_queue }
129
129
  it 'raises a MessageDriver:NoSuchDestinationError' do
130
- expect {
130
+ expect do
131
131
  subject.pop_message(bad_dest_name, options)
132
- }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
133
- adapter_context.should_not have_received(:pop_message)
132
+ end.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
133
+ expect(destination).not_to have_received(:pop_message)
134
134
  end
135
135
  end
136
136
 
137
- it 'requires the destination and returns the message' do
138
- adapter_context.should_receive(:pop_message).with(destination, {}).and_return(expected)
137
+ it 'requires just the destination and returns the message' do
138
+ expect(destination).to receive(:pop_message).with({}).and_return(expected)
139
139
 
140
140
  actual = subject.pop_message(destination)
141
141
 
@@ -143,7 +143,7 @@ module MessageDriver
143
143
  end
144
144
 
145
145
  it 'passes the options through and returns the message' do
146
- adapter_context.should_receive(:pop_message).with(destination, options).and_return(expected)
146
+ expect(destination).to receive(:pop_message).with(options).and_return(expected)
147
147
 
148
148
  actual = subject.pop_message(destination, options)
149
149
 
@@ -153,44 +153,44 @@ module MessageDriver
153
153
 
154
154
  describe '#with_message_transaction' do
155
155
  before do
156
- adapter_context.stub(:begin_transaction)
157
- adapter_context.stub(:commit_transaction)
158
- adapter_context.stub(:rollback_transaction)
156
+ allow(adapter_context).to receive(:begin_transaction)
157
+ allow(adapter_context).to receive(:commit_transaction)
158
+ allow(adapter_context).to receive(:rollback_transaction)
159
159
  end
160
160
 
161
161
  context 'when the adapter supports transactions' do
162
162
  before do
163
- adapter_context.stub(:supports_transactions?) { true }
163
+ allow(adapter_context).to receive(:supports_transactions?) { true }
164
164
  end
165
165
  it 'delegates to the adapter context' do
166
- expect { |blk|
166
+ expect do |blk|
167
167
  subject.with_message_transaction(&blk)
168
- }.to yield_control
169
- adapter_context.should have_received(:begin_transaction)
170
- adapter_context.should have_received(:commit_transaction)
168
+ end.to yield_control
169
+ expect(adapter_context).to have_received(:begin_transaction)
170
+ expect(adapter_context).to have_received(:commit_transaction)
171
171
  end
172
172
 
173
173
  context 'when the block raises an error' do
174
174
  it 'calls rollback instead of commit and raises the error' do
175
- expect {
175
+ expect do
176
176
  subject.with_message_transaction do
177
- raise 'having a tough time'
177
+ fail 'having a tough time'
178
178
  end
179
- }.to raise_error 'having a tough time'
180
- adapter_context.should have_received(:begin_transaction)
181
- adapter_context.should_not have_received(:commit_transaction)
182
- adapter_context.should have_received(:rollback_transaction)
179
+ end.to raise_error 'having a tough time'
180
+ expect(adapter_context).to have_received(:begin_transaction)
181
+ expect(adapter_context).not_to have_received(:commit_transaction)
182
+ expect(adapter_context).to have_received(:rollback_transaction)
183
183
  end
184
184
 
185
185
  context 'and the the rollback raises an error' do
186
186
  it 'logs the error from the rollback and raises the original error' do
187
187
  allow(logger).to receive(:error)
188
- adapter_context.stub(:rollback_transaction).and_raise('rollback failed!')
189
- expect {
188
+ allow(adapter_context).to receive(:rollback_transaction).and_raise('rollback failed!')
189
+ expect do
190
190
  subject.with_message_transaction do
191
- raise 'having a tough time'
191
+ fail 'having a tough time'
192
192
  end
193
- }.to raise_error 'having a tough time'
193
+ end.to raise_error 'having a tough time'
194
194
  expect(logger).to have_received(:error).with(match('rollback failed!'))
195
195
  end
196
196
  end
@@ -198,27 +198,27 @@ module MessageDriver
198
198
 
199
199
  context 'when the transactions are nested' do
200
200
  it 'only starts and commits once' do
201
- expect { |blk|
201
+ expect do |blk|
202
202
  subject.with_message_transaction do
203
203
  subject.with_message_transaction(&blk)
204
204
  end
205
- }.to yield_control
206
- adapter_context.should have_received(:begin_transaction).once
207
- adapter_context.should have_received(:commit_transaction).once
205
+ end.to yield_control
206
+ expect(adapter_context).to have_received(:begin_transaction).once
207
+ expect(adapter_context).to have_received(:commit_transaction).once
208
208
  end
209
209
 
210
210
  context 'when the block raises an error' do
211
211
  it 'calls rollback instead of commit and raises the error' do
212
- expect {
212
+ expect do
213
213
  subject.with_message_transaction do
214
214
  subject.with_message_transaction do
215
- raise 'having a tough time'
215
+ fail 'having a tough time'
216
216
  end
217
217
  end
218
- }.to raise_error 'having a tough time'
219
- adapter_context.should have_received(:begin_transaction).once
220
- adapter_context.should_not have_received(:commit_transaction)
221
- adapter_context.should have_received(:rollback_transaction).once
218
+ end.to raise_error 'having a tough time'
219
+ expect(adapter_context).to have_received(:begin_transaction).once
220
+ expect(adapter_context).not_to have_received(:commit_transaction)
221
+ expect(adapter_context).to have_received(:rollback_transaction).once
222
222
  end
223
223
  end
224
224
  end
@@ -226,21 +226,21 @@ module MessageDriver
226
226
 
227
227
  context "when the adapter doesn't support transactions" do
228
228
  before do
229
- adapter_context.stub(:supports_transactions?) { false }
229
+ allow(adapter_context).to receive(:supports_transactions?) { false }
230
230
  end
231
231
  it "run the block on it's own" do
232
- expect { |blk|
232
+ expect do |blk|
233
233
  subject.with_message_transaction(&blk)
234
- }.to yield_control
235
- adapter_context.should_not have_received(:begin_transaction)
236
- adapter_context.should_not have_received(:commit_transaction)
237
- adapter_context.should_not have_received(:rollback_transaction)
234
+ end.to yield_control
235
+ expect(adapter_context).not_to have_received(:begin_transaction)
236
+ expect(adapter_context).not_to have_received(:commit_transaction)
237
+ expect(adapter_context).not_to have_received(:rollback_transaction)
238
238
  end
239
239
  it 'logs a warning' do
240
240
  allow(logger).to receive(:debug)
241
- expect { |blk|
241
+ expect do |blk|
242
242
  subject.with_message_transaction(&blk)
243
- }.to yield_control
243
+ end.to yield_control
244
244
  expect(logger).to have_received(:debug).with('this adapter does not support transactions')
245
245
  end
246
246
  end
@@ -248,7 +248,7 @@ module MessageDriver
248
248
 
249
249
  describe '#ack_message' do
250
250
  let(:message) { double('message') }
251
- let(:options) { {foo: :bar} }
251
+ let(:options) { { foo: :bar } }
252
252
  before do
253
253
  allow(message).to receive(:ack)
254
254
  end
@@ -264,7 +264,7 @@ module MessageDriver
264
264
 
265
265
  describe '#nack_message' do
266
266
  let(:message) { double('message') }
267
- let(:options) { {foo: :bar} }
267
+ let(:options) { { foo: :bar } }
268
268
  before do
269
269
  allow(message).to receive(:nack)
270
270
  end
@@ -280,30 +280,30 @@ module MessageDriver
280
280
 
281
281
  describe '#subscribe' do
282
282
  let(:destination) { broker.destination(:my_queue, 'my_queue', exclusive: true) }
283
- let(:consumer_double) { lambda do |_| end }
283
+ let(:consumer_double) { ->(_) {} }
284
284
 
285
285
  before do
286
- adapter_context.stub(:subscribe)
286
+ allow(adapter_context).to receive(:subscribe)
287
287
  broker.consumer(:my_consumer, &consumer_double)
288
288
  end
289
289
 
290
290
  it 'delegates to the adapter_context' do
291
- adapter_context.should_receive(:subscribe).with(destination, {}) do |&blk|
291
+ expect(adapter_context).to receive(:subscribe).with(destination, {}) do |&blk|
292
292
  expect(blk).to be(consumer_double)
293
293
  end
294
294
  subject.subscribe(destination, :my_consumer)
295
295
  end
296
296
 
297
297
  it 'passes the options through' do
298
- options = {foo: :bar}
299
- adapter_context.should_receive(:subscribe).with(destination, options) do |&blk|
298
+ options = { foo: :bar }
299
+ expect(adapter_context).to receive(:subscribe).with(destination, options) do |&blk|
300
300
  expect(blk).to be(consumer_double)
301
301
  end
302
302
  subject.subscribe(destination, :my_consumer, options)
303
303
  end
304
304
 
305
305
  it 'looks up the destination' do
306
- adapter_context.should_receive(:subscribe).with(destination, {}) do |&blk|
306
+ expect(adapter_context).to receive(:subscribe).with(destination, {}) do |&blk|
307
307
  expect(blk).to be(consumer_double)
308
308
  end
309
309
  subject.subscribe(:my_queue, :my_consumer)
@@ -312,49 +312,49 @@ module MessageDriver
312
312
  context "when the destination can't be found" do
313
313
  let(:bad_dest_name) { :not_a_queue }
314
314
  it 'raises a MessageDriver:NoSuchDestinationError' do
315
- expect {
315
+ expect do
316
316
  subject.subscribe(bad_dest_name, :my_consumer)
317
- }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
318
- adapter_context.should_not have_received(:subscribe)
317
+ end.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
318
+ expect(adapter_context).not_to have_received(:subscribe)
319
319
  end
320
320
  end
321
321
 
322
322
  context "when the consumer can't be found" do
323
323
  let(:bad_consumer_name) { :not_a_consumer }
324
324
  it 'raises a MessageDriver:NoSuchConsumerError' do
325
- expect {
325
+ expect do
326
326
  subject.subscribe(destination, bad_consumer_name)
327
- }.to raise_error(MessageDriver::NoSuchConsumerError, /#{bad_consumer_name}/)
328
- adapter_context.should_not have_received(:subscribe)
327
+ end.to raise_error(MessageDriver::NoSuchConsumerError, /#{bad_consumer_name}/)
328
+ expect(adapter_context).not_to have_received(:subscribe)
329
329
  end
330
330
  end
331
331
  end
332
332
 
333
333
  describe '#subscribe_with' do
334
334
  let(:destination) { broker.destination(:my_queue, 'my_queue', exclusive: true) }
335
- let(:consumer_double) { lambda do |_| end }
335
+ let(:consumer_double) { ->(_) {} }
336
336
 
337
337
  before do
338
- adapter_context.stub(:subscribe)
338
+ allow(adapter_context).to receive(:subscribe)
339
339
  end
340
340
 
341
341
  it 'delegates to the adapter_context' do
342
- adapter_context.should_receive(:subscribe).with(destination, {}) do |&blk|
342
+ expect(adapter_context).to receive(:subscribe).with(destination, {}) do |&blk|
343
343
  expect(blk).to be(consumer_double)
344
344
  end
345
345
  subject.subscribe_with(destination, &consumer_double)
346
346
  end
347
347
 
348
348
  it 'passes the options through' do
349
- options = {foo: :bar}
350
- adapter_context.should_receive(:subscribe).with(destination, options) do |&blk|
349
+ options = { foo: :bar }
350
+ expect(adapter_context).to receive(:subscribe).with(destination, options) do |&blk|
351
351
  expect(blk).to be(consumer_double)
352
352
  end
353
353
  subject.subscribe_with(destination, options, &consumer_double)
354
354
  end
355
355
 
356
356
  it 'looks up the destination' do
357
- adapter_context.should_receive(:subscribe).with(destination, {}) do |&blk|
357
+ expect(adapter_context).to receive(:subscribe).with(destination, {}) do |&blk|
358
358
  expect(blk).to be(consumer_double)
359
359
  end
360
360
  subject.subscribe_with(:my_queue, &consumer_double)
@@ -363,10 +363,10 @@ module MessageDriver
363
363
  context "when the destination can't be found" do
364
364
  let(:bad_dest_name) { :not_a_queue }
365
365
  it 'raises a MessageDriver:NoSuchDestinationError' do
366
- expect {
366
+ expect do
367
367
  subject.subscribe_with(bad_dest_name, &consumer_double)
368
- }.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
369
- adapter_context.should_not have_received(:subscribe)
368
+ end.to raise_error(MessageDriver::NoSuchDestinationError, /#{bad_dest_name}/)
369
+ expect(adapter_context).not_to have_received(:subscribe)
370
370
  end
371
371
  end
372
372
  end