Skip to content

Commit

Permalink
Added support to RxTest as an alternative to RxBlocking
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
gobetti committed Oct 22, 2018
1 parent dfc2868 commit 295ba56
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
10 changes: 7 additions & 3 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,7 +33,7 @@ SPEC CHECKSUMS:
Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae
Quick: 2623cb30d7a7f41ca62f684f679586558f483d46
RxBlocking: 64c051285261ca2339481e91b5f70eb06b03660a
RxNimble: cb8c3dd1ca79b83c60744f1c327130c1aef202a1
RxNimble: 170cdfa19fb020c25608760961fd35053f2a2646
RxSwift: fe0fd770a43acdb7d0a53da411c9b892e69bb6e4

PODFILE CHECKSUM: 7405369509db0cbd242146add66181ab5ab0efb0
Expand Down
25 changes: 20 additions & 5 deletions RxNimble.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions Source/RxTest/Equal+RxTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Nimble
import RxSwift
@testable import RxTest

public func equal<T: Equatable>(_ expectedEvents: RecordedEvents<T>) -> Predicate<RecordedEvents<T>> {
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))>")
)
}
}
22 changes: 22 additions & 0 deletions Source/RxTest/Expectation+RxTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Nimble
import RxSwift
import RxTest

public typealias RecordedEvents<E> = [Recorded<Event<E>>]

public extension Expectation where T: ObservableType {
func events(scheduler: TestScheduler,
disposeBag: DisposeBag,
startAt initialTime: Int = 0) -> Expectation<RecordedEvents<T.E>> {
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
}
}
}

0 comments on commit 295ba56

Please sign in to comment.