Skip to content

Commit 36fddef

Browse files
committed
Add 4 first unit-tests for Routers and Interactors.
Summary: Now that we have protocol mocks, we can instantiate RootRouter, RootInteractor, SplashRouter, SplashInteractor by providing them with "fake" (mock) dependencies, instead of actual objects. I.e., to instantuate `RootRouter` object in a unit-test, we provide it with mock implementations of `interactor: RootInteractable`, `viewController: RootViewControllable` and `splashBuilder: SplashBuildable` objects, so that we can test side-effects easily. There is one unsolved problem still: base RIB's protocols aren't annotated with `/// sourcery: ` annotations, and the mock generator did not generate them for us. These are required to be able to instantiate instances of *mock* classes, e.g., `RootRoutingMock` - it requires `interactable: Interactable` and `viewControllable: ViewControllable` objects to be passed in its initializer. We'll handle this in the next commit.
1 parent 0a3e73b commit 36fddef

File tree

4 files changed

+70
-21
lines changed

4 files changed

+70
-21
lines changed

Tutorial_RIBs_CodeGenerationTests/Root/RootInteractorSpec.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,32 @@ import RIBs
1313

1414
class RootInteractorSpec: TestSpec {
1515
override func spec() {
16-
/*
17-
var presenter: RootPresentable!
16+
var presenter: RootPresentableMock!
1817
var sut: RootInteractor!
18+
//var router: RootRoutingMock!
1919
beforeEach {
20-
//presenter = RootPresentable
20+
presenter = RootPresentableMock()
2121
sut = RootInteractor(presenter: presenter)
22+
23+
// router = RootRoutingMock(interactable: <#T##Interactable#>, viewControllable: <#T##ViewControllable#>) // TODO: same here.
24+
// sut.router = router
2225
}
23-
*/
26+
27+
// MARK: - init()
28+
describe("init()") {
29+
it("sets presenter.listener to self") {
30+
expect(presenter.listener) === sut
31+
}
32+
} // describe("init()")
33+
34+
// // MARK: - didBecomeActive()
35+
// describe("didBecomeActive()") {
36+
// beforeEach {
37+
// sut.activate()
38+
// }
39+
// it("calls router.routeToSplash()") {
40+
// expect(router.routeToSplashCallCount) == 1
41+
// }
42+
// } // describe("didBecomeActive()")
2443
}
2544
}

Tutorial_RIBs_CodeGenerationTests/Root/RootRouterSpec.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,35 @@ import RIBs
1313

1414
class RootRouterSpec: TestSpec {
1515
override func spec() {
16-
/*
17-
var interactor: RootInteractable!
18-
var viewController: RootViewControllable!
19-
var splashBuilder: SplashBuildable!
16+
var interactor: RootInteractableMock!
17+
var viewController: RootViewControllableMock!
18+
var splashBuilder: SplashBuildableMock!
2019
var sut: RootRouter!
2120
beforeEach {
22-
//interactor = ???
23-
//viewController = ???
24-
//splashBuilder = ???
21+
interactor = RootInteractableMock()
22+
viewController = RootViewControllableMock(uiviewController: UIViewController())
23+
splashBuilder = SplashBuildableMock()
2524
sut = RootRouter(interactor: interactor,
2625
viewController: viewController,
2726
splashBuilder: splashBuilder)
2827
}
29-
*/
28+
29+
// MARK: - init()
30+
describe("init()") {
31+
it("sets interactor.router to self") {
32+
expect(interactor.router) === sut
33+
}
34+
} // describe("init()")
35+
36+
// MARK: - routeToSplash()
37+
describe("routeToSplash()") {
38+
// var splashRouter: SplashRoutingMock!
39+
// beforeEach {
40+
// splashBuilder.buildHandler = { (_ listener: SplashListener) -> (SplashRouting) in
41+
// splashRouter = SplashRoutingMock(interactable: <#T##Interactable#>, viewControllable: <#T##ViewControllable#>) // TODO: Oops, need mocks for base RIBs' protocols (`Interactable`, `ViewControllable`), but we can't annotate them (yet). Will solve that in the next commit.
42+
// return splashRouter
43+
// }
44+
// }
45+
} // describe("routeToSplash()")
3046
}
3147
}

Tutorial_RIBs_CodeGenerationTests/Splash/SplashInteractorSpec.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ import RIBs
1313

1414
class SplashInteractorSpec: TestSpec {
1515
override func spec() {
16-
/*
17-
var presenter: SplashPresentable!
16+
var presenter: SplashPresentableMock!
1817
var sut: SplashInteractor!
1918
beforeEach {
19+
presenter = SplashPresentableMock()
2020
sut = SplashInteractor(presenter: presenter)
2121
}
22-
*/
22+
23+
// MARK: - init()
24+
describe("init()") {
25+
it("sets presenter.listener to self") {
26+
expect(presenter.listener) === sut
27+
}
28+
} // describe("init()")
29+
2330
}
2431
}

Tutorial_RIBs_CodeGenerationTests/Splash/SplashRouterSpec.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ import RIBs
1313

1414
class SplashRouterSpec: TestSpec {
1515
override func spec() {
16-
/*
17-
var interactor: SplashInteractable!
18-
var viewController: SplashViewControllable!
16+
var interactor: SplashInteractableMock!
17+
var viewController: SplashViewControllableMock!
1918
var sut: SplashRouter!
2019
beforeEach {
21-
sut = SplashRouter(interactor: <#T##SplashInteractable#>,
22-
viewController: <#T##SplashViewControllable#>)
20+
interactor = SplashInteractableMock()
21+
viewController = SplashViewControllableMock(uiviewController: UIViewController())
22+
sut = SplashRouter(interactor: interactor,
23+
viewController: viewController)
2324
}
24-
*/
25+
26+
// MARK: - init()
27+
describe("init()") {
28+
it("sets interactor.router to self") {
29+
expect(interactor.router) === sut
30+
}
31+
} // describe("init()")
2532
}
2633
}

0 commit comments

Comments
 (0)