From 96e6c7508c3d21a204a87f91684d7dfe090efc4a Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Mon, 24 Oct 2016 13:51:33 -0400 Subject: [PATCH 1/5] Updated versions. --- Action.podspec | 6 +++--- Cartfile | 2 +- Cartfile.resolved | 4 ++-- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/RxSwift | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Action.podspec b/Action.podspec index 3534689e..b50268a4 100644 --- a/Action.podspec +++ b/Action.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Action" - s.version = "2.0.0-beta.1" + s.version = "2.0.0" s.summary = "Abstracts actions to be performed in RxSwift." s.description = <<-DESC Encapsulates an action to be performed, usually by a UIButton press. @@ -21,8 +21,8 @@ Pod::Spec.new do |s| s.source_files = "*.{swift}" s.frameworks = "Foundation" - s.dependency "RxSwift" - s.dependency "RxCocoa" + s.dependency "RxSwift", "~> 3.0" + s.dependency "RxCocoa", "~> 3.0" s.watchos.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift" s.osx.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift" diff --git a/Cartfile b/Cartfile index 31fdf339..9f2795c5 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveX/RxSwift" "3.0.0-rc.1" +github "ReactiveX/RxSwift" ~> 3.0.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index df314d84..0b446959 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Quick/Nimble" "v5.0.0" +github "Quick/Nimble" "v5.1.0" github "Quick/Quick" "v0.10.0" -github "ReactiveX/RxSwift" "3.0.0-rc.1" +github "ReactiveX/RxSwift" "3.0.0" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 02094196..76c4cb35 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 0209419661b6acceff45cd63984596f2e9eea517 +Subproject commit 76c4cb3567f3492c00e84a1000ba8622355c8323 diff --git a/Carthage/Checkouts/RxSwift b/Carthage/Checkouts/RxSwift index f51c4750..3c55a309 160000 --- a/Carthage/Checkouts/RxSwift +++ b/Carthage/Checkouts/RxSwift @@ -1 +1 @@ -Subproject commit f51c4750103d1746d088ecdf904727989e6ec90b +Subproject commit 3c55a309a24fbe3dbc480431798eec072b633b85 From 94c3e3ccd33276883a07a145c26dfeb9eabd8bfd Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Mon, 24 Oct 2016 13:53:02 -0400 Subject: [PATCH 2/5] Updates for RxSwift 3.0. --- UIBarButtonItem+Action.swift | 2 +- UIButton+Rx.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UIBarButtonItem+Action.swift b/UIBarButtonItem+Action.swift index ca7f4366..639ff86d 100644 --- a/UIBarButtonItem+Action.swift +++ b/UIBarButtonItem+Action.swift @@ -29,7 +29,7 @@ public extension Reactive where Base: UIBarButtonItem { if let action = newValue { action .enabled - .bindTo(self.enabled) + .bindTo(self.isEnabled) .addDisposableTo(self.base.actionDisposeBag) self.tap.subscribe(onNext: { (_) in diff --git a/UIButton+Rx.swift b/UIButton+Rx.swift index fe38e3f9..289f9012 100644 --- a/UIButton+Rx.swift +++ b/UIButton+Rx.swift @@ -28,7 +28,7 @@ public extension Reactive where Base: UIButton { if let action = newValue { action .enabled - .bindTo(self.enabled) + .bindTo(self.isEnabled) .addDisposableTo(self.base.actionDisposeBag) // Technically, this file is only included on tv/iOS platforms, From adb67ffc66a9d410c58f5a60e9d8ad3c67f0189a Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Mon, 24 Oct 2016 16:12:19 -0400 Subject: [PATCH 3/5] Fixes some tests. --- Tests/Action/ActionTests.swift | 62 +++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/Tests/Action/ActionTests.swift b/Tests/Action/ActionTests.swift index 6e959c9a..93cec1bd 100644 --- a/Tests/Action/ActionTests.swift +++ b/Tests/Action/ActionTests.swift @@ -73,12 +73,15 @@ class ActionTests: QuickSpec { let subject = errorSubject() var errored = false - subject - .execute() - .subscribe(onError: { _ in - errored = true - }) - .addDisposableTo(disposeBag) + waitUntil { done in + subject + .execute() + .subscribe(onError: { _ in + errored = true + done() + }) + .addDisposableTo(disposeBag) + } expect(errored) == true } @@ -148,9 +151,17 @@ class ActionTests: QuickSpec { }) .addDisposableTo(disposeBag) - subject.execute() + waitUntil { done in + subject + .execute() + .subscribe(onCompleted: { + done() + }) + .addDisposableTo(disposeBag) + } - expect(elements) == [true, false] + + expect(elements).toEventually( equal([true, false]) ) } sharedExamples("sending elements") { (context: @escaping SharedExampleContext) -> Void in @@ -196,9 +207,11 @@ class ActionTests: QuickSpec { let subject = testSubject(testItems) var receivedElements: [String] = [] - subject.execute().subscribe(onNext: { (element) -> Void in - receivedElements += [element] - }).addDisposableTo(disposeBag) + waitUntil { done in + subject.execute().subscribe(onNext: { (element) -> Void in + receivedElements += [element] + }, onCompleted: done).addDisposableTo(disposeBag) + } expect(receivedElements) == testItems } @@ -232,12 +245,15 @@ class ActionTests: QuickSpec { let subject = emptySubject() var completed = false - subject - .execute() - .subscribe(onCompleted: { - completed = true - }) - .addDisposableTo(disposeBag) + waitUntil { done in + subject + .execute() + .subscribe(onCompleted: { + completed = true + done() + }) + .addDisposableTo(disposeBag) + } expect(completed) == true } @@ -249,7 +265,13 @@ class ActionTests: QuickSpec { return .empty() }) - subject.execute() + waitUntil { done in + subject.execute() + .subscribe(onCompleted: { + done() + }) + .addDisposableTo(disposeBag) + } expect(invocations) == 1 } @@ -282,12 +304,12 @@ class ActionTests: QuickSpec { executer.execute(subject) var enabled = try! subject.enabled.toBlocking().first() - expect(enabled) == false + expect(enabled).toEventually( beFalse() ) observer.onCompleted() enabled = try! subject.enabled.toBlocking().first() - expect(enabled) == true + expect(enabled).toEventually( beTrue() ) } } From 76fec74ac4fb507ce3fba45349783b63ca69c534 Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Mon, 24 Oct 2016 17:04:14 -0400 Subject: [PATCH 4/5] Fixes remaining Action tests. --- Tests/Action/ActionTests.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Tests/Action/ActionTests.swift b/Tests/Action/ActionTests.swift index 93cec1bd..3165fdbb 100644 --- a/Tests/Action/ActionTests.swift +++ b/Tests/Action/ActionTests.swift @@ -303,13 +303,23 @@ class ActionTests: QuickSpec { executer.execute(subject) - var enabled = try! subject.enabled.toBlocking().first() - expect(enabled).toEventually( beFalse() ) + expect(try! subject.enabled.toBlocking().first()).toEventually( beFalse() ) + } + + it("is externally re-enabled after executing") { + var observer: AnyObserver! + let subject = Action(workFactory: { _ in + return Observable.create { (obsv) -> Disposable in + observer = obsv + return Disposables.create() + } + }) + + executer.execute(subject) observer.onCompleted() - enabled = try! subject.enabled.toBlocking().first() - expect(enabled).toEventually( beTrue() ) + expect(try! subject.enabled.toBlocking().first()).toEventually( beTrue() ) } } From 4ab4188f79b2260fc3ad71939f4ac29577957d13 Mon Sep 17 00:00:00 2001 From: Ash Furrow Date: Mon, 24 Oct 2016 17:14:41 -0400 Subject: [PATCH 5/5] Fixes remaining tests. --- Tests/Action/BarButtonTests.swift | 5 ++++- Tests/Action/ButtonTests.swift | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Tests/Action/BarButtonTests.swift b/Tests/Action/BarButtonTests.swift index 91bc28c4..9c8292cc 100644 --- a/Tests/Action/BarButtonTests.swift +++ b/Tests/Action/BarButtonTests.swift @@ -46,6 +46,7 @@ class BarButtonTests: QuickSpec { var subject = UIBarButtonItem(barButtonSystemItem: .save, target: nil, action: nil) subject.rx.action = emptyAction(.just(false)) + expect(subject.target).toEventuallyNot( beNil() ) expect(subject.isEnabled) == false } @@ -73,7 +74,9 @@ class BarButtonTests: QuickSpec { return .empty() }) subject.rx.action = action - + // Setting the action has the asynchronous effect of adding a target. + expect(subject.target).toEventuallyNot( beNil() ) + _ = subject.target?.perform(subject.action, with: subject) expect(executed) == true diff --git a/Tests/Action/ButtonTests.swift b/Tests/Action/ButtonTests.swift index 6a4a2a65..7e82d902 100644 --- a/Tests/Action/ButtonTests.swift +++ b/Tests/Action/ButtonTests.swift @@ -46,6 +46,7 @@ class ButtonTests: QuickSpec { var subject = UIButton(type: .system) subject.rx.action = emptyAction(.just(false)) + expect(subject.allTargets).toEventuallyNot( beEmpty() ) expect(subject.isEnabled) == false } @@ -74,6 +75,9 @@ class ButtonTests: QuickSpec { }) subject.rx.action = action + // Setting the action has an asynchronous effect of adding a target. + expect(subject.allTargets).toEventuallyNot( beEmpty() ) + // Normally I'd use subject.sendActionsForControlEvents(.TouchUpInside) but it's not working for case let target as NSObject in subject.allTargets { for action in subject.actions(forTarget: target, forControlEvent: .touchUpInside) ?? [] { @@ -81,7 +85,7 @@ class ButtonTests: QuickSpec { } } - expect(executed) == true + expect(executed).toEventually( beTrue() ) } it("disposes of old action subscriptions when re-set") { @@ -110,19 +114,22 @@ class ButtonTests: QuickSpec { it("cancels the observable if the button is deallocated") { var disposed = false - - autoreleasepool { - var subject = UIButton(type: .system) - let action = CocoaAction { - return Observable.create {_ in - Disposables.create { - disposed = true + + waitUntil { done in + autoreleasepool { + var subject = UIButton(type: .system) + let action = CocoaAction { + return Observable.create {_ in + Disposables.create { + disposed = true + done() + } } } + + subject.rx.action = action + subject.rx.action?.execute() } - - subject.rx.action = action - subject.rx.action?.execute() } expect(disposed) == true