Giter VIP home page Giter VIP 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

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 oronbz avatar pikuseru avatar rafaelplantard avatar shams-ahmed avatar vhbit avatar

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.