Skip to content

Commit 57b7081

Browse files
committed
Resolve all issues in Tests and Demo
1 parent 0fd6c4c commit 57b7081

File tree

5 files changed

+90
-88
lines changed

5 files changed

+90
-88
lines changed

Demo/ViewController.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class ViewController: UIViewController {
2828
[weak self] observer -> Disposable in
2929

3030
// Demo: show an alert and complete the view's button action once the alert's OK button is pressed
31-
let alertController = UIAlertController(title: "Hello world", message: "This alert was triggered by a button action", preferredStyle: .Alert)
32-
let ok = UIAlertAction.Action("OK", style: .Default)
31+
let alertController = UIAlertController(title: "Hello world", message: "This alert was triggered by a button action", preferredStyle: .alert)
32+
let ok = UIAlertAction.Action("OK", style: .default)
3333
ok.rx_action = CocoaAction {
3434
print("Alert's OK button was pressed")
3535
observer.onCompleted()
3636
return .empty()
3737
}
3838
alertController.addAction(ok)
39-
self!.presentViewController(alertController, animated: true, completion: nil)
39+
self!.present(alertController, animated: true, completion: nil)
4040

41-
return NopDisposable.instance
41+
return Disposables.create()
4242
}
4343
}
4444
button.rx_action = action
@@ -59,17 +59,18 @@ class ViewController: UIViewController {
5959
return a || b
6060
}
6161
.distinctUntilChanged()
62-
.subscribeNext {
62+
.subscribe(onNext: {
6363
// every time the execution status changes, spin an activity indicator
6464
[weak self] executing in
65-
self?.workingLabel.hidden = !executing
65+
self?.workingLabel.isHidden = !executing
6666
if (executing) {
6767
self?.activityIndicator.startAnimating()
6868
}
6969
else {
7070
self?.activityIndicator.stopAnimating()
7171
}
72-
}
72+
})
73+
7374
.addDisposableTo(self.disposableBag)
7475
}
7576
}

Tests/Action/ActionTests.swift

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ActionTests: QuickSpec {
1616
let subject = errorSubject()
1717
var receivedError: ActionError?
1818

19-
subject.errors.subscribeNext({ (value) -> Void in
19+
subject.errors.subscribe(onNext: { (value) -> Void in
2020
receivedError = value
2121
}).addDisposableTo(disposeBag)
2222

@@ -29,7 +29,7 @@ class ActionTests: QuickSpec {
2929
let subject = errorSubject()
3030
var error: ActionError?
3131

32-
subject.errors.subscribeNext({ (value) -> Void in
32+
subject.errors.subscribe(onNext: { (value) -> Void in
3333
error = value
3434
}).addDisposableTo(disposeBag)
3535

@@ -39,7 +39,7 @@ class ActionTests: QuickSpec {
3939
fail("received error is nil."); return
4040
}
4141

42-
if case ActionError.UnderlyingError = receivedError {
42+
if case ActionError.underlyingError = receivedError {
4343
// Nop
4444
} else {
4545
fail("Incorrect error type.")
@@ -50,7 +50,7 @@ class ActionTests: QuickSpec {
5050
let subject = errorSubject()
5151
var error: ActionError?
5252

53-
subject.errors.subscribeNext({ (value) -> Void in
53+
subject.errors.subscribe(onNext: { (value) -> Void in
5454
error = value
5555
}).addDisposableTo(disposeBag)
5656

@@ -60,7 +60,7 @@ class ActionTests: QuickSpec {
6060
fail("received error is nil."); return
6161
}
6262

63-
if case ActionError.UnderlyingError(let e) = receivedError {
63+
if case ActionError.underlyingError(let e) = receivedError {
6464
if let e = e as? String {
6565
expect(e) == TestError
6666
} else {
@@ -75,9 +75,9 @@ class ActionTests: QuickSpec {
7575

7676
subject
7777
.execute()
78-
.subscribeError{ _ in
78+
.subscribe(onError: { _ in
7979
errored = true
80-
}
80+
})
8181
.addDisposableTo(disposeBag)
8282

8383
expect(errored) == true
@@ -89,9 +89,9 @@ class ActionTests: QuickSpec {
8989

9090
subject
9191
.elements
92-
.subscribeError{ _ in
92+
.subscribe(onError: { _ in
9393
errored = true
94-
}
94+
})
9595
.addDisposableTo(disposeBag)
9696

9797
subject.execute()
@@ -106,9 +106,9 @@ class ActionTests: QuickSpec {
106106

107107
subject
108108
.errors
109-
.subscribeError{ _ in
109+
.subscribe(onError: { _ in
110110
errored = true
111-
}
111+
})
112112
.addDisposableTo(disposeBag)
113113

114114
subject.execute()
@@ -121,7 +121,7 @@ class ActionTests: QuickSpec {
121121
var receivedInput: String?
122122
let subject = Action<String, Void>(workFactory: { (input) in
123123
receivedInput = input
124-
return .just()
124+
return .just(())
125125
})
126126

127127
subject.execute(testInput)
@@ -143,17 +143,17 @@ class ActionTests: QuickSpec {
143143
subject
144144
.executing
145145
.skip(1) // Skips initial value
146-
.subscribeNext { value -> Void in
146+
.subscribe(onNext: { value -> Void in
147147
elements += [value]
148-
}
148+
})
149149
.addDisposableTo(disposeBag)
150150

151151
subject.execute()
152152

153153
expect(elements) == [true, false]
154154
}
155155

156-
sharedExamples("sending elements") { (context: QCKDSLSharedExampleContext!) -> Void in
156+
sharedExamples("sending elements") { (context: @escaping SharedExampleContext) -> Void in
157157
var testItems: [String]!
158158

159159
beforeEach {
@@ -164,14 +164,14 @@ class ActionTests: QuickSpec {
164164
let subject = testSubject(testItems)
165165

166166
var receivedInputs: [Void] = []
167-
subject.inputs.subscribeNext { (input) -> Void in
167+
subject.inputs.subscribe(onNext: { (input) -> Void in
168168
receivedInputs += [input]
169-
}.addDisposableTo(disposeBag)
169+
}).addDisposableTo(disposeBag)
170170

171171
var receivedElements: [String] = []
172-
subject.elements.subscribeNext { (element) -> Void in
172+
subject.elements.subscribe(onNext: { (element) -> Void in
173173
receivedElements += [element]
174-
}.addDisposableTo(disposeBag)
174+
}).addDisposableTo(disposeBag)
175175

176176
subject.execute()
177177

@@ -183,9 +183,9 @@ class ActionTests: QuickSpec {
183183
let subject = testSubject(testItems)
184184
var receivedElements: [String] = []
185185

186-
subject.elements.subscribeNext { (element) -> Void in
186+
subject.elements.subscribe(onNext: { (element) -> Void in
187187
receivedElements += [element]
188-
}.addDisposableTo(disposeBag)
188+
}).addDisposableTo(disposeBag)
189189

190190
subject.inputs.onNext()
191191

@@ -196,9 +196,9 @@ class ActionTests: QuickSpec {
196196
let subject = testSubject(testItems)
197197
var receivedElements: [String] = []
198198

199-
subject.execute().subscribeNext { (element) -> Void in
199+
subject.execute().subscribe(onNext: { (element) -> Void in
200200
receivedElements += [element]
201-
}.addDisposableTo(disposeBag)
201+
}).addDisposableTo(disposeBag)
202202

203203
expect(receivedElements) == testItems
204204
}
@@ -210,7 +210,7 @@ class ActionTests: QuickSpec {
210210

211211
subject
212212
.execute()
213-
.subscribeNext({ (string) in
213+
.subscribe(onNext: { (string) in
214214
expect(string) == TestElement
215215
}).addDisposableTo(disposeBag)
216216
})
@@ -234,9 +234,9 @@ class ActionTests: QuickSpec {
234234

235235
subject
236236
.execute()
237-
.subscribeCompleted {
237+
.subscribe(onCompleted: {
238238
completed = true
239-
}
239+
})
240240
.addDisposableTo(disposeBag)
241241

242242
expect(completed) == true
@@ -254,7 +254,8 @@ class ActionTests: QuickSpec {
254254
expect(invocations) == 1
255255
}
256256

257-
sharedExamples("triggering execution") { (context: QCKDSLSharedExampleContext!) -> Void in
257+
258+
sharedExamples("triggering execution") { (context: @escaping SharedExampleContext) -> Void in
258259
var executer: TestActionExecuter!
259260

260261
beforeEach {
@@ -274,7 +275,7 @@ class ActionTests: QuickSpec {
274275
let subject = Action<Void, Void>(workFactory: { _ in
275276
return Observable.create { (obsv) -> Disposable in
276277
observer = obsv
277-
return NopDisposable.instance
278+
return Disposables.create()
278279
}
279280
})
280281

@@ -309,9 +310,9 @@ class ActionTests: QuickSpec {
309310

310311
subject
311312
.errors
312-
.subscribeNext { error in
313+
.subscribe(onNext: { error in
313314
receivedError = error
314-
}
315+
})
315316
.addDisposableTo(disposeBag)
316317

317318
executer.execute(subject)
@@ -328,9 +329,9 @@ class ActionTests: QuickSpec {
328329

329330
subject
330331
.errors
331-
.subscribeNext { error in
332+
.subscribe(onNext: { error in
332333
receivedError = error
333-
}
334+
})
334335
.addDisposableTo(disposeBag)
335336

336337
executer.execute(subject)
@@ -339,7 +340,7 @@ class ActionTests: QuickSpec {
339340
fail("Error is nil"); return
340341
}
341342

342-
if case ActionError.NotEnabled = error {
343+
if case ActionError.notEnabled = error {
343344
// Nop
344345
} else {
345346
fail("Incorrect error returned.")
@@ -383,7 +384,7 @@ let TestError = "Test Error"
383384
func errorObservable() -> Observable<Void> {
384385
return .create({ (observer) -> Disposable in
385386
observer.onError(TestError)
386-
return NopDisposable.instance
387+
return Disposables.create()
387388
})
388389
}
389390

@@ -404,7 +405,7 @@ func testExecutionObservablesSubject() -> Action<Void, String> {
404405
return Observable.create({ (observer) -> Disposable in
405406
observer.onNext(TestElement)
406407
observer.onCompleted()
407-
return NopDisposable.instance
408+
return Disposables.create()
408409
})
409410
})
410411
}
@@ -414,14 +415,14 @@ let TestElement = "Hi there"
414415

415416
func testSubject(_ elements: [String]) -> Action<Void, String> {
416417
return Action(workFactory: { input in
417-
return elements.toObservable()
418+
return Observable.from(elements)
418419
})
419420
}
420421

421422
class TestActionExecuter {
422423
let execute: (Action<Void, Void>) -> Void
423424

424-
init(execute: (Action<Void, Void>) -> Void) {
425+
init(execute: @escaping (Action<Void, Void>) -> Void) {
425426
self.execute = execute
426427
}
427428
}

Tests/Action/AlertActionTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import Action
77
class AlertActionTests: QuickSpec {
88
override func spec() {
99
it("is nil by default") {
10-
let subject = UIAlertAction.Action("Hi", style: .Default)
10+
let subject = UIAlertAction.Action("Hi", style: .default)
1111
expect(subject.rx_action).to( beNil() )
1212
}
1313

1414
it("respects setter") {
15-
let subject = UIAlertAction.Action("Hi", style: .Default)
15+
let subject = UIAlertAction.Action("Hi", style: .default)
1616

1717
let action = emptyAction()
1818

@@ -22,44 +22,44 @@ class AlertActionTests: QuickSpec {
2222
}
2323

2424
it("disables the alert action while executing") {
25-
let subject = UIAlertAction.Action("Hi", style: .Default)
25+
let subject = UIAlertAction.Action("Hi", style: .default)
2626

2727
var observer: AnyObserver<Void>!
2828
let action = CocoaAction(workFactory: { _ in
2929
return Observable.create { (obsv) -> Disposable in
3030
observer = obsv
31-
return NopDisposable.instance
31+
return Disposables.create()
3232
}
3333
})
3434

3535
subject.rx_action = action
3636

3737
action.execute()
38-
expect(subject.enabled).toEventually( beFalse() )
38+
expect(subject.isEnabled).toEventually( beFalse() )
3939

4040
observer.onCompleted()
41-
expect(subject.enabled).toEventually( beTrue() )
41+
expect(subject.isEnabled).toEventually( beTrue() )
4242
}
4343

4444
it("disables the alert action if the Action is disabled") {
45-
let subject = UIAlertAction.Action("Hi", style: .Default)
45+
let subject = UIAlertAction.Action("Hi", style: .default)
4646
let disposeBag = DisposeBag()
4747

4848
subject.rx_action = emptyAction(.just(false))
4949
waitUntil { done in
50-
subject.rx_observe(Bool.self, "enabled")
50+
subject.rx.observe(Bool.self, "enabled")
5151
.take(1)
52-
.subscribeNext { _ in
52+
.subscribe(onNext: { _ in
5353
done()
54-
}
54+
})
5555
.addDisposableTo(disposeBag)
5656
}
5757

58-
expect(subject.enabled) == false
58+
expect(subject.isEnabled) == false
5959
}
6060

6161
it("disposes of old action subscriptions when re-set") {
62-
let subject = UIAlertAction.Action("Hi", style: .Default)
62+
let subject = UIAlertAction.Action("Hi", style: .default)
6363

6464
var disposed = false
6565
autoreleasepool {
@@ -81,4 +81,4 @@ class AlertActionTests: QuickSpec {
8181
expect(disposed) == true
8282
}
8383
}
84-
}
84+
}

0 commit comments

Comments
 (0)