forked from ReactiveCocoa/ReactiveObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRACControlCommandExamples.m
86 lines (64 loc) · 2.44 KB
/
RACControlCommandExamples.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
//
// RACControlCommandExamples.m
// ReactiveObjC
//
// Created by Justin Spahr-Summers on 2013-08-15.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//
@import Quick;
@import Nimble;
#import "RACControlCommandExamples.h"
#import "RACCommand.h"
#import "RACSubject.h"
#import "RACUnit.h"
NSString * const RACControlCommandExamples = @"RACControlCommandExamples";
NSString * const RACControlCommandExampleControl = @"RACControlCommandExampleControl";
NSString * const RACControlCommandExampleActivateBlock = @"RACControlCommandExampleActivateBlock";
// Methods used by the unit test that would otherwise require platform-specific
// imports.
@interface NSObject (RACControlCommandExamples)
@property (nonatomic, strong) RACCommand *rac_command;
- (BOOL)isEnabled;
@end
QuickConfigurationBegin(RACControlCommandExampleGroups)
+ (void)configure:(Configuration *)configuration {
sharedExamples(RACControlCommandExamples, ^(QCKDSLSharedExampleContext exampleContext) {
__block id control;
__block void (^activate)(id);
__block RACSubject *enabledSubject;
__block RACCommand *command;
qck_beforeEach(^{
control = exampleContext()[RACControlCommandExampleControl];
activate = [exampleContext()[RACControlCommandExampleActivateBlock] copy];
enabledSubject = [RACSubject subject];
command = [[RACCommand alloc] initWithEnabled:enabledSubject signalBlock:^(id sender) {
return [RACSignal return:sender];
}];
[control setRac_command:command];
});
qck_it(@"should bind the control's enabledness to the command", ^{
expect(@([control isEnabled])).toEventually(beTruthy());
[enabledSubject sendNext:@NO];
expect(@([control isEnabled])).toEventually(beFalsy());
[enabledSubject sendNext:@YES];
expect(@([control isEnabled])).toEventually(beTruthy());
});
qck_it(@"should execute the control's command when activated", ^{
__block BOOL executed = NO;
[[command.executionSignals flatten] subscribeNext:^(id sender) {
expect(sender).to(equal(control));
executed = YES;
}];
activate(control);
expect(@(executed)).toEventually(beTruthy());
});
qck_it(@"should overwrite an existing command when setting a new one", ^{
RACCommand *secondCommand = [[RACCommand alloc] initWithSignalBlock:^(id _) {
return [RACSignal return:RACUnit.defaultUnit];
}];
[control setRac_command:secondCommand];
expect([control rac_command]).to(beIdenticalTo(secondCommand));
});
});
}
QuickConfigurationEnd