motion-kit 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/motion-kit-tvos/deprecated.rb +31 -0
  4. data/lib/motion-kit-tvos/dummy.rb +93 -0
  5. data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
  6. data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
  7. data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
  8. data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
  9. data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
  10. data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
  11. data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
  12. data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
  13. data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
  14. data/lib/motion-kit-tvos/ios_util.rb +24 -0
  15. data/lib/motion-kit.rb +2 -0
  16. data/lib/motion-kit/version.rb +1 -1
  17. data/spec/tvos/apply_styles_spec.rb +37 -0
  18. data/spec/tvos/autoresizing_helper_spec.rb +240 -0
  19. data/spec/tvos/calayer_spec.rb +23 -0
  20. data/spec/tvos/calculate_spec.rb +322 -0
  21. data/spec/tvos/calculator_spec.rb +31 -0
  22. data/spec/tvos/child_layouts_spec.rb +65 -0
  23. data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
  24. data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
  25. data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
  26. data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
  27. data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  28. data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
  29. data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
  30. data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
  31. data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
  32. data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
  33. data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
  34. data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
  35. data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
  36. data/spec/tvos/create_layout_spec.rb +40 -0
  37. data/spec/tvos/custom_layout_spec.rb +13 -0
  38. data/spec/tvos/custom_root_layout_spec.rb +57 -0
  39. data/spec/tvos/deferred_spec.rb +89 -0
  40. data/spec/tvos/device_helpers_spec.rb +58 -0
  41. data/spec/tvos/frame_helper_spec.rb +1160 -0
  42. data/spec/tvos/layer_layout_spec.rb +36 -0
  43. data/spec/tvos/layout_extensions_spec.rb +70 -0
  44. data/spec/tvos/layout_spec.rb +57 -0
  45. data/spec/tvos/layout_state_spec.rb +27 -0
  46. data/spec/tvos/memory_leak_spec.rb +74 -0
  47. data/spec/tvos/motion_kit_id_spec.rb +15 -0
  48. data/spec/tvos/motionkit_util_spec.rb +15 -0
  49. data/spec/tvos/nearest_spec.rb +80 -0
  50. data/spec/tvos/objc_selectors_spec.rb +10 -0
  51. data/spec/tvos/orientation_helper_specs.rb +67 -0
  52. data/spec/tvos/parent_layout_spec.rb +19 -0
  53. data/spec/tvos/parent_spec.rb +45 -0
  54. data/spec/tvos/prev_next_spec.rb +153 -0
  55. data/spec/tvos/reapply_frame.rb +64 -0
  56. data/spec/tvos/relative_layout.spec.rb +31 -0
  57. data/spec/tvos/remove_layout_spec.rb +28 -0
  58. data/spec/tvos/root_layout_spec.rb +53 -0
  59. data/spec/tvos/setters_spec.rb +63 -0
  60. data/spec/tvos/uibutton_layout_spec.rb +37 -0
  61. data/spec/tvos/uitextfield_spec.rb +14 -0
  62. data/spec/tvos/view_attr_spec.rb +32 -0
  63. metadata +118 -8
@@ -0,0 +1,72 @@
1
+ describe 'Constraints - placeholder helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @view = @layout.context(UIView.new) do
6
+ @first = @layout.add UILabel.new, :label do
7
+ @layout.text 'first'
8
+ end
9
+ @nth = @layout.add UILabel.new, :label do
10
+ @layout.text 'nth'
11
+ end
12
+ @last = @layout.add UILabel.new, :label do
13
+ @layout.text 'last'
14
+ end
15
+ end
16
+ end
17
+
18
+ it 'should return :first' do
19
+ @layout.context(@view) do
20
+ @layout.constraints do
21
+ @constraint = @layout.x.equals(@layout.first(:label))
22
+ end
23
+ end
24
+
25
+ resolved = @constraint.resolve_all(@layout, @view)
26
+ resolved.length.should == 1
27
+ resolved[0].firstItem.should == @view
28
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
29
+ resolved[0].relation.should == NSLayoutRelationEqual
30
+ resolved[0].secondItem.should == @first
31
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
32
+ resolved[0].multiplier.should == 1
33
+ resolved[0].constant.should == 0
34
+ end
35
+
36
+ it 'should return :nth' do
37
+ @layout.context(@view) do
38
+ @layout.constraints do
39
+ @constraint = @layout.x.equals(@layout.nth(:label, 1))
40
+ end
41
+ end
42
+
43
+ resolved = @constraint.resolve_all(@layout, @view)
44
+ resolved.length.should == 1
45
+ resolved[0].firstItem.should == @view
46
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
47
+ resolved[0].relation.should == NSLayoutRelationEqual
48
+ resolved[0].secondItem.should == @nth
49
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
50
+ resolved[0].multiplier.should == 1
51
+ resolved[0].constant.should == 0
52
+ end
53
+
54
+ it 'should return :last' do
55
+ @layout.context(@view) do
56
+ @layout.constraints do
57
+ @constraint = @layout.x.equals(@layout.last(:label))
58
+ end
59
+ end
60
+
61
+ resolved = @constraint.resolve_all(@layout, @view)
62
+ resolved.length.should == 1
63
+ resolved[0].firstItem.should == @view
64
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
65
+ resolved[0].relation.should == NSLayoutRelationEqual
66
+ resolved[0].secondItem.should == @last
67
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
68
+ resolved[0].multiplier.should == 1
69
+ resolved[0].constant.should == 0
70
+ end
71
+
72
+ end
@@ -0,0 +1,19 @@
1
+ describe 'Constraints - priority lookup' do
2
+
3
+ it 'should return 1000' do
4
+ MotionKit::Constraint.priority_lookup(:required).should == 1000
5
+ MotionKit::Constraint.priority_lookup(1000).should == 1000
6
+ end
7
+
8
+ it 'should return 250' do
9
+ MotionKit::Constraint.priority_lookup(:low).should == 250
10
+ MotionKit::Constraint.priority_lookup(250).should == 250
11
+ end
12
+
13
+ it 'should raise InvalidPriorityError' do
14
+ -> do
15
+ MotionKit::Constraint.priority_lookup(:foo)
16
+ end.should.raise(MotionKit::InvalidPriorityError)
17
+ end
18
+
19
+ end
@@ -0,0 +1,27 @@
1
+ describe 'Constraints - relationship lookup' do
2
+
3
+ it 'should return NSLayoutRelationEqual' do
4
+ MotionKit::Constraint.relationship_lookup(:equal).should == NSLayoutRelationEqual
5
+ MotionKit::Constraint.relationship_lookup(NSLayoutRelationEqual).should == NSLayoutRelationEqual
6
+ end
7
+
8
+ it 'should return NSLayoutRelationGreaterThanOrEqual' do
9
+ MotionKit::Constraint.relationship_lookup(:gte).should == NSLayoutRelationGreaterThanOrEqual
10
+ MotionKit::Constraint.relationship_lookup(NSLayoutRelationGreaterThanOrEqual).should == NSLayoutRelationGreaterThanOrEqual
11
+ end
12
+
13
+ it 'should raise InvalidRelationshipError' do
14
+ -> do
15
+ MotionKit::Constraint.relationship_lookup(:foo)
16
+ end.should.raise(MotionKit::InvalidRelationshipError)
17
+ end
18
+
19
+ it 'should reverse NSLayoutRelationEqual' do
20
+ MotionKit::Constraint.relationship_reverse(NSLayoutRelationEqual).should == :equal
21
+ end
22
+
23
+ it 'should reverse NSLayoutRelationGreaterThanOrEqual' do
24
+ MotionKit::Constraint.relationship_reverse(NSLayoutRelationGreaterThanOrEqual).should == :gte
25
+ end
26
+
27
+ end
@@ -0,0 +1,276 @@
1
+ describe 'Constraints - Relative corners helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @constraint = nil
6
+ @view = UIView.new
7
+ @parent_view = UIView.new
8
+ @parent_view.addSubview(@view)
9
+ @another_view = nil
10
+ end
11
+
12
+ it 'should support `top_left [10, 10]`' do
13
+ @layout.context(@view) do
14
+ @layout.constraints do
15
+ @constraint = @layout.top_left([10, 10])
16
+ end
17
+ end
18
+
19
+ @constraint.constant.should == [10, 10]
20
+ @constraint.relationship.should == :equal
21
+ @constraint.multiplier.should == [1, 1]
22
+ @constraint.relative_to.should == :superview
23
+ @constraint.attribute.should == [:left, :top]
24
+ @constraint.attribute2.should == [:left, :top]
25
+
26
+ resolved = @constraint.resolve_all(@layout, @view)
27
+ resolved.length.should == 2
28
+ resolved[0].firstItem.should == @view
29
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
30
+ resolved[0].relation.should == NSLayoutRelationEqual
31
+ resolved[0].secondItem.should == @parent_view
32
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
33
+ resolved[0].multiplier.should == 1
34
+ resolved[0].constant.should == 10
35
+
36
+ resolved[1].firstItem.should == @view
37
+ resolved[1].firstAttribute.should == NSLayoutAttributeTop
38
+ resolved[1].relation.should == NSLayoutRelationEqual
39
+ resolved[1].secondItem.should == @parent_view
40
+ resolved[1].secondAttribute.should == NSLayoutAttributeTop
41
+ resolved[1].multiplier.should == 1
42
+ resolved[1].constant.should == 10
43
+ end
44
+ it 'should support `top_left.equals(:another_view).plus(10).plus([5, 10])`' do
45
+ @layout.context(@view) do
46
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
47
+ @layout.constraints do
48
+ @constraint = @layout.top_left.equals(:another_view).plus(10).plus([5, 10])
49
+ end
50
+ end
51
+
52
+ @constraint.constant.should == [15, 20]
53
+ @constraint.relationship.should == :equal
54
+ @constraint.multiplier.should == [1, 1]
55
+ @constraint.relative_to.should == :another_view
56
+ @constraint.attribute.should == [:left, :top]
57
+ @constraint.attribute2.should == [:left, :top]
58
+
59
+ resolved = @constraint.resolve_all(@layout, @view)
60
+ resolved.length.should == 2
61
+ resolved[0].firstItem.should == @view
62
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
63
+ resolved[0].relation.should == NSLayoutRelationEqual
64
+ resolved[0].secondItem.should == @another_view
65
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
66
+ resolved[0].multiplier.should == 1
67
+ resolved[0].constant.should == 15
68
+
69
+ resolved[1].firstItem.should == @view
70
+ resolved[1].firstAttribute.should == NSLayoutAttributeTop
71
+ resolved[1].relation.should == NSLayoutRelationEqual
72
+ resolved[1].secondItem.should == @another_view
73
+ resolved[1].secondAttribute.should == NSLayoutAttributeTop
74
+ resolved[1].multiplier.should == 1
75
+ resolved[1].constant.should == 20
76
+ end
77
+
78
+ it 'should support `top_right [10, 10]`' do
79
+ @layout.context(@view) do
80
+ @layout.constraints do
81
+ @constraint = @layout.top_right([10, 10])
82
+ end
83
+ end
84
+
85
+ @constraint.constant.should == [10, 10]
86
+ @constraint.relationship.should == :equal
87
+ @constraint.multiplier.should == [1, 1]
88
+ @constraint.relative_to.should == :superview
89
+ @constraint.attribute.should == [:right, :top]
90
+ @constraint.attribute2.should == [:right, :top]
91
+
92
+ resolved = @constraint.resolve_all(@layout, @view)
93
+ resolved.length.should == 2
94
+ resolved[0].firstItem.should == @view
95
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
96
+ resolved[0].relation.should == NSLayoutRelationEqual
97
+ resolved[0].secondItem.should == @parent_view
98
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
99
+ resolved[0].multiplier.should == 1
100
+ resolved[0].constant.should == 10
101
+
102
+ resolved[1].firstItem.should == @view
103
+ resolved[1].firstAttribute.should == NSLayoutAttributeTop
104
+ resolved[1].relation.should == NSLayoutRelationEqual
105
+ resolved[1].secondItem.should == @parent_view
106
+ resolved[1].secondAttribute.should == NSLayoutAttributeTop
107
+ resolved[1].multiplier.should == 1
108
+ resolved[1].constant.should == 10
109
+ end
110
+ it 'should support `top_right.equals(:another_view).plus(10).plus([5, 10])`' do
111
+ @layout.context(@view) do
112
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
113
+ @layout.constraints do
114
+ @constraint = @layout.top_right.equals(:another_view).plus(10).plus([5, 10])
115
+ end
116
+ end
117
+
118
+ @constraint.constant.should == [15, 20]
119
+ @constraint.relationship.should == :equal
120
+ @constraint.multiplier.should == [1, 1]
121
+ @constraint.relative_to.should == :another_view
122
+ @constraint.attribute.should == [:right, :top]
123
+ @constraint.attribute2.should == [:right, :top]
124
+
125
+ resolved = @constraint.resolve_all(@layout, @view)
126
+ resolved.length.should == 2
127
+ resolved[0].firstItem.should == @view
128
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
129
+ resolved[0].relation.should == NSLayoutRelationEqual
130
+ resolved[0].secondItem.should == @another_view
131
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
132
+ resolved[0].multiplier.should == 1
133
+ resolved[0].constant.should == 15
134
+
135
+ resolved[1].firstItem.should == @view
136
+ resolved[1].firstAttribute.should == NSLayoutAttributeTop
137
+ resolved[1].relation.should == NSLayoutRelationEqual
138
+ resolved[1].secondItem.should == @another_view
139
+ resolved[1].secondAttribute.should == NSLayoutAttributeTop
140
+ resolved[1].multiplier.should == 1
141
+ resolved[1].constant.should == 20
142
+ end
143
+
144
+ it 'should support `bottom_left [10, 10]`' do
145
+ @layout.context(@view) do
146
+ @layout.constraints do
147
+ @constraint = @layout.bottom_left([10, 10])
148
+ end
149
+ end
150
+
151
+ @constraint.constant.should == [10, 10]
152
+ @constraint.relationship.should == :equal
153
+ @constraint.multiplier.should == [1, 1]
154
+ @constraint.relative_to.should == :superview
155
+ @constraint.attribute.should == [:left, :bottom]
156
+ @constraint.attribute2.should == [:left, :bottom]
157
+
158
+ resolved = @constraint.resolve_all(@layout, @view)
159
+ resolved.length.should == 2
160
+ resolved[0].firstItem.should == @view
161
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
162
+ resolved[0].relation.should == NSLayoutRelationEqual
163
+ resolved[0].secondItem.should == @parent_view
164
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
165
+ resolved[0].multiplier.should == 1
166
+ resolved[0].constant.should == 10
167
+
168
+ resolved[1].firstItem.should == @view
169
+ resolved[1].firstAttribute.should == NSLayoutAttributeBottom
170
+ resolved[1].relation.should == NSLayoutRelationEqual
171
+ resolved[1].secondItem.should == @parent_view
172
+ resolved[1].secondAttribute.should == NSLayoutAttributeBottom
173
+ resolved[1].multiplier.should == 1
174
+ resolved[1].constant.should == 10
175
+ end
176
+ it 'should support `bottom_left.equals(:another_view).plus(10).plus([5, 10])`' do
177
+ @layout.context(@view) do
178
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
179
+ @layout.constraints do
180
+ @constraint = @layout.bottom_left.equals(:another_view).plus(10).plus([5, 10])
181
+ end
182
+ end
183
+
184
+ @constraint.constant.should == [15, 20]
185
+ @constraint.relationship.should == :equal
186
+ @constraint.multiplier.should == [1, 1]
187
+ @constraint.relative_to.should == :another_view
188
+ @constraint.attribute.should == [:left, :bottom]
189
+ @constraint.attribute2.should == [:left, :bottom]
190
+
191
+ resolved = @constraint.resolve_all(@layout, @view)
192
+ resolved.length.should == 2
193
+ resolved[0].firstItem.should == @view
194
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
195
+ resolved[0].relation.should == NSLayoutRelationEqual
196
+ resolved[0].secondItem.should == @another_view
197
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
198
+ resolved[0].multiplier.should == 1
199
+ resolved[0].constant.should == 15
200
+
201
+ resolved[1].firstItem.should == @view
202
+ resolved[1].firstAttribute.should == NSLayoutAttributeBottom
203
+ resolved[1].relation.should == NSLayoutRelationEqual
204
+ resolved[1].secondItem.should == @another_view
205
+ resolved[1].secondAttribute.should == NSLayoutAttributeBottom
206
+ resolved[1].multiplier.should == 1
207
+ resolved[1].constant.should == 20
208
+ end
209
+
210
+ it 'should support `bottom_right [10, 10]`' do
211
+ @layout.context(@view) do
212
+ @layout.constraints do
213
+ @constraint = @layout.bottom_right([10, 10])
214
+ end
215
+ end
216
+
217
+ @constraint.constant.should == [10, 10]
218
+ @constraint.relationship.should == :equal
219
+ @constraint.multiplier.should == [1, 1]
220
+ @constraint.relative_to.should == :superview
221
+ @constraint.attribute.should == [:right, :bottom]
222
+ @constraint.attribute2.should == [:right, :bottom]
223
+
224
+ resolved = @constraint.resolve_all(@layout, @view)
225
+ resolved.length.should == 2
226
+ resolved[0].firstItem.should == @view
227
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
228
+ resolved[0].relation.should == NSLayoutRelationEqual
229
+ resolved[0].secondItem.should == @parent_view
230
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
231
+ resolved[0].multiplier.should == 1
232
+ resolved[0].constant.should == 10
233
+
234
+ resolved[1].firstItem.should == @view
235
+ resolved[1].firstAttribute.should == NSLayoutAttributeBottom
236
+ resolved[1].relation.should == NSLayoutRelationEqual
237
+ resolved[1].secondItem.should == @parent_view
238
+ resolved[1].secondAttribute.should == NSLayoutAttributeBottom
239
+ resolved[1].multiplier.should == 1
240
+ resolved[1].constant.should == 10
241
+ end
242
+ it 'should support `bottom_right.equals(:another_view).plus(10).plus([5, 10])`' do
243
+ @layout.context(@view) do
244
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
245
+ @layout.constraints do
246
+ @constraint = @layout.bottom_right.equals(:another_view).plus(10).plus([5, 10])
247
+ end
248
+ end
249
+
250
+ @constraint.constant.should == [15, 20]
251
+ @constraint.relationship.should == :equal
252
+ @constraint.multiplier.should == [1, 1]
253
+ @constraint.relative_to.should == :another_view
254
+ @constraint.attribute.should == [:right, :bottom]
255
+ @constraint.attribute2.should == [:right, :bottom]
256
+
257
+ resolved = @constraint.resolve_all(@layout, @view)
258
+ resolved.length.should == 2
259
+ resolved[0].firstItem.should == @view
260
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
261
+ resolved[0].relation.should == NSLayoutRelationEqual
262
+ resolved[0].secondItem.should == @another_view
263
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
264
+ resolved[0].multiplier.should == 1
265
+ resolved[0].constant.should == 15
266
+
267
+ resolved[1].firstItem.should == @view
268
+ resolved[1].firstAttribute.should == NSLayoutAttributeBottom
269
+ resolved[1].relation.should == NSLayoutRelationEqual
270
+ resolved[1].secondItem.should == @another_view
271
+ resolved[1].secondAttribute.should == NSLayoutAttributeBottom
272
+ resolved[1].multiplier.should == 1
273
+ resolved[1].constant.should == 20
274
+ end
275
+
276
+ end
@@ -0,0 +1,113 @@
1
+ describe 'Constraints - Relative location helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ @constraint = nil
6
+ @view = UIView.new
7
+ @parent_view = UIView.new
8
+ @parent_view.addSubview(@view)
9
+ @another_view = nil
10
+ end
11
+
12
+ it 'should support `above(:another_view)`' do
13
+ @layout.context(@view) do
14
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
15
+ @layout.constraints do
16
+ @constraint = @layout.above(:another_view)
17
+ end
18
+ end
19
+
20
+ @constraint.constant.should == 0
21
+ @constraint.relationship.should == :equal
22
+ @constraint.multiplier.should == 1
23
+ @constraint.relative_to.should == :another_view
24
+ @constraint.attribute.should == :bottom
25
+ @constraint.attribute2.should == :top
26
+
27
+ resolved = @constraint.resolve_all(@layout, @view)
28
+ resolved.length.should == 1
29
+ resolved[0].firstItem.should == @view
30
+ resolved[0].firstAttribute.should == NSLayoutAttributeBottom
31
+ resolved[0].relation.should == NSLayoutRelationEqual
32
+ resolved[0].secondItem.should == @another_view
33
+ resolved[0].secondAttribute.should == NSLayoutAttributeTop
34
+ resolved[0].multiplier.should == 1
35
+ resolved[0].constant.should == 0
36
+ end
37
+ it 'should support `below(:another_view)`' do
38
+ @layout.context(@view) do
39
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
40
+ @layout.constraints do
41
+ @constraint = @layout.below(:another_view)
42
+ end
43
+ end
44
+
45
+ @constraint.constant.should == 0
46
+ @constraint.relationship.should == :equal
47
+ @constraint.multiplier.should == 1
48
+ @constraint.relative_to.should == :another_view
49
+ @constraint.attribute.should == :top
50
+ @constraint.attribute2.should == :bottom
51
+
52
+ resolved = @constraint.resolve_all(@layout, @view)
53
+ resolved.length.should == 1
54
+ resolved[0].firstItem.should == @view
55
+ resolved[0].firstAttribute.should == NSLayoutAttributeTop
56
+ resolved[0].relation.should == NSLayoutRelationEqual
57
+ resolved[0].secondItem.should == @another_view
58
+ resolved[0].secondAttribute.should == NSLayoutAttributeBottom
59
+ resolved[0].multiplier.should == 1
60
+ resolved[0].constant.should == 0
61
+ end
62
+ it 'should support `before(:another_view)`' do
63
+ @layout.context(@view) do
64
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
65
+ @layout.constraints do
66
+ @constraint = @layout.before(:another_view)
67
+ end
68
+ end
69
+
70
+ @constraint.constant.should == 0
71
+ @constraint.relationship.should == :equal
72
+ @constraint.multiplier.should == 1
73
+ @constraint.relative_to.should == :another_view
74
+ @constraint.attribute.should == :right
75
+ @constraint.attribute2.should == :left
76
+
77
+ resolved = @constraint.resolve_all(@layout, @view)
78
+ resolved.length.should == 1
79
+ resolved[0].firstItem.should == @view
80
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
81
+ resolved[0].relation.should == NSLayoutRelationEqual
82
+ resolved[0].secondItem.should == @another_view
83
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
84
+ resolved[0].multiplier.should == 1
85
+ resolved[0].constant.should == 0
86
+ end
87
+ it 'should support `after(:another_view)`' do
88
+ @layout.context(@view) do
89
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
90
+ @layout.constraints do
91
+ @constraint = @layout.after(:another_view)
92
+ end
93
+ end
94
+
95
+ @constraint.constant.should == 0
96
+ @constraint.relationship.should == :equal
97
+ @constraint.multiplier.should == 1
98
+ @constraint.relative_to.should == :another_view
99
+ @constraint.attribute.should == :left
100
+ @constraint.attribute2.should == :right
101
+
102
+ resolved = @constraint.resolve_all(@layout, @view)
103
+ resolved.length.should == 1
104
+ resolved[0].firstItem.should == @view
105
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
106
+ resolved[0].relation.should == NSLayoutRelationEqual
107
+ resolved[0].secondItem.should == @another_view
108
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
109
+ resolved[0].multiplier.should == 1
110
+ resolved[0].constant.should == 0
111
+ end
112
+
113
+ end