Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Commit c80d27e

Browse files
committed
Refactor using Nimble matcher syntax
1 parent c665909 commit c80d27e

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

ReactiveViewModelTests/RVMViewModelSpec.m

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,50 @@
2323

2424
describe(@"active property", ^{
2525
it(@"should default to NO", ^{
26-
expect(viewModel.active).to(beFalsy());
26+
expect(@(viewModel.active)).to(beFalsy());
2727
});
2828

2929
it(@"should send on didBecomeActiveSignal when set to YES", ^{
3030
__block NSUInteger nextEvents = 0;
3131
[viewModel.didBecomeActiveSignal subscribeNext:^(RVMViewModel *viewModel) {
3232
expect(viewModel).to(beIdenticalTo(viewModel));
33-
expect(viewModel.active).to(beTruthy());
33+
expect(@(viewModel.active)).to(beTruthy());
3434

3535
nextEvents++;
3636
}];
3737

38-
expect(nextEvents).to(equal(0));
38+
expect(@(nextEvents)).to(equal(@0));
3939

4040
viewModel.active = YES;
41-
expect(nextEvents).to(equal(1));
41+
expect(@(nextEvents)).to(equal(@1));
4242

4343
// Indistinct changes should not trigger the signal again.
4444
viewModel.active = YES;
45-
expect(nextEvents).to(equal(1));
45+
expect(@(nextEvents)).to(equal(@1));
4646

4747
viewModel.active = NO;
4848
viewModel.active = YES;
49-
expect(nextEvents).to(equal(2));
49+
expect(@(nextEvents)).to(equal(@2));
5050
});
5151

5252
it(@"should send on didBecomeInactiveSignal when set to NO", ^{
5353
__block NSUInteger nextEvents = 0;
5454
[viewModel.didBecomeInactiveSignal subscribeNext:^(RVMViewModel *viewModel) {
5555
expect(viewModel).to(beIdenticalTo(viewModel));
56-
expect(viewModel.active).to(beFalsy());
56+
expect(@(viewModel.active)).to(beFalsy());
5757

5858
nextEvents++;
5959
}];
6060

61-
expect(nextEvents).to(equal(1));
61+
expect(@(nextEvents)).to(equal(@1));
6262

6363
viewModel.active = YES;
6464
viewModel.active = NO;
65-
expect(nextEvents).to(equal(2));
65+
expect(@(nextEvents)).to(equal(@2));
6666

6767
// Indistinct changes should not trigger the signal again.
6868
viewModel.active = NO;
69-
expect(nextEvents).to(equal(2));
69+
expect(@(nextEvents)).to(equal(@2));
7070
});
7171

7272
describe(@"signal manipulation", ^{
@@ -95,8 +95,8 @@
9595
});
9696

9797
afterEach(^{
98-
expect(deallocated).will.beTruthy();
99-
expect(completed).to(beTruthy());
98+
expect(@(deallocated)).toEventually(beTruthy());
99+
expect(@(completed)).to(beTruthy());
100100
});
101101

102102
it(@"should forward a signal", ^{
@@ -119,18 +119,18 @@
119119

120120
expectedValues = @[ @1, @2 ];
121121
expect(values).to(equal(expectedValues));
122-
expect(completed).to(beFalsy());
122+
expect(@(completed)).to(beFalsy());
123123

124124
viewModel.active = NO;
125125

126126
expect(values).to(equal(expectedValues));
127-
expect(completed).to(beFalsy());
127+
expect(@(completed)).to(beFalsy());
128128

129129
viewModel.active = YES;
130130

131131
expectedValues = @[ @1, @2, @1, @2 ];
132132
expect(values).to(equal(expectedValues));
133-
expect(completed).to(beFalsy());
133+
expect(@(completed)).to(beFalsy());
134134
}
135135
});
136136

@@ -149,13 +149,13 @@
149149

150150
expectedValues = @[ @0 ];
151151
expect(values).to(equal(expectedValues));
152-
expect(completed).to(beFalsy());
152+
expect(@(completed)).to(beFalsy());
153153

154154
[subject sendNext:@1];
155155

156156
expectedValues = @[ @0, @1 ];
157157
expect(values).to(equal(expectedValues));
158-
expect(completed).to(beFalsy());
158+
expect(@(completed)).to(beFalsy());
159159

160160
viewModel.active = NO;
161161

@@ -164,31 +164,37 @@
164164
[subject sendNext:@3];
165165

166166
expect(values).to(equal(expectedValues));
167-
expect(completed).to(beFalsy());
167+
expect(@(completed)).to(beFalsy());
168168

169169
expectedValues = @[ @0, @1, @3 ];
170-
expect(values).will.equal(expectedValues);
171-
expect(completed).to(beFalsy());
170+
171+
// FIXME: Nimble doesn't support custom timeouts right now, and
172+
// our operation may take longer than 1 second (the default
173+
// timeout), sooo... trololo
174+
[NSThread sleepForTimeInterval:1];
175+
176+
expect(values).toEventually(equal(expectedValues));
177+
expect(@(completed)).to(beFalsy());
172178

173179
// After reactivating, we should still get this event.
174180
[subject sendNext:@4];
175181
viewModel.active = YES;
176182

177183
expectedValues = @[ @0, @1, @3, @4 ];
178-
expect(values).will.equal(expectedValues);
179-
expect(completed).to(beFalsy());
184+
expect(values).toEventually(equal(expectedValues));
185+
expect(@(completed)).to(beFalsy());
180186

181187
// And now new events should be instant.
182188
[subject sendNext:@5];
183189

184190
expectedValues = @[ @0, @1, @3, @4, @5 ];
185191
expect(values).to(equal(expectedValues));
186-
expect(completed).to(beFalsy());
192+
expect(@(completed)).to(beFalsy());
187193

188194
[subject sendCompleted];
189195

190196
expect(values).to(equal(expectedValues));
191-
expect(completed).to(beTruthy());
197+
expect(@(completed)).to(beTruthy());
192198
}
193199
});
194200
});

0 commit comments

Comments
 (0)