Эх сурвалжийг харах

remove unnecessary enum MASCompositeConstraintType and misc tidy up

Jonas Budelmann 12 жил өмнө
parent
commit
a415c8e942

+ 6 - 0
Masonry.xcodeproj/project.pbxproj

@@ -61,6 +61,8 @@
 		DDA5752D17C187D40010F88E /* MASUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = DDA5752917C17C3E0010F88E /* MASUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		DDE2653F179D24E600D48565 /* View+MASShorthandAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE2653D179D24E600D48565 /* View+MASShorthandAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		DDEDACEF17C845DE00098BE6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDEDACEE17C845DE00098BE6 /* Cocoa.framework */; };
+		DDF0BE9517C9D6DA00DEA237 /* MASConstraintMakerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF0BE9417C9D6DA00DEA237 /* MASConstraintMakerSpec.m */; };
+		DDF0BE9617C9D6DA00DEA237 /* MASConstraintMakerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DDF0BE9417C9D6DA00DEA237 /* MASConstraintMakerSpec.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -134,6 +136,7 @@
 		DDA5752917C17C3E0010F88E /* MASUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASUtilities.h; sourceTree = "<group>"; };
 		DDE2653D179D24E600D48565 /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = "<group>"; };
 		DDEDACEE17C845DE00098BE6 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
+		DDF0BE9417C9D6DA00DEA237 /* MASConstraintMakerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraintMakerSpec.m; sourceTree = "<group>"; };
 		EDE028375B0043E190A00F61 /* Pods-Masonry Mac Tests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Masonry Mac Tests.xcconfig"; path = "Pods/Pods-Masonry Mac Tests.xcconfig"; sourceTree = SOURCE_ROOT; };
 /* End PBXFileReference section */
 
@@ -263,6 +266,7 @@
 			children = (
 				DD52F1D8179CAA9C005CD195 /* MASCompositeConstraintSpec.m */,
 				DD52F1D9179CAA9C005CD195 /* MASViewConstraintSpec.m */,
+				DDF0BE9417C9D6DA00DEA237 /* MASConstraintMakerSpec.m */,
 			);
 			name = Specs;
 			sourceTree = "<group>";
@@ -592,6 +596,7 @@
 				DD52F1DA179CAA9C005CD195 /* MASCompositeConstraintSpec.m in Sources */,
 				DD52F1DB179CAA9C005CD195 /* MASViewConstraintSpec.m in Sources */,
 				DD38397E17A5170F00C35C17 /* MASConstraintDelegateMock.m in Sources */,
+				DDF0BE9517C9D6DA00DEA237 /* MASConstraintMakerSpec.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -616,6 +621,7 @@
 				DDA4D72717C025FD0076BD87 /* MASCompositeConstraintSpec.m in Sources */,
 				DDA4D72817C026030076BD87 /* MASViewConstraintSpec.m in Sources */,
 				DDA4D72917C0260C0076BD87 /* MASConstraintDelegateMock.m in Sources */,
+				DDF0BE9617C9D6DA00DEA237 /* MASConstraintMakerSpec.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 29
Masonry/MASCompositeConstraint.h

@@ -9,40 +9,12 @@
 #import "MASConstraint.h"
 #import "MASUtilities.h"
 
-typedef enum MASCompositeConstraintType : NSInteger {
-    MASCompositeConstraintTypeEdges, //top, left, bottom, right
-    MASCompositeConstraintTypeSize, //width, height
-    MASCompositeConstraintTypeCenter, //centerX, centerY
-    MASCompositeConstraintTypeUnknown, //could be mixture of any attributes
-} MASCompositeConstraintType;
-
 /**
  *	A group of MASConstraint objects
  *  conforms to MASConstraint
  */
 @interface MASCompositeConstraint : NSObject <MASConstraint>
 
-/**
- *	default first item for any child MASConstraints
- */
-@property (nonatomic, weak, readonly) MAS_VIEW *view;
-
-/**
- *	type of Composite, used internally to generate child MASViewConstraits
- */
-@property (nonatomic, assign, readonly) MASCompositeConstraintType type;
-
-/**
- *	Creates a composite and automatically generates child MASViewConstraints
- *  Appriopriate to the type
- *
- *	@param	view	first item view
- *	@param	type	determines what kind of child constraints to generate
- *
- *	@return	a composite constraint
- */
-- (id)initWithView:(MAS_VIEW *)view type:(MASCompositeConstraintType)type;
-
 /**
  *	Creates a composite with a predefined array of children
  *
@@ -51,6 +23,6 @@ typedef enum MASCompositeConstraintType : NSInteger {
  *
  *	@return	a composite constraint
  */
-- (id)initWithView:(MAS_VIEW *)view children:(NSArray *)children;
+- (id)initWithChildren:(NSArray *)children;
 
 @end

+ 1 - 49
Masonry/MASCompositeConstraint.m

@@ -7,8 +7,6 @@
 //
 
 #import "MASCompositeConstraint.h"
-#import "View+MASAdditions.h"
-#import "MASViewConstraint.h"
 
 @interface MASCompositeConstraint () <MASConstraintDelegate>
 
@@ -21,24 +19,10 @@
 
 @synthesize delegate = _delegate;
 
-- (id)initWithView:(MAS_VIEW *)view type:(MASCompositeConstraintType)type {
-    self = [super init];
-    if (!self) return nil;
-    
-    _view = view;
-    _type = type;
-    
-    [self createChildren];
-    
-    return self;
-}
-
-- (id)initWithView:(MAS_VIEW *)view children:(NSArray *)children {
+- (id)initWithChildren:(NSArray *)children {
     self = [super init];
     if (!self) return nil;
 
-    _type = MASCompositeConstraintTypeUnknown;
-    _view = view;
     _childConstraints = [children mutableCopy];
     for (id<MASConstraint> constraint in _childConstraints) {
         constraint.delegate = self;
@@ -47,38 +31,6 @@
     return self;
 }
 
-- (void)createChildren {
-    self.childConstraints = NSMutableArray.array;
-    
-    NSArray *viewAttributes;
-    switch (self.type) {
-        case MASCompositeConstraintTypeEdges:
-            viewAttributes = @[
-                self.view.mas_top, self.view.mas_left,
-                self.view.mas_bottom, self.view.mas_right
-            ];
-            break;
-        case MASCompositeConstraintTypeSize:
-            viewAttributes = @[
-                self.view.mas_width, self.view.mas_height
-            ];
-            break;
-        case MASCompositeConstraintTypeCenter:
-            viewAttributes = @[
-                self.view.mas_centerX, self.view.mas_centerY
-            ];
-            break;
-        default:
-            break;
-    }
-    
-    for (MASViewAttribute *viewAttribute in viewAttributes) {
-        MASViewConstraint *child = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
-        child.delegate = self;
-        [self.childConstraints addObject:child];
-    }
-}
-
 #pragma mark - MASConstraintDelegate
 
 - (void)constraint:(id<MASConstraint>)constraint shouldBeReplacedWithConstraint:(id<MASConstraint>)replacementConstraint {

+ 2 - 2
Masonry/MASConstraintMaker.h

@@ -58,8 +58,8 @@
 - (id)initWithView:(MAS_VIEW *)view;
 
 /**
- *	Calls commit method on any MASConstraints which requested to be added view MASConstraintDelegate
+ *	Calls install method on any MASConstraints which have been created by this maker
  */
-- (void)commit;
+- (void)install;
 
 @end

+ 31 - 16
Masonry/MASConstraintMaker.m

@@ -10,6 +10,7 @@
 #import "MASViewConstraint.h"
 #import "MASCompositeConstraint.h"
 #import "MASViewAttribute.h"
+#import "View+MASAdditions.h"
 
 @interface MASConstraintMaker () <MASConstraintDelegate>
 
@@ -30,7 +31,7 @@
     return self;
 }
 
-- (void)commit {
+- (void)install {
     for (id<MASConstraint> constraint in self.constraints) {
         [constraint install];
     }
@@ -47,7 +48,7 @@
 
 #pragma mark - constraint properties
 
-- (id<MASConstraint>)constraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
+- (id<MASConstraint>)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
     MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute];
     MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
     constraint.delegate = self;
@@ -58,68 +59,82 @@
 #pragma mark - standard Attributes
 
 - (id<MASConstraint>)left {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeLeft];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
 }
 
 - (id<MASConstraint>)top {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeTop];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
 }
 
 - (id<MASConstraint>)right {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeRight];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
 }
 
 - (id<MASConstraint>)bottom {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeBottom];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
 }
 
 - (id<MASConstraint>)leading {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeLeading];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
 }
 
 - (id<MASConstraint>)trailing {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeTrailing];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
 }
 
 - (id<MASConstraint>)width {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeWidth];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
 }
 
 - (id<MASConstraint>)height {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeHeight];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
 }
 
 - (id<MASConstraint>)centerX {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeCenterX];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
 }
 
 - (id<MASConstraint>)centerY {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeCenterY];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
 }
 
 - (id<MASConstraint>)baseline {
-    return [self constraintWithLayoutAttribute:NSLayoutAttributeBaseline];
+    return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
 }
 
 
 #pragma mark - composite Attributes
 
 - (id<MASConstraint>)edges {
-    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeConstraintTypeEdges];
+    NSArray *children = @[
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_top],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_left],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_bottom],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_right]
+    ];
+    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
     constraint.delegate = self;
     [self.constraints addObject:constraint];
     return constraint;
 }
 
 - (id<MASConstraint>)size {
-    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeConstraintTypeSize];
+    NSArray *children = @[
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_width],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_height]
+    ];
+    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
     constraint.delegate = self;
     [self.constraints addObject:constraint];
     return constraint;
 }
 
 - (id<MASConstraint>)center {
-    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeConstraintTypeCenter];
+    NSArray *children = @[
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_centerX],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:self.view.mas_centerY]
+    ];
+    MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
     constraint.delegate = self;
     [self.constraints addObject:constraint];
     return constraint;

+ 0 - 5
Masonry/MASViewConstraint.h

@@ -22,11 +22,6 @@
  */
 @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
 
-/**
- *	The generate MASLayoutConstraint could be nil if -commit has not been called
- */
-@property (nonatomic, strong, readonly) MASLayoutConstraint *layoutConstraint;
-
 /**
  *	initialises the MASViewConstraint with the first part of the equation
  *

+ 21 - 16
Masonry/MASViewConstraint.m

@@ -14,8 +14,8 @@
 @interface MASViewConstraint ()
 
 @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
-@property (nonatomic, strong, readwrite) MASLayoutConstraint *layoutConstraint;
 @property (nonatomic, weak) MAS_VIEW *installedView;
+@property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
 @property (nonatomic, assign) NSLayoutRelation layoutRelation;
 @property (nonatomic, assign) MASLayoutPriority layoutPriority;
 @property (nonatomic, assign) CGFloat layoutMultiplier;
@@ -214,7 +214,7 @@
                 viewConstraint.secondViewAttribute = attr;
                 [children addObject:viewConstraint];
             }
-            MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithView:self.firstViewAttribute.view children:children];
+            MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
             compositeConstraint.delegate = self.delegate;
             [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
             return compositeConstraint;
@@ -262,34 +262,39 @@
     NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
     MAS_VIEW *secondLayoutItem = self.secondViewAttribute.view;
     NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
+
+    // alignment attributes must have a secondViewAttribute
+    // therefore we assume that is refering to superview
+    // eg make.left.equalTo(@10)
     if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
         secondLayoutItem = firstLayoutItem.superview;
         secondLayoutAttribute = firstLayoutAttribute;
     }
     
+    MASLayoutConstraint *layoutConstraint
+        = [MASLayoutConstraint constraintWithItem:firstLayoutItem
+                                        attribute:firstLayoutAttribute
+                                        relatedBy:self.layoutRelation
+                                           toItem:secondLayoutItem
+                                        attribute:secondLayoutAttribute
+                                       multiplier:self.layoutMultiplier
+                                         constant:self.layoutConstant];
     
-    self.layoutConstraint = [MASLayoutConstraint constraintWithItem:firstLayoutItem
-                                                          attribute:firstLayoutAttribute
-                                                          relatedBy:self.layoutRelation
-                                                             toItem:secondLayoutItem
-                                                          attribute:secondLayoutAttribute
-                                                         multiplier:self.layoutMultiplier
-                                                           constant:self.layoutConstant];
-    
-    self.layoutConstraint.priority = self.layoutPriority;
-    self.layoutConstraint.mas_key = self.mas_key;
+    layoutConstraint.priority = self.layoutPriority;
+    layoutConstraint.mas_key = self.mas_key;
     
     if (secondLayoutItem) {
         MAS_VIEW *closestCommonSuperview = [firstLayoutItem mas_closestCommonSuperview:secondLayoutItem];
         NSAssert(closestCommonSuperview,
                  @"couldn't find a common superview for %@ and %@",
-                 firstLayoutItem,
-                 secondLayoutItem);
+                 firstLayoutItem, secondLayoutItem);
         self.installedView = closestCommonSuperview;
-        [closestCommonSuperview addConstraint:self.layoutConstraint];
+        [closestCommonSuperview addConstraint:layoutConstraint];
+        self.layoutConstraint = layoutConstraint;
     } else {
         self.installedView = firstLayoutItem;
-        [firstLayoutItem addConstraint:self.layoutConstraint];
+        [firstLayoutItem addConstraint:layoutConstraint];
+        self.layoutConstraint = layoutConstraint;
     }
 }
 

+ 7 - 0
Masonry/View+MASAdditions.h

@@ -36,6 +36,13 @@
  */
 @property (nonatomic, strong) id mas_key;
 
+/**
+ *	Finds the closest common superview between this view and another view
+ *
+ *	@param	view	other view
+ *
+ *	@return	returns nil if common superview could not be found
+ */
 - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
 
 /**

+ 2 - 2
Masonry/View+MASAdditions.m

@@ -15,7 +15,7 @@
     self.translatesAutoresizingMaskIntoConstraints = NO;
     MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
     block(constraintMaker);
-    [constraintMaker commit];
+    [constraintMaker install];
 }
 
 #pragma mark - NSLayoutAttribute properties
@@ -64,7 +64,7 @@
     return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
 }
 
-#pragma mark - key
+#pragma mark - associated properties
 
 - (id)mas_key {
     return objc_getAssociatedObject(self, @selector(mas_key));

+ 8 - 63
MasonryTests/MASCompositeConstraintSpec.m

@@ -9,6 +9,7 @@
 #import "MASCompositeConstraint.h"
 #import "MASViewConstraint.h"
 #import "MASConstraintDelegateMock.h"
+#import "View+MASAdditions.h"
 
 @interface MASCompositeConstraint () <MASConstraintDelegate>
 
@@ -18,6 +19,7 @@
 
 @interface MASViewConstraint ()
 
+@property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
 @property (nonatomic, assign) CGFloat layoutConstant;
 @property (nonatomic, assign) MASLayoutPriority layoutPriority;
 
@@ -31,71 +33,19 @@ __block MAS_VIEW *view;
 __block MASCompositeConstraint *composite;
 
 beforeEach(^{
-    composite = nil;
     delegate = MASConstraintDelegateMock.new;
     view = MAS_VIEW.new;
     superview = MAS_VIEW.new;
     [superview addSubview:view];
-});
-
-it(@"should create centerY and centerX children", ^{
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeCenter];
-
-    expect(composite.childConstraints).to.haveCountOf(2);
-
-    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeCenterX);
-
-    viewConstraint = [composite.childConstraints objectAtIndex:1];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeCenterY);
-});
-
-it(@"should create top, left, bottom, right children", ^{
-    MAS_VIEW *newView = MAS_VIEW.new;
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeEdges];
-    composite.equalTo(newView);
-
-    expect(composite.childConstraints).to.haveCountOf(4);
-
-    //top
-    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeTop);
-
-    //left
-    viewConstraint = [composite.childConstraints objectAtIndex:1];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeLeft);
-
-    //bottom
-    viewConstraint = [composite.childConstraints objectAtIndex:2];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeBottom);
-
-    //right
-    viewConstraint = [composite.childConstraints objectAtIndex:3];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeRight);
-});
-
-it(@"should create width and height children", ^{
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeSize];
-    expect(composite.childConstraints).to.haveCountOf(2);
-
-    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
-
-    viewConstraint = [composite.childConstraints objectAtIndex:1];
-    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(composite.view);
-    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
+    NSArray *children = @[
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_width],
+        [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_height]
+    ];
+    composite = [[MASCompositeConstraint alloc] initWithChildren:children];
+    composite.delegate = delegate;
 });
 
 it(@"should complete children", ^{
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeSize];
-    composite.delegate = delegate;
     MAS_VIEW *newView = MAS_VIEW.new;
 
     //first equality statement
@@ -117,8 +67,6 @@ it(@"should complete children", ^{
 });
 
 it(@"should not remove on install", ^{
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeSize];
-    composite.delegate = delegate;
     MAS_VIEW *newView = MAS_VIEW.new;
     [superview addSubview:newView];
 
@@ -131,9 +79,6 @@ it(@"should not remove on install", ^{
 });
 
 it(@"should spawn child composite constraints", ^{
-    composite = [[MASCompositeConstraint alloc] initWithView:view type:MASCompositeConstraintTypeSize];
-    composite.delegate = delegate;
-
     MAS_VIEW *otherView = MAS_VIEW.new;
     [superview addSubview:otherView];
     composite.lessThanOrEqualTo(@[@2, otherView]);

+ 97 - 0
MasonryTests/MASConstraintMakerSpec.m

@@ -0,0 +1,97 @@
+//
+//  MASConstraintMakerSpec.m
+//  Masonry
+//
+//  Created by Jonas Budelmann on 25/08/13.
+//  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
+//
+
+#import "MASConstraintMaker.h"
+#import "MASCompositeConstraint.h"
+#import "MASViewConstraint.h"
+
+@interface MASConstraintMaker () <MASConstraintDelegate>
+
+@property (nonatomic, weak) MAS_VIEW *view;
+@property (nonatomic, strong) NSMutableArray *constraints;
+
+@end
+
+@interface MASCompositeConstraint ()
+
+@property (nonatomic, strong) NSMutableArray *childConstraints;
+
+@end
+
+SpecBegin(MASConstraintMaker)
+
+__block MASConstraintMaker *maker;
+__block MAS_VIEW *superview;
+__block MAS_VIEW *view;
+__block MASCompositeConstraint *composite;
+
+beforeEach(^{
+    composite = nil;
+    view = MAS_VIEW.new;
+    superview = MAS_VIEW.new;
+    [superview addSubview:view];
+
+    maker = [[MASConstraintMaker alloc] initWithView:view];
+});
+
+it(@"should create centerY and centerX children", ^{
+    composite = maker.center;
+
+    expect(composite.childConstraints).to.haveCountOf(2);
+
+    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeCenterX);
+
+    viewConstraint = [composite.childConstraints objectAtIndex:1];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeCenterY);
+});
+
+it(@"should create top, left, bottom, right children", ^{
+    MAS_VIEW *newView = MAS_VIEW.new;
+    composite = maker.edges;
+    composite.equalTo(newView);
+
+    expect(composite.childConstraints).to.haveCountOf(4);
+
+    //top
+    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeTop);
+
+    //left
+    viewConstraint = [composite.childConstraints objectAtIndex:1];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeLeft);
+
+    //bottom
+    viewConstraint = [composite.childConstraints objectAtIndex:2];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeBottom);
+
+    //right
+    viewConstraint = [composite.childConstraints objectAtIndex:3];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeRight);
+});
+
+it(@"should create width and height children", ^{
+    composite = maker.size;
+    expect(composite.childConstraints).to.haveCountOf(2);
+
+    MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
+
+    viewConstraint = [composite.childConstraints objectAtIndex:1];
+    expect(viewConstraint.firstViewAttribute.view).to.beIdenticalTo(maker.view);
+    expect(viewConstraint.firstViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
+});
+
+SpecEnd

+ 1 - 0
MasonryTests/MASViewConstraintSpec.m

@@ -14,6 +14,7 @@
 
 @interface MASViewConstraint ()
 
+@property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
 @property (nonatomic, assign) NSLayoutRelation layoutRelation;
 @property (nonatomic, assign) MASLayoutPriority layoutPriority;
 @property (nonatomic, assign) CGFloat layoutMultiplier;