spec/acceptance/realtime/connection_spec.rb in ably-0.8.1 vs spec/acceptance/realtime/connection_spec.rb in ably-0.8.2

- old
+ new

@@ -25,13 +25,13 @@ expect(connection.state).to eq(:connected) stop_reactor end end - context 'with :connect_automatically option set to false' do + context 'with :auto_connect option set to false' do let(:client) do - Ably::Realtime::Client.new(default_options.merge(connect_automatically: false)) + Ably::Realtime::Client.new(default_options.merge(auto_connect: false)) end it 'does not connect automatically' do EventMachine.add_timer(1) do expect(connection).to be_initialized @@ -199,35 +199,35 @@ end end context 'initialization state changes' do let(:phases) { [:connecting, :connected] } - let(:events_triggered) { [] } + let(:events_emitted) { [] } let(:test_expectation) do Proc.new do - expect(events_triggered).to eq(phases) + expect(events_emitted).to eq(phases) stop_reactor end end def expect_ordered_phases phases.each do |phase| connection.on(phase) do - events_triggered << phase - test_expectation.call if events_triggered.length == phases.length + events_emitted << phase + test_expectation.call if events_emitted.length == phases.length end end end context 'with implicit #connect' do - it 'are triggered in order' do + it 'are emitted in order' do expect_ordered_phases end end context 'with explicit #connect' do - it 'are triggered in order' do + it 'are emitted in order' do expect_ordered_phases connection.connect end end end @@ -540,24 +540,26 @@ end let(:available_states) { self.class.available_states} let(:states) { Hash.new } let(:client_options) { default_options.merge(log_level: :none) } - it 'is composed of connection id and serial that is kept up to date with each message ACK received' do + it 'is composed of connection key and serial that is kept up to date with each message ACK received' do connection.on(:connected) do expected_serial = -1 - expect(connection.id).to_not be_nil + expect(connection.key).to_not be_nil expect(connection.serial).to eql(expected_serial) client.channel('test').attach do |channel| channel.publish('event', 'data') do expected_serial += 1 # attach message received expect(connection.serial).to eql(expected_serial) channel.publish('event', 'data') do 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 end end end end @@ -619,19 +621,19 @@ stop_reactor end end end - it 'does not trigger a resume callback', api_private: true do + it 'does not call a resume callback', api_private: true do connection.once(:connected) do connection.transition_state_machine! :failed end connection.once(:failed) do recover_client = Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key)) recover_client.connection.on_resume do - raise 'Should not trigger resume callback' + raise 'Should not call the resume callback' end recover_client.connection.on(:connected) do EventMachine.add_timer(0.5) { stop_reactor } end end @@ -674,11 +676,11 @@ end context 'with invalid formatted value sent to server' do let(:client_options) { default_options.merge(recover: 'not-a-valid-connection-key:1', log_level: :none) } - it 'triggers a fatal error on the connection object, sets the #error_reason and disconnects' do + it 'emits a fatal error on the connection object, sets the #error_reason and disconnects' do connection.once(:error) do |error| expect(connection.state).to eq(:failed) expect(error.message).to match(/Invalid connection key/) expect(connection.error_reason.message).to match(/Invalid connection key/) expect(connection.error_reason.code).to eql(40006) @@ -689,10 +691,10 @@ end context 'with expired (missing) value sent to server' do let(:client_options) { default_options.merge(recover: '0123456789abcdef:0', log_level: :fatal) } - it 'triggers an error on the connection object, sets the #error_reason, yet will connect anyway' do + it 'emits an error on the connection object, sets the #error_reason, yet will connect anyway' do connection.once(:error) do |error| expect(connection.state).to eq(:connected) expect(error.message).to match(/Invalid connection key/i) expect(connection.error_reason.message).to match(/Invalid connection key/i) expect(connection.error_reason.code).to eql(80008)