Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2
5.0
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
osx_image: xcode10
osx_image: xcode10.2
language: objective-c
sudo: required
env:
global:
- PROJECT="RxExpect.xcodeproj"
- SCHEME="RxExpect-Package"
- IOS_SDK="iphonesimulator12.0"
- IOS_SDK="iphonesimulator"
- MACOS_SDK="macosx10.14"
- TVOS_SDK="appletvsimulator12.0"
- TVOS_SDK="appletvsimulator"
matrix:
- SDK="$IOS_SDK" DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=12.0"
- SDK="$IOS_SDK" DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=12.2"
- SDK="$MACOS_SDK" DESTINATION="arch=x86_64"
- SDK="$TVOS_SDK" DESTINATION="OS=12.0,name=Apple TV 4K"
- SDK="$TVOS_SDK" DESTINATION="OS=12.2,name=Apple TV 4K"

install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "ReactiveX/RxSwift" >= 3.4
github "ReactiveX/RxSwift" >= 5.0
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.2
// swift-tools-version:5.0

import PackageDescription

Expand All @@ -8,7 +8,7 @@ let package = Package(
.library(name: "RxExpect", targets: ["RxExpect"]),
],
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.0.0")),
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")),
],
targets: [
.target(name: "RxExpect", dependencies: ["RxSwift", "RxTest"]),
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RxExpect
========

![Swift](https://img.shields.io/badge/Swift-4.2-orange.svg)
![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)
[![CocoaPods](http://img.shields.io/cocoapods/v/RxExpect.svg)](https://cocoapods.org/pods/RxExpect)
[![Build Status](https://travis-ci.org/devxoul/RxExpect.svg?branch=master)](https://travis-ci.org/devxoul/RxExpect)
[![Codecov](https://img.shields.io/codecov/c/github/devxoul/RxExpect.svg)](https://codecov.io/gh/devxoul/RxExpect/)
Expand All @@ -20,19 +20,19 @@ func testMultiply() {

// provide inputs
test.input(value, [
next(100, 1),
next(200, 2),
next(300, 3),
completed(400)
.next(100, 1),
.next(200, 2),
.next(300, 3),
.completed(400)
])

// test output
test.assert(result) { events in
XCTAssertEqual(events, [
next(100, 2),
next(200, 4),
next(300, 6),
completed(400)
.next(100, 2),
.next(200, 4),
.next(300, 6),
.completed(400)
])
}
}
Expand All @@ -57,7 +57,7 @@ final class ArticleDetailViewModelTests: XCTestCase {

// providing an user input: user tapped like button
test.input(viewModel.likeButtonDidTap, [
next(100, Void()),
.next(100, Void()),
])

// test output: like button become selected
Expand All @@ -73,7 +73,7 @@ final class ArticleDetailViewModelTests: XCTestCase {

// providing an user input: user tapped like button
test.input(viewModel.likeButtonDidTap, [
next(100, Void()),
.next(100, Void()),
])

// test output: like button become selected
Expand Down
10 changes: 5 additions & 5 deletions RxExpect.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RxExpect"
s.version = "1.2.0"
s.version = "1.3.0"
s.summary = "The RxSwift testing framework"
s.homepage = "https://github.com/devxoul/RxExpect"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand All @@ -14,8 +14,8 @@ Pod::Spec.new do |s|
s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"
s.dependency "RxSwift", ">= 4.0.0"
s.dependency "RxCocoa", ">= 4.0.0"
s.dependency "RxTest", ">= 4.0.0"

s.dependency "RxSwift", ">= 5.0.0"
s.dependency "RxCocoa", ">= 5.0.0"
s.dependency "RxTest", ">= 5.0.0"
end
8 changes: 5 additions & 3 deletions Sources/RxExpect/AnyTestTime.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import RxSwift
import RxTest

let AnyTestTime = TestTime.min
public struct AnyTestTime {
static let time = TestTime.min

public func next<T>(_ element: T) -> Recorded<Event<T>> {
return next(AnyTestTime, element)
public static func next<T>(_ element: T) -> Recorded<Event<T>> {
return Recorded.next(time, element)
}
}
8 changes: 4 additions & 4 deletions Sources/RxExpect/Assertion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ public typealias AssertionClosure<E> = ([Recorded<Event<E>>]) -> Void
open class Assertion<O: ObservableConvertibleType>: AnyAssertion {
let source: O
let disposeAt: TestTime?
let closure: AssertionClosure<O.E>
var recorder: TestableObserver<O.E>?
let closure: AssertionClosure<O.Element>
var recorder: TestableObserver<O.Element>?

init(source: O, disposeAt: TestTime?, closure: @escaping AssertionClosure<O.E>) {
init(source: O, disposeAt: TestTime?, closure: @escaping AssertionClosure<O.Element>) {
self.source = source
self.disposeAt = disposeAt
self.closure = closure
}

func prepareRecorder(scheduler: TestScheduler, disposeAt: TestTime?) {
let recorder = scheduler.createObserver(O.E.self)
let recorder = scheduler.createObserver(O.Element.self)
self.recorder = recorder

let subscription = self.source.asObservable().subscribe(recorder)
Expand Down
26 changes: 26 additions & 0 deletions Sources/RxExpect/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import RxSwift
import RxTest

// MARK: - AnyTestTime

@available(*, deprecated, message: "next is deprecated. Please use `AnyTestTime.next` as a replacement.")
public func next<T>(_ element: T) -> Recorded<Event<T>> {
return Recorded.next(AnyTestTime.time, element)
}

// MARK: - RxExpect

extension RxExpect {

@available(*, deprecated, message: "Variable is deprecated.")
public func input<Element>(_ variable: Variable<Element>, _ events: [Recorded<Event<Element>>], file: StaticString = #file, line: UInt = #line) {
Swift.assert(!events.contains { $0.time == AnyTestTime.time }, "Input events should have specific time.", file: file, line: line)
self.maximumInputTime = ([self.maximumInputTime] + events.map { $0.time }).max() ?? self.maximumInputTime
self.deferredInputs.append { `self` in
self.scheduler
.createHotObservable(events)
.subscribe(onNext: { variable.value = $0 })
.disposed(by: self.disposeBag)
}
}
}
17 changes: 3 additions & 14 deletions Sources/RxExpect/RxExpect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ open class RxExpect {
return object
}

public func input<O: ObserverType>(_ observer: O, _ events: [Recorded<Event<O.E>>], file: StaticString = #file, line: UInt = #line) {
Swift.assert(!events.contains { $0.time == AnyTestTime }, "Input events should have specific time.", file: file, line: line)
public func input<O: ObserverType>(_ observer: O, _ events: [Recorded<Event<O.Element>>], file: StaticString = #file, line: UInt = #line) {
Swift.assert(!events.contains { $0.time == AnyTestTime.time }, "Input events should have specific time.", file: file, line: line)
self.maximumInputTime = ([self.maximumInputTime] + events.map { $0.time }).max() ?? self.maximumInputTime
self.deferredInputs.append { `self` in
self.scheduler
Expand All @@ -40,18 +40,7 @@ open class RxExpect {
}
}

public func input<E>(_ variable: Variable<E>, _ events: [Recorded<Event<E>>], file: StaticString = #file, line: UInt = #line) {
Swift.assert(!events.contains { $0.time == AnyTestTime }, "Input events should have specific time.", file: file, line: line)
self.maximumInputTime = ([self.maximumInputTime] + events.map { $0.time }).max() ?? self.maximumInputTime
self.deferredInputs.append { `self` in
self.scheduler
.createHotObservable(events)
.subscribe(onNext: { variable.value = $0 })
.disposed(by: self.disposeBag)
}
}

open func assert<O: ObservableConvertibleType>(_ source: O, disposed: TestTime? = nil, closure: @escaping AssertionClosure<O.E>) {
open func assert<O: ObservableConvertibleType>(_ source: O, disposed: TestTime? = nil, closure: @escaping AssertionClosure<O.Element>) {
let assertion = Assertion(source: source, disposeAt: disposed, closure: closure)
self.assertions.append(assertion)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/RxExpect/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public enum EventFilter {
}

public extension Array where Element: RecordedType, Element.ValueType: EventType {
public var elements: [Element.ValueType.ElementType] {
var elements: [Element.ValueType.ElementType] {
return self.compactMap { $0.value.element }
}

public var error: Error? {
var error: Error? {
return self.lazy.compactMap { $0.value.error }.first
}

public func filter(_ event: EventFilter) -> Array<Element> {
func filter(_ event: EventFilter) -> Array<Element> {
return self.filter { $0.value.is(event) }
}

public func `in`<R>(_ timeRange: R) -> Array<Element> where R: RangeExpression, R.Bound == TestTime {
func `in`<R>(_ timeRange: R) -> Array<Element> where R: RangeExpression, R.Bound == TestTime {
return self.filter { timeRange.contains($0.time) }
}
}
2 changes: 1 addition & 1 deletion Tests/RxExpectTests/AnyTestTimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RxExpect

final class AnyTestTimeTests: XCTestCase {
func testAnyTestTime() {
let event = next("Hey")
let event = AnyTestTime.next("Hey")
XCTAssertEqual(event.value.element, "Hey")
XCTAssertLessThan(event.time, 0)
}
Expand Down
52 changes: 28 additions & 24 deletions Tests/RxExpectTests/RxExpectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class RxExpectTests: XCTestCase {
_ = {
let test = RxExpect()
let source = PublishSubject<String>()
test.input(source, [next(100, "A"), next(200, "B")])
test.input(source, [.next(100, "A"), .next(200, "B")])
test.assert(source) { _ in executions.append("1") }
test.assert(source) { _ in executions.append("2") }
test.assert(source) { _ in executions.append("3") }
Expand All @@ -21,47 +21,51 @@ final class RxExpectTests: XCTestCase {
let test = RxExpect()
let subject = PublishSubject<String>()
test.input(subject, [
next(100, "A"),
next(200, "B"),
completed(300),
.next(100, "A"),
.next(200, "B"),
.completed(300),
])
test.assert(subject) { events in
XCTAssertEqual(events, [
next(100, "A"),
next(200, "B"),
completed(300),
.next(100, "A"),
.next(200, "B"),
.completed(300),
])
}
}

@available(*, deprecated)
func testAssertEventsWithVariable() {
let test = RxExpect()
let variable = Variable<Int>(0)
test.input(variable, [
next(300, 1),
next(400, 2),
next(500, 3),
])
.next(300, 1),
.next(400, 2),
.next(500, 3),
])
test.assert(variable.asObservable()) { events in
XCTAssertEqual(events, [
next(0, 0),
next(300, 1),
next(400, 2),
next(500, 3),
.next(0, 0),
.next(300, 1),
.next(400, 2),
.next(500, 3),
])
}
}

func testAssertInfiniteObservable() {
let test = RxExpect()
let timer = Observable<Int>.interval(100, scheduler: test.scheduler)
let timer = Observable<Int>.interval(.seconds(100), scheduler: test.scheduler)
test.assert(timer, disposed: 400) { events in
XCTAssertEqual(events, [
next(100, 0),
next(200, 1),
next(300, 2),
.next(100, 0),
.next(200, 1),
.next(300, 2),
])
}
test.assert(timer, disposed: 200) { events in
XCTAssertEqual(events, [
next(100, 0),
.next(100, 0),
])
}
}
Expand All @@ -71,14 +75,14 @@ final class RxExpectTests: XCTestCase {
let subjects: [PublishSubject<String>] = [.init(), .init(), .init()]
let observable = Observable<String>.merge(subjects).observeOn(MainScheduler.instance)
test.input(subjects[0], [
next(500, "A"),
.next(500, "A"),
])
test.input(subjects[1], [
next(300, "B"),
.next(300, "B"),
])
test.input(subjects[2], [
next(100, "C"),
next(600, "D"),
.next(100, "C"),
.next(600, "D"),
])
test.assert(observable) { events in
XCTAssertEqual(events.elements, ["C", "B", "A", "D"])
Expand Down
Loading