NSArray+MASAdditionsSpec.m
1.87 KB
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
//
// NSArray+MASAdditionsSpec.m
// Masonry
//
// Created by Daniel Hammond on 11/26/13.
//
#import "NSArray+MASAdditions.h"
#import "MASViewConstraint.h"
SpecBegin(NSArray_MASAdditions)
- (void)testShouldFailWhenArrayContainsNonViews {
NSArray *array = @[ MAS_VIEW.new, [NSObject new] ];
expect(^{
[array mas_makeConstraints:^(MASConstraintMaker *make) {}];
}).to.raise(@"NSInternalInconsistencyException");
}
- (void)testShouldCreateConstraintsForEachView {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
NSArray *views = @[ subject1, subject2 ];
NSArray *constraints = [views mas_makeConstraints:^(MASConstraintMaker *make) {
expect(make.updateExisting).to.beFalsy();
make.width.equalTo(superView);
}];
expect(constraints).to.haveCountOf(views.count);
for (MASViewConstraint *constraint in constraints) {
MASViewAttribute *firstAttribute = [constraint firstViewAttribute];
expect([views indexOfObject:firstAttribute.view]).toNot.equal(NSNotFound);
expect(firstAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
MASViewAttribute *second = [constraint secondViewAttribute];
expect(second.view).to.equal(superView);
expect(second.layoutAttribute).to.equal(NSLayoutAttributeWidth);
}
}
- (void)testShouldSetUpdateExistingForArray {
NSArray *views = @[ MAS_VIEW.new ];
[views mas_updateConstraints:^(MASConstraintMaker *make) {
expect(make.updateExisting).to.beTruthy();
}];
}
- (void)testShouldSetRemoveExistingForArray {
NSArray *views = @[ MAS_VIEW.new ];
[views mas_remakeConstraints:^(MASConstraintMaker *make) {
expect(make.removeExisting).to.beTruthy();
}];
}
SpecEnd