ソースを参照

Added tests for maker.removeExisting

Nikolay Tymchenko 11 年 前
コミット
0133f34d18

+ 22 - 0
Tests/Specs/MASConstraintMakerSpec.m

@@ -172,6 +172,28 @@ SpecBegin(MASConstraintMaker) {
     expect(constraint2.constant).to.equal(20);
 }
 
+- (void)testRemoveConstraints {
+    MAS_VIEW *newView = MAS_VIEW.new;
+    [superview addSubview:newView];
+    
+    maker.left.equalTo(newView).offset(10);
+    maker.right.equalTo(newView).offset(20);
+    maker.width.equalTo(newView).offset(30);
+    [maker install];
+    
+    expect(superview.constraints).to.haveCountOf(3);
+    expect([MASViewConstraint installedConstraintsForView:view]).to.haveCountOf(3);
+    
+    maker.removeExisting = YES;
+    maker.height.equalTo(newView).offset(100);
+    [maker install];
+    
+    expect(superview.constraints).to.haveCountOf(1);
+    expect([MASViewConstraint installedConstraintsForView:view]).to.haveCountOf(1);
+    NSLayoutConstraint *constraint1 = superview.constraints[0];
+    expect(constraint1.constant).to.equal(100);
+}
+
 - (void)testCreateNewViewAttributes {
     expect(maker.left).notTo.beIdenticalTo(maker.left);
     expect(maker.right).notTo.beIdenticalTo(maker.right);

+ 7 - 0
Tests/Specs/NSArray+MASAdditionsSpec.m

@@ -52,4 +52,11 @@ SpecBegin(NSArray_MASAdditions)
     }];
 }
 
+- (void)testShouldSetRemoveExistingForArray {
+    NSArray *views = @[ MAS_VIEW.new ];
+    [views mas_remakeConstraints:^(MASConstraintMaker *make) {
+        expect(make.removeExisting).to.beTruthy();
+    }];
+}
+
 SpecEnd

+ 9 - 0
Tests/Specs/View+MASAdditionsSpec.m

@@ -28,4 +28,13 @@ SpecBegin(View_MASAdditions)
     expect(newView.translatesAutoresizingMaskIntoConstraints).to.beFalsy();
 }
 
+- (void)testSetRemoveExisting {
+    MAS_VIEW *newView = MAS_VIEW.new;
+    [newView mas_remakeConstraints:^(MASConstraintMaker *make) {
+        expect(make.removeExisting).to.beTruthy();
+    }];
+    
+    expect(newView.translatesAutoresizingMaskIntoConstraints).to.beFalsy();
+}
+
 SpecEnd