Sha256: 3b7314a107183571bb3b49e44c012df0547e8527bcd6de5ec66c622a3cfc43dc
Contents?: true
Size: 1.36 KB
Versions: 25
Compression:
Stored size: 1.36 KB
Contents
require 'spec_helper' describe Freddy::SyncResponseContainer do let(:container) { described_class.new(on_timeout) } let(:on_timeout) { Proc.new {} } context 'when timeout' do subject { container.wait_for_response(0.01) } it 'raises timeout error' do expect { subject }.to raise_error do |error| expect(error).to be_a(Freddy::TimeoutError) expect(error.response).to eq( error: 'RequestTimeout', message: 'Timed out waiting for response' ) end end end context 'when nil response' do let(:delivery) { {} } it 'raises timeout error' do expect { container.call(nil, delivery) }.to raise_error(StandardError, 'unexpected nil value for response') end end describe '#wait_for_response' do let(:timeout) { 2 } let(:response) { {msg: 'response'} } let(:delivery) { OpenStruct.new(type: 'success') } context 'when called after #call' do let(:max_wait_time_in_seconds) { 0.5 } before do container.call(response, delivery) end it 'returns response' do expect(container.wait_for_response(timeout)).to eq(response) end it 'does not wait for timeout' do expect { container.wait_for_response(timeout) }.to change(Time, :now).by_at_most(max_wait_time_in_seconds) end end end end
Version data entries
25 entries across 25 versions & 2 rubygems