From 3b0403e5563b546d382a71593c000f27e2810225 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Wed, 17 Oct 2018 18:29:24 -0400 Subject: [PATCH 1/3] Add test for Fail --- SnailTests/FailTests.swift | 39 ++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/SnailTests/FailTests.swift b/SnailTests/FailTests.swift index fcfd843..fa77aef 100644 --- a/SnailTests/FailTests.swift +++ b/SnailTests/FailTests.swift @@ -18,14 +18,41 @@ class FailTests: XCTestCase { super.setUp() subject = Fail(TestError.test) strings = [] - subject?.subscribe(onNext: { [weak self] string in self?.strings?.append(string) }) + error = nil + done = nil + + subject?.subscribe( + queue: nil, + onNext: { [weak self] string in self?.strings?.append(string) }, + onError: { error in self.error = error }, + onDone: { self.done = true } + ) + } + + func testOnErrorIsRun() { + XCTAssertEqual((error as? TestError), TestError.test) } - func testFail() { - subject? - .subscribe(onError: { error in self.error = error }) + func testOnNextIsNotRun() { subject?.on(.next("1")) - XCTAssert(strings?.count == 0) - XCTAssert((error as? TestError) == TestError.test) + XCTAssertEqual(strings?.count, 0) + } + + func testOnDoneIsNotRun() { + XCTAssertNil(done) + } + + func testFiresStoppedEventOnSubscribe() { + var newError: Error? = nil + done = nil + + subject?.subscribe( + onError: { error in newError = error }, + onDone: { self.done = true } + ) + + XCTAssertNotNil(newError as? TestError) + XCTAssertEqual(newError as? TestError, error as? TestError) + XCTAssertNil(done) } } From f1d7be901c2fb09ec7ae5dd605a81ae7824f4d77 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Mon, 19 Nov 2018 15:41:01 -0500 Subject: [PATCH 2/3] Use -bash --- SnailTests/FailTests.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SnailTests/FailTests.swift b/SnailTests/FailTests.swift index fa77aef..91222c5 100644 --- a/SnailTests/FailTests.swift +++ b/SnailTests/FailTests.swift @@ -20,15 +20,15 @@ class FailTests: XCTestCase { strings = [] error = nil done = nil - + subject?.subscribe( queue: nil, - onNext: { [weak self] string in self?.strings?.append(string) }, - onError: { error in self.error = error }, + onNext: { [weak self] in self?.strings?.append($0) }, + onError: { self.error = $0 }, onDone: { self.done = true } ) } - + func testOnErrorIsRun() { XCTAssertEqual((error as? TestError), TestError.test) } @@ -37,11 +37,11 @@ class FailTests: XCTestCase { subject?.on(.next("1")) XCTAssertEqual(strings?.count, 0) } - + func testOnDoneIsNotRun() { XCTAssertNil(done) } - + func testFiresStoppedEventOnSubscribe() { var newError: Error? = nil done = nil @@ -50,7 +50,7 @@ class FailTests: XCTestCase { onError: { error in newError = error }, onDone: { self.done = true } ) - + XCTAssertNotNil(newError as? TestError) XCTAssertEqual(newError as? TestError, error as? TestError) XCTAssertNil(done) From 07d9ef9757376d346657ffe10906816bc24bfc52 Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Mon, 19 Nov 2018 15:41:47 -0500 Subject: [PATCH 3/3] Fix linter warnings --- SnailTests/FailTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnailTests/FailTests.swift b/SnailTests/FailTests.swift index 91222c5..c9f0558 100644 --- a/SnailTests/FailTests.swift +++ b/SnailTests/FailTests.swift @@ -43,9 +43,9 @@ class FailTests: XCTestCase { } func testFiresStoppedEventOnSubscribe() { - var newError: Error? = nil + var newError: Error? done = nil - + subject?.subscribe( onError: { error in newError = error }, onDone: { self.done = true }