lawrencelomax / llreactivematchers Goto Github PK
View Code? Open in Web Editor NEWExpecta matchers for ReactiveCocoa
License: MIT License
Expecta matchers for ReactiveCocoa
License: MIT License
I was changing a bunch of the Unit Tests in the RAC repo to see how suitable the matchers were. By using RACReplaySubject
s in place of subjects, Signal chains can be tested at the end of the case
So this:
NSMutableArray *values = [NSMutableArray array];
[merged subscribeNext:^(id x) {
[values addObject:x];
}];
[sub1 sendNext:@1];
[sub2 sendNext:@2];
[sub2 sendNext:@3];
[sub1 sendNext:@4];
NSArray *expected = @[ @1, @2, @3, @4 ];
expect(values).to.equal(expected);
Goes to this:
[sub1 sendNext:@1];
[sub2 sendNext:@2];
[sub2 sendNext:@3];
[sub1 sendNext:@4];
NSArray *expected = @[ @1, @2, @3, @4 ];
expect(merged).to.sendValues(expected);
However this will not work where ordering of the values is significant as is the case in the tests for merge:
NSMutableArray *results = [NSMutableArray array];
[combined subscribeNext:^(id x) {
[results addObject:x];
}];
[subject1 sendNext:@"1"];
[subject2 sendNext:@"2"];
[subject1 sendNext:@"3"];
[subject2 sendNext:@"4"];
expect(results[0]).to.equal(RACTuplePack(@"1", @"2"));
expect(results[1]).to.equal(RACTuplePack(@"3", @"2"));
expect(results[2]).to.equal(RACTuplePack(@"3", @"4"));
The alternative will fail:
LLSignalTestRecorder *recorder = [LLSignalTestRecorder recordWithSignal:combined];
[subject1 sendNext:@"1"];
[subject2 sendNext:@"2"];
[subject1 sendNext:@"3"];
[subject2 sendNext:@"4"];
expect(recorder).to.sendValuesIdentically(@[ RACTuplePack(@"1", @"2"), RACTuplePack(@"3", @"2"), RACTuplePack(@"3", @"4")]);
This is because the each of the two subjects are unaware (by design) of the order that they were called relative to one another. By passing a LLSignalTestRecorder
as the actual instead of a Signal, we can remove the dependency on a RACReplaySubject
and keep the significance of the ordering.
In particular this will apply for tests that use Subjects because their values are sent at the time sendNext:
is called rather than when they are subscribed to in the matcher.
In matchers for next values we can fail early
For example with haveIdenticalValues()
for two signals:
1, 2, 3, 4, 5
1, 2, 5, 4, 5
we can fail when the events are known to be non-identical, i.e at index 2 of the values
LLSignalTestRecorder
is essentially a RACReplaySubject
that exposes all the values it has received as properties. During #13, it seemed to me that LLSignalTestRecorder
maybe better off as a Signal, then usage of LLSignalTestRecorder
as an actual doesn't need to be special cased. The behaviour of LLSignalTestRecorder
will then be much clearer to newcomers to the library
This repo contains too much ReactiveCocoa. Use it less.
Asserts that two Signals have the same Errors.
There is currently an issue with CocoaPods that means ReactiveCocoa will get linked twice when LLReactiveMatchers is used as a Pod.
Since this project should be vendable as a CocoaPod, I will watch and then close this issue when the issue has been fixed.
A matcher for the number of subscriptions a Signal takes, important for testing side-effects for Signals that perform side-effects on Subscription.
This will probably not be orthogonal to the changes made to LLSignalTestRecorder
, which now has multicasting behaviour. Ideally the monitoring of subscription counts would occur inside the recorder so as to avoid swizzling subscribe:
on RACSignal
After installing LLReactiveMatchers (via cocoa pods) on unit test target I am getting exception on switchToLatest, which completely doesn't make sense (exception is quite self explanatory). Once I remove LLReactiveMatchers from project, problem disappears.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-switchToLatest requires that the source signal (<RACDynamicSignal: 0x7fcd23c5db40> name: ) send signals. Instead we got: <RACDynamicSignal: 0x7fcd23c86010> name: '
The builds have been breaking on Travis as there have been updates to cocoapods in the time that I have been on 😎
From the documentation I cannot understand the concept of matchIndex
s. What does that mean?
Further, the use of to.sendValue(matchIndex, value)
is not covered outside of the context of multicast.
It's very confusing!
Matches two Signals that have the same number of next events, in the same order, with all values the same
There are a bunch of different behaviours that the ReactiveCocoa repo checks in Unit Tests other than checking values sent. I've seen some tests on the number of subscriptions that occur and disposal.
I might take a look at rewriting some of the RAC Unit tests using LLReactiveMatchers, but I want to prevent this from being anything other than an experiment to figure out how suitable LLReactiveMatchers is to the task.
A matcher that tests that a Signal finishes with a specific error
A matcher that tests whether a Signal ends in a completion event
Matches two Signals that end in the same way effectively completes()
|| sendsError()
Matches:
Does Not Match:
Failure messages for Signals don't contain the values and errors sent by the Signals in all cases, this should be improved.
These matchers are kinda too awesome not to be on there, right!
The behaviour of asynchronous matching is to continuously check the matcher passes until the timeout elapses, or the matcher passes.
This can pose a problem for negative matchers, which essentially invert the matcher.
Given an asynchronous signal that will complete before the timeout period, but after the matcher is first polled, it will pass because the condition that completed is not sent will be satisfied immediately be passed. The desired behaviour would be to check that the condition is satisfied for the duration of the timeout period.
// Lets assume that this signal does not exhibit the desired behaviour of not completing
// It will complete a short time after it is subscribed to
RACSignal *signal;
// Passes immediately
expect(signal).toNot.complete();
This knowledge about the expectation would probably need to be implemented in something like EXPExpect
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.