spec/acceptance/realtime/connection_spec.rb in ably-0.8.14 vs spec/acceptance/realtime/connection_spec.rb in ably-0.8.15
- old
+ new
@@ -613,20 +613,27 @@
channel.publish('event', 'data')
end
end
end
- it 'is set to 0 when a message sent ACK is received' do
- channel.publish('event', 'data') do
+ it 'is set to 0 when a message is received back' do
+ channel.publish('event', 'data')
+ channel.subscribe do
expect(connection.serial).to eql(0)
stop_reactor
end
end
- it 'is set to 1 when the second message sent ACK is received' do
+ it 'is set to 1 when the second message is received' do
channel.publish('event', 'data') do
- channel.publish('event', 'data') do
+ channel.publish('event', 'data')
+ end
+
+ messages = []
+ channel.subscribe do |message|
+ messages << message
+ if messages.length == 2
expect(connection.serial).to eql(1)
stop_reactor
end
end
end
@@ -882,15 +889,20 @@
expected_serial = -1
expect(connection.key).to_not be_nil
expect(connection.serial).to eql(expected_serial)
channel.attach do
- channel.publish('event', 'data') do
+ channel.publish('event', 'data')
+ channel.subscribe do
+ channel.unsubscribe
+
expected_serial += 1 # attach message received
expect(connection.serial).to eql(expected_serial)
- channel.publish('event', 'data') do
+ channel.publish('event', 'data')
+ channel.subscribe do
+ channel.unsubscribe
expected_serial += 1 # attach message received
expect(connection.serial).to eql(expected_serial)
expect(connection.recovery_key).to eql("#{connection.key}:#{connection.serial}")
stop_reactor
@@ -1276,18 +1288,42 @@
end
end
end
context 'connection state change' do
+ # See https://github.com/ably/ably-ruby/issues/103
+ it 'emits event to all and single subscribers' do
+ connected_emitted = []
+ block = Proc.new do |state_change|
+ if state_change.current == :connected
+ connected_emitted << state_change
+ EventMachine.add_timer(0.5) do
+ expect(connected_emitted.length).to eql(2)
+ stop_reactor
+ end
+ end
+ end
+ connection.on(&block)
+ connection.on(:connected, &block)
+ end
+
it 'emits a ConnectionStateChange object' do
connection.on(:connected) do |connection_state_change|
expect(connection_state_change).to be_a(Ably::Models::ConnectionStateChange)
stop_reactor
end
end
context 'ConnectionStateChange object' do
+ def unbind
+ if connection.transport
+ connection.transport.unbind
+ else
+ EventMachine.add_timer(0.005) { unbind }
+ end
+ end
+
it 'has current state' do
connection.on(:connected) do |connection_state_change|
expect(connection_state_change.current).to eq(:connected)
stop_reactor
end
@@ -1347,11 +1383,11 @@
connection.once(:connecting) do
connection.once(:disconnected) do |connection_state_change|
expect(connection_state_change.retry_in).to eql(0)
stop_reactor
end
- EventMachine.add_timer(0.005) { connection.transport.unbind }
+ unbind
end
end
it 'is 0 when an immediate reconnect will occur' do
connection.once(:connected) do
@@ -1368,10 +1404,10 @@
connection.once(:connecting) do
connection.once(:disconnected) do |connection_state_change|
expect(connection_state_change.retry_in).to be > 0
stop_reactor
end
- EventMachine.add_timer(0.005) { connection.transport.unbind }
+ unbind
end
connection.transport.unbind
end
end
end