Giter VIP home page Giter VIP logo

llreactivematchers's People

Contributors

antol avatar glyuck avatar lawrencelomax 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

Watchers

 avatar  avatar  avatar  avatar

llreactivematchers's Issues

Temporally sensitive Signals require subscription before Subject values are sent

I was changing a bunch of the Unit Tests in the RAC repo to see how suitable the matchers were. By using RACReplaySubjects 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.

Optimisations - Fail early in appropriate matchers

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

Making LLSignalTestRecorder a Signal

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

Too much RAC

This repo contains too much ReactiveCocoa. Use it less.

Matchers - haveIdenticalErrors()

Asserts that two Signals have the same Errors.

  • Fails if the Signals do not error
  • Passes if the Signals have errors with the same error value
  • Fails if the Signals have errors with different error values

Double inclusion when Used as a Cocoapods

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.

Matcher - beSubscribedTo(count)

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

Super weird behaviour of switchToLatest after installing LLReactiveMatchers

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: '

match* matchers are not obvious

From the documentation I cannot understand the concept of matchIndexs. 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!

Matchers - haveIdenticalValues()

Matches two Signals that have the same number of next events, in the same order, with all values the same

  • Fails either of the Signals have not finished
  • Succeeds if events are the same, but one Signal ends in error, the other in completion
  • Fails if any of the events do not match

Trawl the ReactiveCocoa repo for common assertions

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.

Matchers - sendsError()

A matcher that tests that a Signal finishes with a specific error

  • Fails if the Signal has not finished
  • Fails if the Signal does not send the error provided
  • Succeeds if the expected error is equal to the one sent by the Signal.

Matchers - completes()

A matcher that tests whether a Signal ends in a completion event

  • Fails if the Signal has not yet completed
  • Fails if the Signal ends in error
  • Succeeds if the Signal has sent a completed event

Matchers - haveIdenticalEnd()

Matches two Signals that end in the same way effectively completes() || sendsError()

Matches:

  • Two Signals that both end in an error
  • Two Signals that end in the same error

Does Not Match:

  • Two Signals that end in different errors
  • One Signal ending in error, the other in completion

Semantics for Completion & Error testing Asynchronously

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

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.