-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from larryonoff/feature/extend-action
Add completed and started signals to Action
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// ActionTests.swift | ||
// Rex | ||
// | ||
// Created by Ilya Laryionau on 4/20/16. | ||
// Copyright © 2016 Neil Pankey. All rights reserved. | ||
// | ||
|
||
@testable import Rex | ||
import ReactiveCocoa | ||
import XCTest | ||
import enum Result.NoError | ||
|
||
final class ActionTests: XCTestCase { | ||
|
||
enum TestError: ErrorType { | ||
case Unknown | ||
} | ||
|
||
func testStarted() { | ||
let action = Action<Void, Void, NoError> { .empty } | ||
|
||
var started = false | ||
action | ||
.rex_started | ||
.observeNext { started = true } | ||
|
||
action | ||
.apply() | ||
.start() | ||
|
||
XCTAssertTrue(started) | ||
} | ||
|
||
func testCompleted() { | ||
let (producer, observer) = SignalProducer<Int, TestError>.buffer(Int.max) | ||
let action = Action { producer } | ||
|
||
var completed = false | ||
action | ||
.rex_completed | ||
.observeNext { completed = true } | ||
|
||
action | ||
.apply() | ||
.start() | ||
|
||
observer.sendNext(1) | ||
XCTAssertFalse(completed) | ||
|
||
observer.sendCompleted() | ||
XCTAssertTrue(completed) | ||
} | ||
|
||
func testCompletedOnFailed() { | ||
let (producer, observer) = SignalProducer<Int, TestError>.buffer(Int.max) | ||
let action = Action { producer } | ||
|
||
var completed = false | ||
action | ||
.rex_completed | ||
.observeNext { completed = true } | ||
|
||
action | ||
.apply() | ||
.start() | ||
|
||
observer.sendFailed(.Unknown) | ||
XCTAssertFalse(completed) | ||
} | ||
} |