-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d05eaa
commit 63605de
Showing
4 changed files
with
112 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// BaseTestCase.swift | ||
// BaseTestCase | ||
// | ||
// Created by 장재훈 on 2023/01/09. | ||
// | ||
|
||
import XCTest | ||
|
||
class BaseTestCase: XCTestCase { | ||
func given(_ task: () -> Void) { | ||
task() | ||
} | ||
|
||
func when(_ task: () -> Void) { | ||
task() | ||
} | ||
|
||
func then(_ task: () -> Void) { | ||
task() | ||
} | ||
} |
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,56 @@ | ||
// | ||
// RxTestCase.swift | ||
// SpaceCapsuleTests | ||
// | ||
// Created by 장재훈 on 2023/01/09. | ||
// | ||
|
||
import RxCocoa | ||
import RxRelay | ||
import RxSwift | ||
import RxTest | ||
import XCTest | ||
|
||
class RxTestCase<T>: BaseTestCase { | ||
var scheduler: TestScheduler! | ||
var disposeBag: DisposeBag! | ||
private var resultObserver: TestableObserver<T>! | ||
|
||
var eventsToObserve: Observable<T> = .empty() { | ||
didSet { | ||
disposeBag = DisposeBag() | ||
scheduler = TestScheduler(initialClock: 0) | ||
resultObserver = scheduler.createObserver(T.self) | ||
|
||
eventsToObserve | ||
.bind(to: resultObserver) | ||
.disposed(by: disposeBag) | ||
} | ||
} | ||
|
||
func when(observing events: Observable<T>, _ task: () -> Void) { | ||
eventsToObserve = events | ||
task() | ||
executeEvents() | ||
} | ||
|
||
func createEvents<U>(_ events: [Recorded<Event<U>>], to relay: PublishRelay<U>) { | ||
scheduler | ||
.createHotObservable(events) | ||
.bind(to: relay) | ||
.disposed(by: disposeBag) | ||
} | ||
|
||
func createEvents<U>(_ events: [Recorded<Event<U>>], to subject: PublishSubject<U>) { | ||
scheduler | ||
.createHotObservable(events) | ||
.bind(to: subject) | ||
.disposed(by: disposeBag) | ||
} | ||
|
||
func executeEvents(advanceTo futureTime: VirtualTimeScheduler<TestSchedulerVirtualTimeConverter>.VirtualTime = 10) { | ||
scheduler.start() | ||
scheduler.advanceTo(futureTime) | ||
scheduler.stop() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.