Skip to content

Commit 8c335d8

Browse files
authored
Merge pull request #54 from RxSwiftCommunity/2.0-final
Final 2.0 Release
2 parents b0fb8c9 + 4ab4188 commit 8c335d8

File tree

10 files changed

+86
-44
lines changed

10 files changed

+86
-44
lines changed

Action.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Action"
3-
s.version = "2.0.0-beta.1"
3+
s.version = "2.0.0"
44
s.summary = "Abstracts actions to be performed in RxSwift."
55
s.description = <<-DESC
66
Encapsulates an action to be performed, usually by a UIButton press.
@@ -21,8 +21,8 @@ Pod::Spec.new do |s|
2121
s.source_files = "*.{swift}"
2222

2323
s.frameworks = "Foundation"
24-
s.dependency "RxSwift"
25-
s.dependency "RxCocoa"
24+
s.dependency "RxSwift", "~> 3.0"
25+
s.dependency "RxCocoa", "~> 3.0"
2626

2727
s.watchos.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"
2828
s.osx.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "ReactiveX/RxSwift" "3.0.0-rc.1"
1+
github "ReactiveX/RxSwift" ~> 3.0.0

Cartfile.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
github "Quick/Nimble" "v5.0.0"
1+
github "Quick/Nimble" "v5.1.0"
22
github "Quick/Quick" "v0.10.0"
3-
github "ReactiveX/RxSwift" "3.0.0-rc.1"
3+
github "ReactiveX/RxSwift" "3.0.0"

Carthage/Checkouts/Nimble

Submodule Nimble updated 58 files

Carthage/Checkouts/RxSwift

Submodule RxSwift updated 321 files

Tests/Action/ActionTests.swift

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ class ActionTests: QuickSpec {
7373
let subject = errorSubject()
7474
var errored = false
7575

76-
subject
77-
.execute()
78-
.subscribe(onError: { _ in
79-
errored = true
80-
})
81-
.addDisposableTo(disposeBag)
76+
waitUntil { done in
77+
subject
78+
.execute()
79+
.subscribe(onError: { _ in
80+
errored = true
81+
done()
82+
})
83+
.addDisposableTo(disposeBag)
84+
}
8285

8386
expect(errored) == true
8487
}
@@ -148,9 +151,17 @@ class ActionTests: QuickSpec {
148151
})
149152
.addDisposableTo(disposeBag)
150153

151-
subject.execute()
154+
waitUntil { done in
155+
subject
156+
.execute()
157+
.subscribe(onCompleted: {
158+
done()
159+
})
160+
.addDisposableTo(disposeBag)
161+
}
152162

153-
expect(elements) == [true, false]
163+
164+
expect(elements).toEventually( equal([true, false]) )
154165
}
155166

156167
sharedExamples("sending elements") { (context: @escaping SharedExampleContext) -> Void in
@@ -196,9 +207,11 @@ class ActionTests: QuickSpec {
196207
let subject = testSubject(testItems)
197208
var receivedElements: [String] = []
198209

199-
subject.execute().subscribe(onNext: { (element) -> Void in
200-
receivedElements += [element]
201-
}).addDisposableTo(disposeBag)
210+
waitUntil { done in
211+
subject.execute().subscribe(onNext: { (element) -> Void in
212+
receivedElements += [element]
213+
}, onCompleted: done).addDisposableTo(disposeBag)
214+
}
202215

203216
expect(receivedElements) == testItems
204217
}
@@ -232,12 +245,15 @@ class ActionTests: QuickSpec {
232245
let subject = emptySubject()
233246
var completed = false
234247

235-
subject
236-
.execute()
237-
.subscribe(onCompleted: {
238-
completed = true
239-
})
240-
.addDisposableTo(disposeBag)
248+
waitUntil { done in
249+
subject
250+
.execute()
251+
.subscribe(onCompleted: {
252+
completed = true
253+
done()
254+
})
255+
.addDisposableTo(disposeBag)
256+
}
241257

242258
expect(completed) == true
243259
}
@@ -249,7 +265,13 @@ class ActionTests: QuickSpec {
249265
return .empty()
250266
})
251267

252-
subject.execute()
268+
waitUntil { done in
269+
subject.execute()
270+
.subscribe(onCompleted: {
271+
done()
272+
})
273+
.addDisposableTo(disposeBag)
274+
}
253275

254276
expect(invocations) == 1
255277
}
@@ -281,13 +303,23 @@ class ActionTests: QuickSpec {
281303

282304
executer.execute(subject)
283305

284-
var enabled = try! subject.enabled.toBlocking().first()
285-
expect(enabled) == false
306+
expect(try! subject.enabled.toBlocking().first()).toEventually( beFalse() )
307+
}
308+
309+
it("is externally re-enabled after executing") {
310+
var observer: AnyObserver<Void>!
311+
let subject = Action<Void, Void>(workFactory: { _ in
312+
return Observable.create { (obsv) -> Disposable in
313+
observer = obsv
314+
return Disposables.create()
315+
}
316+
})
317+
318+
executer.execute(subject)
286319

287320
observer.onCompleted()
288321

289-
enabled = try! subject.enabled.toBlocking().first()
290-
expect(enabled) == true
322+
expect(try! subject.enabled.toBlocking().first()).toEventually( beTrue() )
291323
}
292324
}
293325

Tests/Action/BarButtonTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class BarButtonTests: QuickSpec {
4646
var subject = UIBarButtonItem(barButtonSystemItem: .save, target: nil, action: nil)
4747

4848
subject.rx.action = emptyAction(.just(false))
49+
expect(subject.target).toEventuallyNot( beNil() )
4950

5051
expect(subject.isEnabled) == false
5152
}
@@ -73,7 +74,9 @@ class BarButtonTests: QuickSpec {
7374
return .empty()
7475
})
7576
subject.rx.action = action
76-
77+
// Setting the action has the asynchronous effect of adding a target.
78+
expect(subject.target).toEventuallyNot( beNil() )
79+
7780
_ = subject.target?.perform(subject.action, with: subject)
7881

7982
expect(executed) == true

Tests/Action/ButtonTests.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ButtonTests: QuickSpec {
4646
var subject = UIButton(type: .system)
4747

4848
subject.rx.action = emptyAction(.just(false))
49+
expect(subject.allTargets).toEventuallyNot( beEmpty() )
4950

5051
expect(subject.isEnabled) == false
5152
}
@@ -74,14 +75,17 @@ class ButtonTests: QuickSpec {
7475
})
7576
subject.rx.action = action
7677

78+
// Setting the action has an asynchronous effect of adding a target.
79+
expect(subject.allTargets).toEventuallyNot( beEmpty() )
80+
7781
// Normally I'd use subject.sendActionsForControlEvents(.TouchUpInside) but it's not working
7882
for case let target as NSObject in subject.allTargets {
7983
for action in subject.actions(forTarget: target, forControlEvent: .touchUpInside) ?? [] {
8084
target.perform(Selector(action), with: subject)
8185
}
8286
}
8387

84-
expect(executed) == true
88+
expect(executed).toEventually( beTrue() )
8589
}
8690

8791
it("disposes of old action subscriptions when re-set") {
@@ -110,19 +114,22 @@ class ButtonTests: QuickSpec {
110114
it("cancels the observable if the button is deallocated") {
111115

112116
var disposed = false
113-
114-
autoreleasepool {
115-
var subject = UIButton(type: .system)
116-
let action = CocoaAction {
117-
return Observable.create {_ in
118-
Disposables.create {
119-
disposed = true
117+
118+
waitUntil { done in
119+
autoreleasepool {
120+
var subject = UIButton(type: .system)
121+
let action = CocoaAction {
122+
return Observable.create {_ in
123+
Disposables.create {
124+
disposed = true
125+
done()
126+
}
120127
}
121128
}
129+
130+
subject.rx.action = action
131+
subject.rx.action?.execute()
122132
}
123-
124-
subject.rx.action = action
125-
subject.rx.action?.execute()
126133
}
127134

128135
expect(disposed) == true

UIBarButtonItem+Action.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public extension Reactive where Base: UIBarButtonItem {
2929
if let action = newValue {
3030
action
3131
.enabled
32-
.bindTo(self.enabled)
32+
.bindTo(self.isEnabled)
3333
.addDisposableTo(self.base.actionDisposeBag)
3434

3535
self.tap.subscribe(onNext: { (_) in

UIButton+Rx.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public extension Reactive where Base: UIButton {
2828
if let action = newValue {
2929
action
3030
.enabled
31-
.bindTo(self.enabled)
31+
.bindTo(self.isEnabled)
3232
.addDisposableTo(self.base.actionDisposeBag)
3333

3434
// Technically, this file is only included on tv/iOS platforms,

0 commit comments

Comments
 (0)