From 52a9d07579f20f56708055d7bf4c41d20e2aaf52 Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Wed, 3 Feb 2016 08:02:48 +0000 Subject: [PATCH] RTL4b --- ablySpec/RealtimeClientChannel.swift | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/ablySpec/RealtimeClientChannel.swift b/ablySpec/RealtimeClientChannel.swift index 99c1424bf..c1e0d56ea 100644 --- a/ablySpec/RealtimeClientChannel.swift +++ b/ablySpec/RealtimeClientChannel.swift @@ -139,6 +139,63 @@ class RealtimeClientChannel: QuickSpec { // RTL4 describe("attach") { + // RTL4b + context("results in an error if the connection state is") { + + pending("CLOSING") { + let options = AblyTests.commonAppSetup() + options.autoConnect = false + let client = ARTRealtime(options: options) + client.setTransportClass(TestProxyTransport.self) + client.connect() + defer { client.close() } + + expect(client.connection().state).toEventually(equal(ARTRealtimeConnectionState.Connected), timeout: testTimeout) + let transport = client.transport as! TestProxyTransport + transport.actionsIgnored += [.Closed] + + let channel = client.channel("test") + + client.close() + expect(client.connection().state).to(equal(ARTRealtimeConnectionState.Closing)) + + expect(channel.attach()).toNot(beNil()) + } + + it("CLOSED") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + + let channel = client.channel("test") + + client.close() + expect(client.connection().state).toEventually(equal(ARTRealtimeConnectionState.Closed), timeout: testTimeout) + + expect(channel.attach()).toNot(beNil()) + } + + it("SUSPENDED") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + + let channel = client.channel("test") + client.onSuspended() + expect(client.connection().state).to(equal(ARTRealtimeConnectionState.Suspended)) + expect(channel.attach()).toNot(beNil()) + } + + it("FAILED") { + let client = ARTRealtime(options: AblyTests.commonAppSetup()) + defer { client.close() } + + let channel = client.channel("test") + client.onError(AblyTests.newErrorProtocolMessage()) + expect(client.connection().state).to(equal(ARTRealtimeConnectionState.Failed)) + expect(channel.attach()).toNot(beNil()) + } + + } + // RTL4c it("should send an ATTACH ProtocolMessage, change state to ATTACHING and change state to ATTACHED after confirmation") { let options = AblyTests.commonAppSetup()