Skip to content

Commit d9b6449

Browse files
authored
Merge pull request #33 from Fatsoma/ENG-549-log-channel-error-amends
Move open_channel test block instance var to class instance
2 parents d7c4748 + bbd6074 commit d9b6449

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

spec/hutch/channel_broker_spec.rb

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
Hutch::Config.instance_variable_set(:@config, nil)
1212
Hutch::Config.initialize
1313
end
14-
let(:connection) { double('Connection') }
15-
let(:channel) { double('Channel') }
14+
let(:connection) { double(:connection) }
15+
let(:channel) { double(:channel) }
16+
1617
subject(:channel_broker) { Hutch::ChannelBroker.new(connection, config) }
1718

1819
shared_examples 'an empty channel broker' do
@@ -46,8 +47,8 @@
4647
end
4748

4849
describe '#reconnect' do
49-
let(:new_channel) { double('Channel') }
50-
let(:new_exchange) { double('Exchange') }
50+
let(:new_channel) { double(:new_channel) }
51+
let(:new_exchange) { double(:new_exchange) }
5152

5253
before do
5354
allow(channel_broker).to receive(:disconnect)
@@ -97,8 +98,8 @@
9798
describe '#declare_wait_exchange' do
9899
let(:expiration) { rand(1000..1_000_000) }
99100
let(:suffix) { expiration.to_s }
100-
let(:new_exchange) { double('Exchange') }
101-
let(:new_queue) { double('Queue') }
101+
let(:new_exchange) { double(:new_exchange) }
102+
let(:new_queue) { double(:new_queue) }
102103
let(:exchange_name) { "wait-exchange_#{suffix}" }
103104
let(:queue_name) { "wait-queue_#{suffix}" }
104105
let(:main_exchange_name) { 'main-exchange' }
@@ -131,6 +132,17 @@
131132
end
132133

133134
describe '#open_channel' do
135+
let(:channel) do
136+
Class.new do
137+
def on_error(&block)
138+
@on_error = block
139+
end
140+
def test_on_error(*args)
141+
@on_error.call(*args)
142+
end
143+
def confirm_select; end
144+
end.new
145+
end
134146
let(:honey_badger) { double(:honey_badger) }
135147
let(:config) { {} }
136148
let(:method) { Class.new }
@@ -142,9 +154,6 @@
142154
allow(connection).to receive(:create_channel).and_return(channel)
143155
allow(connection).to receive(:prefetch_channel)
144156
allow(channel).to receive(:confirm_select)
145-
allow(channel).to receive(:on_error) do |&blk|
146-
@captured_block = blk
147-
end
148157
end
149158

150159
subject { channel_broker.open_channel }
@@ -183,8 +192,8 @@
183192
let(:method_id) { 'test-method-id' }
184193

185194
subject do
186-
channel_broker.open_channel.tap do
187-
@captured_block.call(channel, method)
195+
channel_broker.open_channel.tap do |channel|
196+
channel.test_on_error(channel, method)
188197
end
189198
end
190199

@@ -201,7 +210,6 @@
201210

202211
it do
203212
is_expected.to eq(channel)
204-
expect(@captured_block).to be_a(Proc)
205213
expect(honey_badger).to have_received(:notify)
206214
.with(
207215
error_class: 'Hutch::ChannelBroker::OnError',
@@ -223,7 +231,6 @@
223231

224232
it do
225233
is_expected.to eq(channel)
226-
expect(@captured_block).to be_a(Proc)
227234
expect(honey_badger).to have_received(:notify)
228235
.with(
229236
error_class: 'Hutch::ChannelBroker::OnError',

0 commit comments

Comments
 (0)