-
Notifications
You must be signed in to change notification settings - Fork 19
/
connection_spec.rb
40 lines (33 loc) · 1.36 KB
/
connection_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'spec_helper'
require 'shared/protocol_msgbus_behaviour'
describe Ably::Realtime::Connection do
let(:client) { instance_double('Ably::Realtime::Client', logger: double('logger').as_null_object, recover: nil, endpoint: double('endpoint', host: 'realtime.ably.io')) }
subject do
Ably::Realtime::Connection.new(client, {}).tap do |connection|
connection.__incoming_protocol_msgbus__.unsubscribe
connection.__outgoing_protocol_msgbus__.unsubscribe
end
end
before do
expect(EventMachine).to receive(:next_tick) # non_blocking_loop_while for delivery of messages async
subject.__incoming_protocol_msgbus__.off
subject.__outgoing_protocol_msgbus__.off
end
describe 'callbacks' do
specify 'are supported for valid STATE events' do
state = nil
subject.on(:initialized) { state = :ready }
expect { subject.emit(:initialized) }.to change { state }.to(:ready)
end
specify 'fail with unacceptable STATE event names' do
expect { subject.on(:invalid) }.to raise_error KeyError
expect { subject.emit(:invalid) }.to raise_error KeyError
expect { subject.off(:invalid) }.to raise_error KeyError
end
end
it_behaves_like 'an incoming protocol message bus'
it_behaves_like 'an outgoing protocol message bus'
after(:all) do
sleep 1 # let realtime library shut down any open clients
end
end