From 295ba56d965d5d3a427d3e663ca09129a4d16978 Mon Sep 17 00:00:00 2001 From: Marcelo Gobetti Date: Sun, 21 Oct 2018 21:57:00 -0300 Subject: [PATCH] Added support to RxTest as an alternative to RxBlocking Users of RxNimble may now opt between RxBlocking and RxTest (mutually or exclusively). In order to keep compability with previous versions, the `default_subspec` is "RxBlocking", but "RxNimble/RxTest" can be added to clients' Podfiles, or replace "RxNimble" entirely in order to remove the dependency on `RxBlocking`. --- Demo/Podfile.lock | 10 +++++--- RxNimble.podspec | 25 +++++++++++++++---- Source/{ => Core}/Expectation+Ext.swift | 0 .../Expectation+Blocking.swift | 0 Source/{ => RxBlocking}/RxNimble.swift | 0 Source/RxTest/Equal+RxTest.swift | 16 ++++++++++++ Source/RxTest/Expectation+RxTest.swift | 22 ++++++++++++++++ 7 files changed, 65 insertions(+), 8 deletions(-) rename Source/{ => Core}/Expectation+Ext.swift (100%) rename Source/{ => RxBlocking}/Expectation+Blocking.swift (100%) rename Source/{ => RxBlocking}/RxNimble.swift (100%) create mode 100644 Source/RxTest/Equal+RxTest.swift create mode 100644 Source/RxTest/Expectation+RxTest.swift diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 30827b9..4401694 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -3,10 +3,14 @@ PODS: - Quick (1.3.2) - RxBlocking (4.3.1): - RxSwift (~> 4.0) - - RxNimble (4.2.0): + - RxNimble (4.4.0): + - RxNimble/RxBlocking (= 4.4.0) + - RxNimble/Core (4.4.0): - Nimble (~> 7.0) - - RxBlocking (~> 4.0) - RxSwift (~> 4.2) + - RxNimble/RxBlocking (4.4.0): + - RxBlocking + - RxNimble/Core - RxSwift (4.3.1) DEPENDENCIES: @@ -29,7 +33,7 @@ SPEC CHECKSUMS: Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae Quick: 2623cb30d7a7f41ca62f684f679586558f483d46 RxBlocking: 64c051285261ca2339481e91b5f70eb06b03660a - RxNimble: cb8c3dd1ca79b83c60744f1c327130c1aef202a1 + RxNimble: 170cdfa19fb020c25608760961fd35053f2a2646 RxSwift: fe0fd770a43acdb7d0a53da411c9b892e69bb6e4 PODFILE CHECKSUM: 7405369509db0cbd242146add66181ab5ab0efb0 diff --git a/RxNimble.podspec b/RxNimble.podspec index 340b4fb..31f35aa 100644 --- a/RxNimble.podspec +++ b/RxNimble.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxNimble" - s.version = "4.3.0" + s.version = "4.4.0" s.summary = "Nimble extensions that making unit testing with RxSwift easier 🎉" s.description = <<-DESC This library includes functions that make testing RxSwift projects easier with Nimble. @@ -13,10 +13,25 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.10" s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/RxSwiftCommunity/RxNimble.git", :tag => s.version } - s.source_files = "Source/**/*.swift" - s.dependency "Nimble", "~> 7.0" - s.dependency "RxSwift", "~> 4.2" - s.dependency "RxBlocking", "~> 4.0" + s.default_subspec = "RxBlocking" s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO', 'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"' } + + s.subspec "Core" do |ss| + ss.source_files = "Source/Core/" + ss.dependency "Nimble", "~> 7.0" + ss.dependency "RxSwift", "~> 4.2" + end + + s.subspec "RxBlocking" do |ss| + ss.source_files = "Source/RxBlocking/" + ss.dependency "RxNimble/Core" + ss.dependency "RxBlocking" + end + + s.subspec "RxTest" do |ss| + ss.source_files = "Source/RxTest/" + ss.dependency "RxNimble/Core" + ss.dependency "RxTest" + end end diff --git a/Source/Expectation+Ext.swift b/Source/Core/Expectation+Ext.swift similarity index 100% rename from Source/Expectation+Ext.swift rename to Source/Core/Expectation+Ext.swift diff --git a/Source/Expectation+Blocking.swift b/Source/RxBlocking/Expectation+Blocking.swift similarity index 100% rename from Source/Expectation+Blocking.swift rename to Source/RxBlocking/Expectation+Blocking.swift diff --git a/Source/RxNimble.swift b/Source/RxBlocking/RxNimble.swift similarity index 100% rename from Source/RxNimble.swift rename to Source/RxBlocking/RxNimble.swift diff --git a/Source/RxTest/Equal+RxTest.swift b/Source/RxTest/Equal+RxTest.swift new file mode 100644 index 0000000..64fb2e7 --- /dev/null +++ b/Source/RxTest/Equal+RxTest.swift @@ -0,0 +1,16 @@ +import Nimble +import RxSwift +@testable import RxTest + +public func equal(_ expectedEvents: RecordedEvents) -> Predicate> { + return Predicate.define { actualEvents in + let actualEquatableEvents = try actualEvents.evaluate()?.map { AnyEquatable(target: $0, comparer: ==) } + let expectedEquatableEvents = expectedEvents.map { AnyEquatable(target: $0, comparer: ==) } + + let matches = (actualEquatableEvents == expectedEquatableEvents) + return PredicateResult(bool: matches, + message: .expectedActualValueTo( + "emit <\(stringify(expectedEquatableEvents))>") + ) + } +} diff --git a/Source/RxTest/Expectation+RxTest.swift b/Source/RxTest/Expectation+RxTest.swift new file mode 100644 index 0000000..027079a --- /dev/null +++ b/Source/RxTest/Expectation+RxTest.swift @@ -0,0 +1,22 @@ +import Nimble +import RxSwift +import RxTest + +public typealias RecordedEvents = [Recorded>] + +public extension Expectation where T: ObservableType { + func events(scheduler: TestScheduler, + disposeBag: DisposeBag, + startAt initialTime: Int = 0) -> Expectation> { + return transform { source in + let results = scheduler.createObserver(T.E.self) + + scheduler.scheduleAt(initialTime) { + source?.subscribe(results).disposed(by: disposeBag) + } + scheduler.start() + + return results.events + } + } +}