Giter Site home page Giter Site logo

rxnimble's Introduction

Build Status

RxNimble

Nimble extensions that make unit testing with RxSwift easier ๐ŸŽ‰

If you came here because you want to help out, please check out the contribution guide

Why

RxSwift includes a really nifty little library called RxBlocking which provides convenience functions for peeking in on Observable instances. Check is a blocking call, hence the name.

But writing code to check an Observable's value is sooooo tedious:

let result = try! observable.toBlocking().first()
expect(result) == 42

With RxNimble, we've added Nimble extension for Observables, so the code above can be rewritten as:

expect(observable).first == 42

Nice.

It's also possible to pass a timeout to the blocking operators:

expect(observable).first(timeout: 3) == 42

This extension is also available for all Traits (e.g. Single, Maybe) and other types conforming to ObservableConvertibleType.


If on the other hand you'd rather use RxTest instead of RxBlocking, you can do it by specifying RxNimble's RxTest subspec. With RxTest you can have more powerful tests, checking a stream as a whole instead of being limited to first, last and array (while the last 2 implicitly require the stream to have completed).

That means RxTest allows you to verify the occurrence of multiple next, error and completed events at specific virtual times:

expect(subject).events(scheduler: scheduler, disposeBag: disposeBag)
    .to(equal([
        Recorded.next(5, "Hello"),
        Recorded.next(10, "World"),
        Recorded.completed(100)
       ]))

You may also verify specific error types:

expect(imageSubject).events(scheduler: scheduler, disposeBag: disposeBag)
    .to(equal([
        Recorded.error(5, ImageError.invalidImage)
       ]))

Installation

CocoaPods

Add to the tests target in your Podfile:

pod 'RxNimble' # same as RxNimble/RxBlocking

or

pod 'RxNimble/RxTest' # installs RxTest instead of RxBlocking

or even

pod 'RxNimble', subspecs: ['RxBlocking', 'RxTest'] # installs both dependencies

And pod install and that's it!

Carthage

Add to your Cartfile.private:

github 'RxSwiftCommunity/RxNimble'

Run carthage update --cache-builds then drag & drop from the Carthage/Builds folder into your project either or both of:

  • RxNimbleRxBlocking.framework and RxBlocking.framework
  • RxNimbleRxTest.framework and RxTest.framework

Migration 4.5.0 -> 5.0.0

Deprecated function equalFirst was removed in favor of a more natural Nimble matcher API style.

RxNimble 4.5.0:

expect(o).to(equalFirst(...))

RxNimble 5.0.0:

expect(o).first.to(equal(...))

Known Issues

Very very very rarely the Swift compiler gets confused about the different types and you need to use the original RxBlocking code.

License

MIT ofc.

Give yourself a high five

rxnimble's People

Contributors

anton-plebanovich avatar ashfurrow avatar benuuu avatar cruisediary avatar ealeksandrov avatar gobetti avatar gre4ixin avatar kamitchell avatar lordzsolt avatar m0rtymerr avatar matyaskriz avatar mgray88 avatar mosamer avatar mrcljx avatar mrs- avatar n1nomiya avatar oronbz avatar rafaelplantard avatar shams-ahmed avatar vhbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxnimble's Issues

pod install fail with message "CocoaPods could not find compatible versions for pod RxNimble/RxTest"

Hi.
Thanks for creating the nice library.

I'm in trouble now with pod install.

After adding a line pod 'RxNimble/RxTest' to Podfile, pod install fails with an error below:

[!] CocoaPods could not find compatible versions for pod "RxNimble/RxTest":
In Podfile:
RxNimble/RxTest

None of your spec sources contain a spec satisfying the dependency: RxNimble/RxTest.

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.
โŒ๏ธ ERROR 31

How can I fix it?

Thanks in advance.

Including actual along with expected values in expectation message

I recently found it very helpful to edit the expectation messages (such as this one), to also report actual values.

I changed:
.expectedTo("equal <\(String(describing: expectedValue))>"

To:
.expectedTo("equal <\(String(describing: expectedValue))> got <\(String(describing: actualValue))>"))

You might also find it useful.
Thanks for your great work!

Can't use beAnInstanceOf to match Expectations

When comparing instances or classes the methods beAnInstanceOf and beAKindOf returns a Predicate<Any> but RxNimble expectation ask's for Predicate<T> instead.

Code:

let driverObject = Driver.just(Int())

// doesn't compile
expect(driverObject.asObservable()).first.to(beAnInstanceOf(Int.self))

// compile
let result = try! driverObject.asObservable().toBlocking().first()
expect(result).to(beAnInstanceOf(Int.self))

I don't know if it is as expected or if we can improve this.
Therefore I'm at your disposal to make a PR for this, but I would need some direction since I think this is not as easy as just changing the type of var first

Auto linking library fails with Swift version 5.2

I just tried to check out and build the project with Swift version 5.2 and got the error message

Could not find or use auto-linked library 'XCTest'
Could not find or use auto-linked library 'XCTestSupport'

When I explicitly link the XCTest framework into the project, it works just fine, but I cannot build my project when using this library with carthage.

Expectation not supporting all traits

I personally ran into a problem where Single was not supported. Single is widely used for HTTP requests as we expect just a single value/error, not a stream of multiple events.

Currently, expectation confronts to T : ObservableType, if it would be switched to T: ObservableConvertibleType, it would support all observables that have toBlocking support.

Nimble comparators seem to broken on Xcode 8.3.2 & Swift 3.1

The current code doesn't seem to catch the correct types with lhs and rhs based on the code example provided in the repo.

image

I've tried messing with the code a bit and couldn't get it to work, didn't really have time to thoroughly dig into it but thought it would be good to report.

Remove equalFirst

These methods were deprecated in 2017/11/02. I think two years are more than enough to migrate codebase (especially for such small repo). What do you think about removing them with version bump? Just to prevent potential user confusion.

Won't build on device when bitcode generation is enabled

Simple solution is turn off RxNimble's bitcode generation.

I think we should add target_xcconfig to turn off bitcode like Nimble does?

Library/Developer/Xcode/DerivedData/Fungogo-cuofhjsqszwhrjeanimgqkwzqduy/Build/Products/Debug-iphoneos/Nimble.framework/Nimble' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

CI

We should be testing this library.

(XCode 11.4) Could not find or use auto-linked library 'XCTestSwiftSupport'

XCode: v11.4
Swift: v5.2
RxNimble: v4.7.1

I cannot build the project. It shows auto-link error.

ld: warning: Could not find or use auto-linked library 'XCTestSwiftSupport'
Undefined symbols for architecture arm64:
  "__swift_FORCE_LOAD_$_XCTestSwiftSupport", referenced from:
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxNimbleRxTest in ThrowError+RxTest.o
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxNimbleRxTest in Expectation+RxTest.o
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxNimbleRxTest in Equal+RxTest.o
      __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxNimbleRxTest in Expectation+Ext.o
     (maybe you meant: __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_RxNimbleRxTest)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Package.swift need modify iOS deploy version 8 to 9

When using SPM, the following error message is displayed.

The package product 'RxSwift' requires minimum platform version 9.0 for the iOS platform, but this target supports 8.0
The package product 'Nimble' requires minimum platform version 9.0 for the iOS platform, but this target supports 8.0
The package product 'RxTest' requires minimum platform version 9.0 for the iOS platform, but this target supports 8.0
The package product 'RxBlocking' requires minimum platform version 9.0 for the iOS platform, but this target supports 8.0

To solve this problem, you need to modify iOS deploy version macOS(.v10_10) to macOS(.v10_12) and iOS(.v8) to iOS(.v9) of Package.swift.

Nimble 6.0 support

Please, add the Nimble 6.0+ support
I am using cocoapods, and RxNimble force version 5.1.1 to be installed, but 6.0.1 is available already

Not working with Xcode 10.0 and Swift 4.2

RxNimble 4.1.0
Nimble 7.1.3

I am getting

Cycle path: RxNimble โ†’ Nimble โ†’ RxNimble
Cycle details:
โ†’ Target 'RxNimble' has target dependency on Target 'Nimble'
...

throwError only works with Any

When using:

expect(subject).[last|first|array].to(throwError())

the tests only compile if the element used is Any. Otherwise you get a compilation error.

So

let subject = ReplaySubject<**Any**>.createUnbounded()
subject.onError(AnyError.any)

expect(subject).first.to(throwError())

works.

While

let subject = ReplaySubject<**String**>.createUnbounded()
subject.onError(AnyError.any)

expect(subject).first.to(throwError())

proceses: Instance method 'to(_:description:)' requires the types 'String' and 'Any' be equivalent

This issue seems closely related to #38

Visibility issue in Expectation extension

The workaround for accessing making the Expectation constructor "public" doesn't seem to work (anymore?):

extension Expectation {
    init(_ expression: Expression<T>) {
        self.expression = expression
    }

    // ...
}

I get the following error:

Initializer for struct 'Expectation' must use "self.init(...)" or "self = ..." because it is not in module 'Nimble'

I raised Quick/Nimble#531 - if that gets merged, I'll try to put up a PR to just use the constructor.

Xcode 15 Nimble & Foundation naming conflict

Hi, when using Xcode 15, RxNimble has an error 'Predicate' is ambiguous for type lookup in this context since Foundation has a conflict type Predicate with Nimble.
This is the related issue link in Nimble. I think maybe you want to consider the workaround described in it.

Carthage support

Is the lack of Carthage support a design decision or just no one got to do it yet? ๐Ÿ˜Š

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.