|
11 | 11 | Hutch::Config.instance_variable_set(:@config, nil) |
12 | 12 | Hutch::Config.initialize |
13 | 13 | end |
14 | | - let(:connection) { double('Connection') } |
15 | | - let(:channel) { double('Channel') } |
| 14 | + let(:connection) { double(:connection) } |
| 15 | + let(:channel) { double(:channel) } |
| 16 | + |
16 | 17 | subject(:channel_broker) { Hutch::ChannelBroker.new(connection, config) } |
17 | 18 |
|
18 | 19 | shared_examples 'an empty channel broker' do |
|
46 | 47 | end |
47 | 48 |
|
48 | 49 | 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) } |
51 | 52 |
|
52 | 53 | before do |
53 | 54 | allow(channel_broker).to receive(:disconnect) |
|
97 | 98 | describe '#declare_wait_exchange' do |
98 | 99 | let(:expiration) { rand(1000..1_000_000) } |
99 | 100 | 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) } |
102 | 103 | let(:exchange_name) { "wait-exchange_#{suffix}" } |
103 | 104 | let(:queue_name) { "wait-queue_#{suffix}" } |
104 | 105 | let(:main_exchange_name) { 'main-exchange' } |
|
131 | 132 | end |
132 | 133 |
|
133 | 134 | 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 |
134 | 146 | let(:honey_badger) { double(:honey_badger) } |
135 | 147 | let(:config) { {} } |
136 | 148 | let(:method) { Class.new } |
|
142 | 154 | allow(connection).to receive(:create_channel).and_return(channel) |
143 | 155 | allow(connection).to receive(:prefetch_channel) |
144 | 156 | allow(channel).to receive(:confirm_select) |
145 | | - allow(channel).to receive(:on_error) do |&blk| |
146 | | - @captured_block = blk |
147 | | - end |
148 | 157 | end |
149 | 158 |
|
150 | 159 | subject { channel_broker.open_channel } |
|
183 | 192 | let(:method_id) { 'test-method-id' } |
184 | 193 |
|
185 | 194 | 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) |
188 | 197 | end |
189 | 198 | end |
190 | 199 |
|
|
201 | 210 |
|
202 | 211 | it do |
203 | 212 | is_expected.to eq(channel) |
204 | | - expect(@captured_block).to be_a(Proc) |
205 | 213 | expect(honey_badger).to have_received(:notify) |
206 | 214 | .with( |
207 | 215 | error_class: 'Hutch::ChannelBroker::OnError', |
|
223 | 231 |
|
224 | 232 | it do |
225 | 233 | is_expected.to eq(channel) |
226 | | - expect(@captured_block).to be_a(Proc) |
227 | 234 | expect(honey_badger).to have_received(:notify) |
228 | 235 | .with( |
229 | 236 | error_class: 'Hutch::ChannelBroker::OnError', |
|
0 commit comments