-
Notifications
You must be signed in to change notification settings - Fork 496
/
Copy pathRACSequenceExamples.m
131 lines (104 loc) · 3.87 KB
/
RACSequenceExamples.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// RACSequenceExamples.m
// ReactiveObjC
//
// Created by Justin Spahr-Summers on 2012-11-01.
// Copyright (c) 2012 GitHub, Inc. All rights reserved.
//
@import Quick;
@import Nimble;
#import "RACSequenceExamples.h"
#import "RACScheduler.h"
#import "RACSequence.h"
#import "RACSignal+Operations.h"
NSString * const RACSequenceExamples = @"RACSequenceExamples";
NSString * const RACSequenceExampleSequence = @"RACSequenceExampleSequence";
NSString * const RACSequenceExampleExpectedValues = @"RACSequenceExampleExpectedValues";
QuickConfigurationBegin(RACSequenceExampleGroups)
+ (void)configure:(Configuration *)configuration {
sharedExamples(RACSequenceExamples, ^(QCKDSLSharedExampleContext exampleContext) {
__block RACSequence *sequence;
__block NSArray *values;
qck_beforeEach(^{
sequence = exampleContext()[RACSequenceExampleSequence];
values = [exampleContext()[RACSequenceExampleExpectedValues] copy];
});
qck_it(@"should implement <NSFastEnumeration>", ^{
NSMutableArray *collectedValues = [NSMutableArray array];
for (id value in sequence) {
[collectedValues addObject:value];
}
expect(collectedValues).to(equal(values));
});
qck_it(@"should return an array", ^{
expect(sequence.array).to(equal(values));
});
qck_describe(@"-signalWithScheduler:", ^{
qck_it(@"should return an immediately scheduled signal", ^{
RACSignal *signal = [sequence signalWithScheduler:RACScheduler.immediateScheduler];
expect(signal.toArray).to(equal(values));
});
qck_it(@"should return a background scheduled signal", ^{
RACSignal *signal = [sequence signalWithScheduler:[RACScheduler scheduler]];
expect(signal.toArray).to(equal(values));
});
qck_it(@"should only evaluate one value per scheduling", ^{
RACScheduler* scheduler = [RACScheduler schedulerWithPriority:RACSchedulerPriorityHigh];
RACSignal *signal = [sequence signalWithScheduler:scheduler];
__block BOOL flag = YES;
__block BOOL completed = NO;
[signal subscribeNext:^(id x) {
expect(@(flag)).to(beTruthy());
flag = NO;
[scheduler schedule:^{
// This should get executed before the next value (which
// verifies that it's YES).
flag = YES;
}];
} completed:^{
completed = YES;
}];
expect(@(completed)).toEventually(beTruthy());
});
});
qck_it(@"should be equal to itself", ^{
expect(sequence).to(equal(sequence));
});
qck_it(@"should be equal to the same sequence of values", ^{
RACSequence *newSequence = RACSequence.empty;
for (id value in values) {
RACSequence *valueSeq = [RACSequence return:value];
expect(valueSeq).notTo(beNil());
newSequence = [newSequence concat:valueSeq];
}
expect(sequence).to(equal(newSequence));
expect(@(sequence.hash)).to(equal(@(newSequence.hash)));
});
qck_it(@"should not be equal to a different sequence of values", ^{
RACSequence *anotherSequence = [RACSequence return:@(-1)];
expect(sequence).notTo(equal(anotherSequence));
});
qck_it(@"should return an identical object for -copy", ^{
expect([sequence copy]).to(beIdenticalTo(sequence));
});
qck_it(@"should archive", ^{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:sequence];
expect(data).notTo(beNil());
RACSequence *unarchived = [NSKeyedUnarchiver unarchiveObjectWithData:data];
expect(unarchived).to(equal(sequence));
});
qck_it(@"should fold right", ^{
RACSequence *result = [sequence foldRightWithStart:[RACSequence empty] reduce:^(id first, RACSequence *rest) {
return [rest.head startWith:first];
}];
expect(result.array).to(equal(values));
});
qck_it(@"should fold left", ^{
RACSequence *result = [sequence foldLeftWithStart:[RACSequence empty] reduce:^(RACSequence *first, id rest) {
return [first concat:[RACSequence return:rest]];
}];
expect(result.array).to(equal(values));
});
});
}
QuickConfigurationEnd