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:
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
Observableinstances. Check is a blocking call, hence the name.But writing code to check an
Observable‘s value is sooooo tedious:With
RxNimble, we’ve added Nimble extension forObservables, so the code above can be rewritten as:Nice.
It’s also possible to pass a timeout to the blocking operators:
This extension is also available for all Traits (e.g.
Single,Maybe) and other types conforming toObservableConvertibleType.If on the other hand you’d rather use RxTest instead of
RxBlocking, you can do it by specifying RxNimble’sRxTestsubspec. With RxTest you can have more powerful tests, checking a stream as a whole instead of being limited tofirst,lastandarray(while the last 2 implicitly require the stream to have completed).That means RxTest allows you to verify the occurrence of multiple
next,errorandcompletedevents at specific virtual times:You may also verify specific error types:
Installation
CocoaPods
Add to the tests target in your Podfile:
or
or even
And
pod installand that’s it!Carthage
Add to your Cartfile.private:
Run
carthage update --cache-buildsthen drag & drop from the Carthage/Builds folder into your project either or both of:RxNimbleRxBlocking.frameworkandRxBlocking.frameworkRxNimbleRxTest.frameworkandRxTest.frameworkMigration 4.5.0 -> 5.0.0
Deprecated function
equalFirstwas removed in favor of a more natural Nimble matcher API style.RxNimble 4.5.0:
RxNimble 5.0.0:
Known Issues
Very very very rarely the Swift compiler gets confused about the different types and you need to use the original
RxBlockingcode.License
MIT ofc.