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,62 @@
1
+ class MagicSizeView < UIView
2
+
3
+ def intrinsicContentSize
4
+ CGSize.new(200, 100)
5
+ end
6
+
7
+ end
8
+
9
+
10
+ describe 'Constraints - Size helpers' do
11
+
12
+ before do
13
+ @layout = MK::Layout.new
14
+ @constraint = nil
15
+ @view = MagicSizeView.new
16
+ end
17
+
18
+ it 'should support `height :scale`' do
19
+ @layout.context(@view) do
20
+ @layout.constraints do
21
+ @constraint = @layout.height(:scale)
22
+ end
23
+ end
24
+
25
+ @constraint.target.should == @view
26
+ @constraint.attribute.should == :height
27
+ @constraint.attribute2.should == :width
28
+ @constraint.relationship.should == :equal
29
+ @constraint.multiplier.should == 0.5
30
+ nsconstraint = @constraint.resolve_all(@layout, @view).first
31
+ nsconstraint.firstItem.should == @view
32
+ nsconstraint.firstAttribute.should == NSLayoutAttributeHeight
33
+ nsconstraint.secondItem.should == @view
34
+ nsconstraint.secondAttribute.should == NSLayoutAttributeWidth
35
+ nsconstraint.relation.should == NSLayoutRelationEqual
36
+ nsconstraint.multiplier.should == 0.5
37
+ nsconstraint.constant.should == 0
38
+ end
39
+
40
+ it 'should support `width :scale`' do
41
+ @layout.context(@view) do
42
+ @layout.constraints do
43
+ @constraint = @layout.width(:scale)
44
+ end
45
+ end
46
+
47
+ @constraint.target.should == @view
48
+ @constraint.attribute.should == :width
49
+ @constraint.attribute2.should == :height
50
+ @constraint.relationship.should == :equal
51
+ @constraint.multiplier.should == 2.0
52
+ nsconstraint = @constraint.resolve_all(@layout, @view).first
53
+ nsconstraint.firstItem.should == @view
54
+ nsconstraint.firstAttribute.should == NSLayoutAttributeWidth
55
+ nsconstraint.secondItem.should == @view
56
+ nsconstraint.secondAttribute.should == NSLayoutAttributeHeight
57
+ nsconstraint.relation.should == NSLayoutRelationEqual
58
+ nsconstraint.multiplier.should == 2.0
59
+ nsconstraint.constant.should == 0
60
+ end
61
+
62
+ end
@@ -0,0 +1,2755 @@
1
+ describe 'Constraints - Simple helpers' do
2
+
3
+ before do
4
+ @layout = MotionKit::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
+ describe '`x/left` support' do
13
+ it 'should support `x 10`' do
14
+ @layout.context(@view) do
15
+ @layout.constraints do
16
+ @constraint = @layout.x(10)
17
+ end
18
+ end
19
+
20
+ @constraint.constant.should == 10
21
+ @constraint.relationship.should == :equal
22
+ @constraint.multiplier.should == 1
23
+ @constraint.relative_to.should == :superview
24
+ @constraint.attribute.should == :left
25
+ @constraint.attribute2.should == :left
26
+
27
+ resolved = @constraint.resolve_all(@layout, @view)
28
+ resolved.length.should == 1
29
+ resolved[0].firstItem.should.be.kind_of(UIView)
30
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
31
+ resolved[0].relation.should == NSLayoutRelationEqual
32
+ resolved[0].secondItem.should == @parent_view
33
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
34
+ resolved[0].multiplier.should == 1
35
+ resolved[0].constant.should == 10
36
+ end
37
+ it 'should update the constraint' do
38
+ @layout.context(@view) do
39
+ @layout.constraints do
40
+ @constraint = @layout.x(10)
41
+ end
42
+ end
43
+
44
+ @constraint.constant.should == 10
45
+
46
+ resolved = @constraint.resolve_all(@layout, @view)
47
+ resolved.length.should == 1
48
+ resolved[0].constant.should == 10
49
+
50
+ @constraint.constant = 100
51
+ resolved[0].constant.should == 100
52
+ end
53
+ it 'should support `x.is == 10`' do
54
+ @layout.context(@view) do
55
+ @layout.constraints do
56
+ @constraint = @layout.x.is == 10
57
+ end
58
+ end
59
+
60
+ @constraint.constant.should == 10
61
+ @constraint.relationship.should == :equal
62
+ @constraint.multiplier.should == 1
63
+ @constraint.relative_to.should == :superview
64
+ @constraint.attribute.should == :left
65
+ @constraint.attribute2.should == :left
66
+ end
67
+ it 'should support `x.is <= 10`' do
68
+ @layout.context(@view) do
69
+ @layout.constraints do
70
+ @constraint = @layout.x.is <= 10
71
+ end
72
+ end
73
+
74
+ @constraint.constant.should == 10
75
+ @constraint.relationship.should == :lte
76
+ @constraint.multiplier.should == 1
77
+ @constraint.relative_to.should == :superview
78
+ @constraint.attribute.should == :left
79
+ @constraint.attribute2.should == :left
80
+ end
81
+ it 'should support `min_x.is == 10`' do
82
+ @layout.context(@view) do
83
+ @layout.constraints do
84
+ @constraint = @layout.min_x.is == 10
85
+ end
86
+ end
87
+
88
+ @constraint.constant.should == 10
89
+ @constraint.relationship.should == :gte
90
+ @constraint.multiplier.should == 1
91
+ @constraint.relative_to.should == :superview
92
+ @constraint.attribute.should == :left
93
+ @constraint.attribute2.should == :left
94
+ end
95
+ it 'should support `(x.is >= 10).priority(:low)`' do
96
+ @layout.context(@view) do
97
+ @layout.constraints do
98
+ @constraint = (@layout.x.is >= 10).priority(:low)
99
+ end
100
+ end
101
+
102
+ @constraint.constant.should == 10
103
+ @constraint.relationship.should == :gte
104
+ @constraint.multiplier.should == 1
105
+ @constraint.relative_to.should == :superview
106
+ @constraint.attribute.should == :left
107
+ @constraint.attribute2.should == :left
108
+ @constraint.priority.should == :low
109
+ end
110
+ it 'should support `min_x 10`' do
111
+ @layout.context(@view) do
112
+ @layout.constraints do
113
+ @constraint = @layout.min_x(10)
114
+ end
115
+ end
116
+
117
+ @constraint.constant.should == 10
118
+ @constraint.relationship.should == :gte
119
+ @constraint.multiplier.should == 1
120
+ @constraint.relative_to.should == :superview
121
+ @constraint.attribute.should == :left
122
+ @constraint.attribute2.should == :left
123
+ end
124
+ it 'should support `min_x.equals "50%"`' do
125
+ @layout.context(@parent_view) do
126
+ @view = @layout.add(UIView.new) do
127
+ @layout.constraints do
128
+ @constraint = @layout.min_x('50%')
129
+ end
130
+ end
131
+ end
132
+
133
+ @constraint.constant.should == 0
134
+ @constraint.relationship.should == :gte
135
+ @constraint.multiplier.should == 0.5
136
+ @constraint.relative_to.should == :superview
137
+ @constraint.attribute.should == :left
138
+ @constraint.attribute2.should == :left
139
+ end
140
+ it 'should support `min_x.equals("50%").of(:another_view)`' do
141
+ @layout.context(@parent_view) do
142
+ @view = @layout.add(UIView.new) do
143
+ @layout.constraints do
144
+ @constraint = @layout.min_x.equals('50%').of(:another_view)
145
+ end
146
+ end
147
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
148
+ end
149
+
150
+ @constraint.constant.should == 0
151
+ @constraint.relationship.should == :gte
152
+ @constraint.multiplier.should == 0.5
153
+ @constraint.relative_to.should == :another_view
154
+ @constraint.attribute.should == :left
155
+ @constraint.attribute2.should == :left
156
+ end
157
+ it 'should support `min_x.equals("50%").of(:another_view, :right)`' do
158
+ @layout.context(@parent_view) do
159
+ @view = @layout.add(UIView.new) do
160
+ @layout.constraints do
161
+ @constraint = @layout.min_x.equals('50%').of(:another_view, :right)
162
+ end
163
+ end
164
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
165
+ end
166
+
167
+ @constraint.constant.should == 0
168
+ @constraint.relationship.should == :gte
169
+ @constraint.multiplier.should == 0.5
170
+ @constraint.relative_to.should == :another_view
171
+ @constraint.attribute.should == :left
172
+ @constraint.attribute2.should == :right
173
+ end
174
+ it 'should support `max_x 10`' do
175
+ @layout.context(@view) do
176
+ @layout.constraints do
177
+ @constraint = @layout.max_x(10)
178
+ end
179
+ end
180
+
181
+ @constraint.constant.should == 10
182
+ @constraint.relationship.should == :lte
183
+ @constraint.multiplier.should == 1
184
+ @constraint.relative_to.should == :superview
185
+ @constraint.attribute.should == :left
186
+ @constraint.attribute2.should == :left
187
+ end
188
+ it 'should support `x.equals(:another_view[, :left])`' do
189
+ @layout.context(@view) do
190
+ @layout.constraints do
191
+ @constraint = @layout.x.equals(:another_view)
192
+ end
193
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
194
+ end
195
+
196
+ @constraint.constant.should == 0
197
+ @constraint.relationship.should == :equal
198
+ @constraint.multiplier.should == 1
199
+ @constraint.relative_to.should == :another_view
200
+ @constraint.attribute.should == :left
201
+ @constraint.attribute2.should == :left
202
+ end
203
+ it 'should support `x.equals(:another_view).plus(10).plus(20)`' do
204
+ @layout.context(@view) do
205
+ @layout.constraints do
206
+ @constraint = @layout.x.equals(:another_view).plus(10).plus(20)
207
+ end
208
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
209
+ end
210
+
211
+ @constraint.constant.should == 30
212
+ @constraint.relationship.should == :equal
213
+ @constraint.multiplier.should == 1
214
+ @constraint.relative_to.should == :another_view
215
+ @constraint.attribute.should == :left
216
+ @constraint.attribute2.should == :left
217
+ end
218
+ it 'should support `x.equals(:another_view).minus(10)`' do
219
+ @layout.context(@view) do
220
+ @layout.constraints do
221
+ @constraint = @layout.x.equals(:another_view).minus(10)
222
+ end
223
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
224
+ end
225
+
226
+ @constraint.constant.should == -10
227
+ @constraint.relationship.should == :equal
228
+ @constraint.multiplier.should == 1
229
+ @constraint.relative_to.should == :another_view
230
+ @constraint.attribute.should == :left
231
+ @constraint.attribute2.should == :left
232
+ end
233
+ it 'should support `min_x.equals(:another_view[, :left])`' do
234
+ @layout.context(@view) do
235
+ @layout.constraints do
236
+ @constraint = @layout.min_x.equals(:another_view)
237
+ end
238
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
239
+ end
240
+
241
+ @constraint.constant.should == 0
242
+ @constraint.relationship.should == :gte
243
+ @constraint.multiplier.should == 1
244
+ @constraint.relative_to.should == :another_view
245
+ @constraint.attribute.should == :left
246
+ @constraint.attribute2.should == :left
247
+ end
248
+ it 'should support `max_x.equals(:another_view[, :left])`' do
249
+ @layout.context(@view) do
250
+ @layout.constraints do
251
+ @constraint = @layout.max_x.equals(:another_view)
252
+ end
253
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
254
+ end
255
+
256
+ @constraint.constant.should == 0
257
+ @constraint.relationship.should == :lte
258
+ @constraint.multiplier.should == 1
259
+ @constraint.relative_to.should == :another_view
260
+ @constraint.attribute.should == :left
261
+ @constraint.attribute2.should == :left
262
+ end
263
+ it 'should support `x.equals(:another_view, :right)`' do
264
+ @layout.context(@view) do
265
+ @layout.constraints do
266
+ @constraint = @layout.x.equals(:another_view, :right)
267
+ end
268
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
269
+ end
270
+
271
+ @constraint.constant.should == 0
272
+ @constraint.relationship.should == :equal
273
+ @constraint.multiplier.should == 1
274
+ @constraint.relative_to.should == :another_view
275
+ @constraint.attribute.should == :left
276
+ @constraint.attribute2.should == :right
277
+ end
278
+ it 'should support `min_x.equals(:another_view, :right)`' do
279
+ @layout.context(@view) do
280
+ @layout.constraints do
281
+ @constraint = @layout.min_x.equals(:another_view, :right)
282
+ end
283
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
284
+ end
285
+
286
+ @constraint.constant.should == 0
287
+ @constraint.relationship.should == :gte
288
+ @constraint.multiplier.should == 1
289
+ @constraint.relative_to.should == :another_view
290
+ @constraint.attribute.should == :left
291
+ @constraint.attribute2.should == :right
292
+ end
293
+ it 'should support `max_x.equals(:another_view, :right)`' do
294
+ @layout.context(@view) do
295
+ @layout.constraints do
296
+ @constraint = @layout.max_x.equals(:another_view, :right)
297
+ end
298
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
299
+ end
300
+
301
+ @constraint.constant.should == 0
302
+ @constraint.relationship.should == :lte
303
+ @constraint.multiplier.should == 1
304
+ @constraint.relative_to.should == :another_view
305
+ @constraint.attribute.should == :left
306
+ @constraint.attribute2.should == :right
307
+ end
308
+ it 'should support `x.equals(:another_view, :right).plus(10)`' do
309
+ @layout.context(@view) do
310
+ @layout.constraints do
311
+ @constraint = @layout.x.equals(:another_view, :right).plus(10)
312
+ end
313
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
314
+ end
315
+
316
+ @constraint.constant.should == 10
317
+ @constraint.relationship.should == :equal
318
+ @constraint.multiplier.should == 1
319
+ @constraint.relative_to.should == :another_view
320
+ @constraint.attribute.should == :left
321
+ @constraint.attribute2.should == :right
322
+ end
323
+ it 'should support `min_x.equals(:another_view, :right).plus(10)`' do
324
+ @layout.context(@view) do
325
+ @layout.constraints do
326
+ @constraint = @layout.min_x.equals(:another_view, :right).plus(10)
327
+ end
328
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
329
+ end
330
+
331
+ @constraint.constant.should == 10
332
+ @constraint.relationship.should == :gte
333
+ @constraint.multiplier.should == 1
334
+ @constraint.relative_to.should == :another_view
335
+ @constraint.attribute.should == :left
336
+ @constraint.attribute2.should == :right
337
+ end
338
+ it 'should support `max_x.equals(:another_view, :right).plus(10)`' do
339
+ @layout.context(@view) do
340
+ @layout.constraints do
341
+ @constraint = @layout.max_x.equals(:another_view, :right).plus(10)
342
+ end
343
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
344
+ end
345
+
346
+ @constraint.constant.should == 10
347
+ @constraint.relationship.should == :lte
348
+ @constraint.multiplier.should == 1
349
+ @constraint.relative_to.should == :another_view
350
+ @constraint.attribute.should == :left
351
+ @constraint.attribute2.should == :right
352
+ end
353
+ it 'should support `x.equals(:another_view).times(2).plus(10)`' do
354
+ @layout.context(@view) do
355
+ @layout.constraints do
356
+ @constraint = @layout.x.equals(:another_view).times(2).plus(10)
357
+ end
358
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
359
+ end
360
+
361
+ @constraint.constant.should == 10
362
+ @constraint.relationship.should == :equal
363
+ @constraint.multiplier.should == 2
364
+ @constraint.relative_to.should == :another_view
365
+ @constraint.attribute.should == :left
366
+ @constraint.attribute2.should == :left
367
+ end
368
+ it 'should support `x.equals(:another_view).times(2).times(3)`' do
369
+ @layout.context(@view) do
370
+ @layout.constraints do
371
+ @constraint = @layout.x.equals(:another_view).times(2).times(3)
372
+ end
373
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
374
+ end
375
+
376
+ @constraint.constant.should == 0
377
+ @constraint.relationship.should == :equal
378
+ @constraint.multiplier.should == 6
379
+ @constraint.relative_to.should == :another_view
380
+ @constraint.attribute.should == :left
381
+ @constraint.attribute2.should == :left
382
+ end
383
+ it 'should support `x.equals(:another_view).divided_by(2)`' do
384
+ @layout.context(@view) do
385
+ @layout.constraints do
386
+ @constraint = @layout.x.equals(:another_view).divided_by(2)
387
+ end
388
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
389
+ end
390
+
391
+ @constraint.constant.should == 0
392
+ @constraint.relationship.should == :equal
393
+ @constraint.multiplier.should == 0.5
394
+ @constraint.relative_to.should == :another_view
395
+ @constraint.attribute.should == :left
396
+ @constraint.attribute2.should == :left
397
+ end
398
+ it 'should support `min_x.equals(:another_view).times(2).plus(10)`' do
399
+ @layout.context(@view) do
400
+ @layout.constraints do
401
+ @constraint = @layout.min_x.equals(:another_view).times(2).plus(10)
402
+ end
403
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
404
+ end
405
+
406
+ @constraint.constant.should == 10
407
+ @constraint.relationship.should == :gte
408
+ @constraint.multiplier.should == 2
409
+ @constraint.relative_to.should == :another_view
410
+ @constraint.attribute.should == :left
411
+ @constraint.attribute2.should == :left
412
+ end
413
+ it 'should support `max_x.equals(:another_view).times(2).plus(10)`' do
414
+ @layout.context(@view) do
415
+ @layout.constraints do
416
+ @constraint = @layout.max_x.equals(:another_view).times(2).plus(10)
417
+ end
418
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
419
+ end
420
+
421
+ @constraint.constant.should == 10
422
+ @constraint.relationship.should == :lte
423
+ @constraint.multiplier.should == 2
424
+ @constraint.relative_to.should == :another_view
425
+ @constraint.attribute.should == :left
426
+ @constraint.attribute2.should == :left
427
+ end
428
+ it 'should support `left.equals(:another_view).times(2).plus(10)`' do
429
+ @layout.context(@view) do
430
+ @layout.constraints do
431
+ @constraint = @layout.left.equals(:another_view).times(2).plus(10)
432
+ end
433
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
434
+ end
435
+
436
+ @constraint.constant.should == 10
437
+ @constraint.relationship.should == :equal
438
+ @constraint.multiplier.should == 2
439
+ @constraint.relative_to.should == :another_view
440
+ @constraint.attribute.should == :left
441
+ @constraint.attribute2.should == :left
442
+ end
443
+ it 'should support `min_left.equals(:another_view).times(2).plus(10)`' do
444
+ @layout.context(@view) do
445
+ @layout.constraints do
446
+ @constraint = @layout.min_left.equals(:another_view).times(2).plus(10)
447
+ end
448
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
449
+ end
450
+
451
+ @constraint.constant.should == 10
452
+ @constraint.relationship.should == :gte
453
+ @constraint.multiplier.should == 2
454
+ @constraint.relative_to.should == :another_view
455
+ @constraint.attribute.should == :left
456
+ @constraint.attribute2.should == :left
457
+ end
458
+ it 'should support `max_left.equals(:another_view).times(2).plus(10)`' do
459
+ @layout.context(@view) do
460
+ @layout.constraints do
461
+ @constraint = @layout.max_left.equals(:another_view).times(2).plus(10)
462
+ end
463
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
464
+ end
465
+
466
+ @constraint.constant.should == 10
467
+ @constraint.relationship.should == :lte
468
+ @constraint.multiplier.should == 2
469
+ @constraint.relative_to.should == :another_view
470
+ @constraint.attribute.should == :left
471
+ @constraint.attribute2.should == :left
472
+
473
+ resolved = @constraint.resolve_all(@layout, @view)
474
+ resolved.length.should == 1
475
+ resolved[0].firstItem.should.be.kind_of(UIView)
476
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeft
477
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
478
+ resolved[0].secondItem.should == @another_view
479
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeft
480
+ resolved[0].multiplier.should == 2
481
+ resolved[0].constant.should == 10
482
+ end
483
+ end
484
+
485
+ describe '`center_x` support' do
486
+ it 'should support `center_x 10`' do
487
+ @layout.context(@view) do
488
+ @layout.constraints do
489
+ @constraint = @layout.center_x(10)
490
+ end
491
+ end
492
+
493
+ @constraint.constant.should == 10
494
+ @constraint.relationship.should == :equal
495
+ @constraint.multiplier.should == 1
496
+ @constraint.relative_to.should == :superview
497
+ @constraint.attribute.should == :center_x
498
+ @constraint.attribute2.should == :center_x
499
+
500
+ resolved = @constraint.resolve_all(@layout, @view)
501
+ resolved.length.should == 1
502
+ resolved[0].firstItem.should.be.kind_of(UIView)
503
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
504
+ resolved[0].relation.should == NSLayoutRelationEqual
505
+ resolved[0].secondItem.should == @parent_view
506
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
507
+ resolved[0].multiplier.should == 1
508
+ resolved[0].constant.should == 10
509
+ end
510
+ it 'should support `min_center_x 10`' do
511
+ @layout.context(@view) do
512
+ @layout.constraints do
513
+ @constraint = @layout.min_center_x(10)
514
+ end
515
+ end
516
+
517
+ @constraint.constant.should == 10
518
+ @constraint.relationship.should == :gte
519
+ @constraint.multiplier.should == 1
520
+ @constraint.relative_to.should == :superview
521
+ @constraint.attribute.should == :center_x
522
+ @constraint.attribute2.should == :center_x
523
+ end
524
+ it 'should support `max_center_x 10`' do
525
+ @layout.context(@view) do
526
+ @layout.constraints do
527
+ @constraint = @layout.max_center_x(10)
528
+ end
529
+ end
530
+
531
+ @constraint.constant.should == 10
532
+ @constraint.relationship.should == :lte
533
+ @constraint.multiplier.should == 1
534
+ @constraint.relative_to.should == :superview
535
+ @constraint.attribute.should == :center_x
536
+ @constraint.attribute2.should == :center_x
537
+ end
538
+ it 'should support `center_x.equals(:another_view[, :center_x])`' do
539
+ @layout.context(@view) do
540
+ @layout.constraints do
541
+ @constraint = @layout.center_x.equals(:another_view)
542
+ end
543
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
544
+ end
545
+
546
+ @constraint.constant.should == 0
547
+ @constraint.relationship.should == :equal
548
+ @constraint.multiplier.should == 1
549
+ @constraint.relative_to.should == :another_view
550
+ @constraint.attribute.should == :center_x
551
+ @constraint.attribute2.should == :center_x
552
+ end
553
+ it 'should support `min_center_x.equals(:another_view[, :center_x])`' do
554
+ @layout.context(@view) do
555
+ @layout.constraints do
556
+ @constraint = @layout.min_center_x.equals(:another_view)
557
+ end
558
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
559
+ end
560
+
561
+ @constraint.constant.should == 0
562
+ @constraint.relationship.should == :gte
563
+ @constraint.multiplier.should == 1
564
+ @constraint.relative_to.should == :another_view
565
+ @constraint.attribute.should == :center_x
566
+ @constraint.attribute2.should == :center_x
567
+ end
568
+ it 'should support `max_center_x.equals(:another_view[, :center_x])`' do
569
+ @layout.context(@view) do
570
+ @layout.constraints do
571
+ @constraint = @layout.max_center_x.equals(:another_view)
572
+ end
573
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
574
+ end
575
+
576
+ @constraint.constant.should == 0
577
+ @constraint.relationship.should == :lte
578
+ @constraint.multiplier.should == 1
579
+ @constraint.relative_to.should == :another_view
580
+ @constraint.attribute.should == :center_x
581
+ @constraint.attribute2.should == :center_x
582
+ end
583
+ it 'should support `center_x.equals(:another_view, :right)`' do
584
+ @layout.context(@view) do
585
+ @layout.constraints do
586
+ @constraint = @layout.center_x.equals(:another_view, :right)
587
+ end
588
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
589
+ end
590
+
591
+ @constraint.constant.should == 0
592
+ @constraint.relationship.should == :equal
593
+ @constraint.multiplier.should == 1
594
+ @constraint.relative_to.should == :another_view
595
+ @constraint.attribute.should == :center_x
596
+ @constraint.attribute2.should == :right
597
+ end
598
+ it 'should support `min_center_x.equals(:another_view, :right)`' do
599
+ @layout.context(@view) do
600
+ @layout.constraints do
601
+ @constraint = @layout.min_center_x.equals(:another_view, :right)
602
+ end
603
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
604
+ end
605
+
606
+ @constraint.constant.should == 0
607
+ @constraint.relationship.should == :gte
608
+ @constraint.multiplier.should == 1
609
+ @constraint.relative_to.should == :another_view
610
+ @constraint.attribute.should == :center_x
611
+ @constraint.attribute2.should == :right
612
+ end
613
+ it 'should support `max_center_x.equals(:another_view, :right)`' do
614
+ @layout.context(@view) do
615
+ @layout.constraints do
616
+ @constraint = @layout.max_center_x.equals(:another_view, :right)
617
+ end
618
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
619
+ end
620
+
621
+ @constraint.constant.should == 0
622
+ @constraint.relationship.should == :lte
623
+ @constraint.multiplier.should == 1
624
+ @constraint.relative_to.should == :another_view
625
+ @constraint.attribute.should == :center_x
626
+ @constraint.attribute2.should == :right
627
+ end
628
+ it 'should support `center_x.equals(:another_view, :right).plus(10)`' do
629
+ @layout.context(@view) do
630
+ @layout.constraints do
631
+ @constraint = @layout.center_x.equals(:another_view, :right).plus(10)
632
+ end
633
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
634
+ end
635
+
636
+ @constraint.constant.should == 10
637
+ @constraint.relationship.should == :equal
638
+ @constraint.multiplier.should == 1
639
+ @constraint.relative_to.should == :another_view
640
+ @constraint.attribute.should == :center_x
641
+ @constraint.attribute2.should == :right
642
+ end
643
+ it 'should support `min_center_x.equals(:another_view, :right).plus(10)`' do
644
+ @layout.context(@view) do
645
+ @layout.constraints do
646
+ @constraint = @layout.min_center_x.equals(:another_view, :right).plus(10)
647
+ end
648
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
649
+ end
650
+
651
+ @constraint.constant.should == 10
652
+ @constraint.relationship.should == :gte
653
+ @constraint.multiplier.should == 1
654
+ @constraint.relative_to.should == :another_view
655
+ @constraint.attribute.should == :center_x
656
+ @constraint.attribute2.should == :right
657
+ end
658
+ it 'should support `max_center_x.equals(:another_view, :right).plus(10)`' do
659
+ @layout.context(@view) do
660
+ @layout.constraints do
661
+ @constraint = @layout.max_center_x.equals(:another_view, :right).plus(10)
662
+ end
663
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
664
+ end
665
+
666
+ @constraint.constant.should == 10
667
+ @constraint.relationship.should == :lte
668
+ @constraint.multiplier.should == 1
669
+ @constraint.relative_to.should == :another_view
670
+ @constraint.attribute.should == :center_x
671
+ @constraint.attribute2.should == :right
672
+ end
673
+ it 'should support `center_x.equals(:another_view).times(2).plus(10)`' do
674
+ @layout.context(@view) do
675
+ @layout.constraints do
676
+ @constraint = @layout.center_x.equals(:another_view).times(2).plus(10)
677
+ end
678
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
679
+ end
680
+
681
+ @constraint.constant.should == 10
682
+ @constraint.relationship.should == :equal
683
+ @constraint.multiplier.should == 2
684
+ @constraint.relative_to.should == :another_view
685
+ @constraint.attribute.should == :center_x
686
+ @constraint.attribute2.should == :center_x
687
+ end
688
+ it 'should support `min_center_x.equals(:another_view).times(2).plus(10)`' do
689
+ @layout.context(@view) do
690
+ @layout.constraints do
691
+ @constraint = @layout.min_center_x.equals(:another_view).times(2).plus(10)
692
+ end
693
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
694
+ end
695
+
696
+ @constraint.constant.should == 10
697
+ @constraint.relationship.should == :gte
698
+ @constraint.multiplier.should == 2
699
+ @constraint.relative_to.should == :another_view
700
+ @constraint.attribute.should == :center_x
701
+ @constraint.attribute2.should == :center_x
702
+ end
703
+ it 'should support `max_center_x.equals(:another_view).times(2).plus(10)`' do
704
+ @layout.context(@view) do
705
+ @layout.constraints do
706
+ @constraint = @layout.max_center_x.equals(:another_view).times(2).plus(10)
707
+ end
708
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
709
+ end
710
+
711
+ @constraint.constant.should == 10
712
+ @constraint.relationship.should == :lte
713
+ @constraint.multiplier.should == 2
714
+ @constraint.relative_to.should == :another_view
715
+ @constraint.attribute.should == :center_x
716
+ @constraint.attribute2.should == :center_x
717
+
718
+ resolved = @constraint.resolve_all(@layout, @view)
719
+ resolved.length.should == 1
720
+ resolved[0].firstItem.should.be.kind_of(UIView)
721
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterX
722
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
723
+ resolved[0].secondItem.should == @another_view
724
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterX
725
+ resolved[0].multiplier.should == 2
726
+ resolved[0].constant.should == 10
727
+ end
728
+ end
729
+
730
+ describe '`right` support' do
731
+ it 'should support `right 10`' do
732
+ @layout.context(@view) do
733
+ @layout.constraints do
734
+ @constraint = @layout.right(10)
735
+ end
736
+ end
737
+
738
+ @constraint.constant.should == 10
739
+ @constraint.relationship.should == :equal
740
+ @constraint.multiplier.should == 1
741
+ @constraint.relative_to.should == :superview
742
+ @constraint.attribute.should == :right
743
+ @constraint.attribute2.should == :right
744
+
745
+ resolved = @constraint.resolve_all(@layout, @view)
746
+ resolved.length.should == 1
747
+ resolved[0].firstItem.should.be.kind_of(UIView)
748
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
749
+ resolved[0].relation.should == NSLayoutRelationEqual
750
+ resolved[0].secondItem.should == @parent_view
751
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
752
+ resolved[0].multiplier.should == 1
753
+ resolved[0].constant.should == 10
754
+ end
755
+ it 'should support `min_right 10`' do
756
+ @layout.context(@view) do
757
+ @layout.constraints do
758
+ @constraint = @layout.min_right(10)
759
+ end
760
+ end
761
+
762
+ @constraint.constant.should == 10
763
+ @constraint.relationship.should == :gte
764
+ @constraint.multiplier.should == 1
765
+ @constraint.relative_to.should == :superview
766
+ @constraint.attribute.should == :right
767
+ @constraint.attribute2.should == :right
768
+ end
769
+ it 'should support `max_right 10`' do
770
+ @layout.context(@view) do
771
+ @layout.constraints do
772
+ @constraint = @layout.max_right(10)
773
+ end
774
+ end
775
+
776
+ @constraint.constant.should == 10
777
+ @constraint.relationship.should == :lte
778
+ @constraint.multiplier.should == 1
779
+ @constraint.relative_to.should == :superview
780
+ @constraint.attribute.should == :right
781
+ @constraint.attribute2.should == :right
782
+ end
783
+ it 'should support `right.equals(:another_view[, :right])`' do
784
+ @layout.context(@view) do
785
+ @layout.constraints do
786
+ @constraint = @layout.right.equals(:another_view)
787
+ end
788
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
789
+ end
790
+
791
+ @constraint.constant.should == 0
792
+ @constraint.relationship.should == :equal
793
+ @constraint.multiplier.should == 1
794
+ @constraint.relative_to.should == :another_view
795
+ @constraint.attribute.should == :right
796
+ @constraint.attribute2.should == :right
797
+ end
798
+ it 'should support `min_right.equals(:another_view[, :right])`' do
799
+ @layout.context(@view) do
800
+ @layout.constraints do
801
+ @constraint = @layout.min_right.equals(:another_view)
802
+ end
803
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
804
+ end
805
+
806
+ @constraint.constant.should == 0
807
+ @constraint.relationship.should == :gte
808
+ @constraint.multiplier.should == 1
809
+ @constraint.relative_to.should == :another_view
810
+ @constraint.attribute.should == :right
811
+ @constraint.attribute2.should == :right
812
+ end
813
+ it 'should support `max_right.equals(:another_view[, :right])`' do
814
+ @layout.context(@view) do
815
+ @layout.constraints do
816
+ @constraint = @layout.max_right.equals(:another_view)
817
+ end
818
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
819
+ end
820
+
821
+ @constraint.constant.should == 0
822
+ @constraint.relationship.should == :lte
823
+ @constraint.multiplier.should == 1
824
+ @constraint.relative_to.should == :another_view
825
+ @constraint.attribute.should == :right
826
+ @constraint.attribute2.should == :right
827
+ end
828
+ it 'should support `right.equals(:another_view, :left)`' do
829
+ @layout.context(@view) do
830
+ @layout.constraints do
831
+ @constraint = @layout.right.equals(:another_view, :left)
832
+ end
833
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
834
+ end
835
+
836
+ @constraint.constant.should == 0
837
+ @constraint.relationship.should == :equal
838
+ @constraint.multiplier.should == 1
839
+ @constraint.relative_to.should == :another_view
840
+ @constraint.attribute.should == :right
841
+ @constraint.attribute2.should == :left
842
+ end
843
+ it 'should support `min_right.equals(:another_view, :left)`' do
844
+ @layout.context(@view) do
845
+ @layout.constraints do
846
+ @constraint = @layout.min_right.equals(:another_view, :left)
847
+ end
848
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
849
+ end
850
+
851
+ @constraint.constant.should == 0
852
+ @constraint.relationship.should == :gte
853
+ @constraint.multiplier.should == 1
854
+ @constraint.relative_to.should == :another_view
855
+ @constraint.attribute.should == :right
856
+ @constraint.attribute2.should == :left
857
+ end
858
+ it 'should support `max_right.equals(:another_view, :left)`' do
859
+ @layout.context(@view) do
860
+ @layout.constraints do
861
+ @constraint = @layout.max_right.equals(:another_view, :left)
862
+ end
863
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
864
+ end
865
+
866
+ @constraint.constant.should == 0
867
+ @constraint.relationship.should == :lte
868
+ @constraint.multiplier.should == 1
869
+ @constraint.relative_to.should == :another_view
870
+ @constraint.attribute.should == :right
871
+ @constraint.attribute2.should == :left
872
+ end
873
+ it 'should support `right.equals(:another_view, :left).plus(10)`' do
874
+ @layout.context(@view) do
875
+ @layout.constraints do
876
+ @constraint = @layout.right.equals(:another_view, :left).plus(10)
877
+ end
878
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
879
+ end
880
+
881
+ @constraint.constant.should == 10
882
+ @constraint.relationship.should == :equal
883
+ @constraint.multiplier.should == 1
884
+ @constraint.relative_to.should == :another_view
885
+ @constraint.attribute.should == :right
886
+ @constraint.attribute2.should == :left
887
+ end
888
+ it 'should support `min_right.equals(:another_view, :left).plus(10)`' do
889
+ @layout.context(@view) do
890
+ @layout.constraints do
891
+ @constraint = @layout.min_right.equals(:another_view, :left).plus(10)
892
+ end
893
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
894
+ end
895
+
896
+ @constraint.constant.should == 10
897
+ @constraint.relationship.should == :gte
898
+ @constraint.multiplier.should == 1
899
+ @constraint.relative_to.should == :another_view
900
+ @constraint.attribute.should == :right
901
+ @constraint.attribute2.should == :left
902
+ end
903
+ it 'should support `max_right.equals(:another_view, :left).plus(10)`' do
904
+ @layout.context(@view) do
905
+ @layout.constraints do
906
+ @constraint = @layout.max_right.equals(:another_view, :left).plus(10)
907
+ end
908
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
909
+ end
910
+
911
+ @constraint.constant.should == 10
912
+ @constraint.relationship.should == :lte
913
+ @constraint.multiplier.should == 1
914
+ @constraint.relative_to.should == :another_view
915
+ @constraint.attribute.should == :right
916
+ @constraint.attribute2.should == :left
917
+ end
918
+ it 'should support `right.equals(:another_view).times(2).plus(10)`' do
919
+ @layout.context(@view) do
920
+ @layout.constraints do
921
+ @constraint = @layout.right.equals(:another_view).times(2).plus(10)
922
+ end
923
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
924
+ end
925
+
926
+ @constraint.constant.should == 10
927
+ @constraint.relationship.should == :equal
928
+ @constraint.multiplier.should == 2
929
+ @constraint.relative_to.should == :another_view
930
+ @constraint.attribute.should == :right
931
+ @constraint.attribute2.should == :right
932
+ end
933
+ it 'should support `min_right.equals(:another_view).times(2).plus(10)`' do
934
+ @layout.context(@view) do
935
+ @layout.constraints do
936
+ @constraint = @layout.min_right.equals(:another_view).times(2).plus(10)
937
+ end
938
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
939
+ end
940
+
941
+ @constraint.constant.should == 10
942
+ @constraint.relationship.should == :gte
943
+ @constraint.multiplier.should == 2
944
+ @constraint.relative_to.should == :another_view
945
+ @constraint.attribute.should == :right
946
+ @constraint.attribute2.should == :right
947
+ end
948
+ it 'should support `max_right.equals(:another_view).times(2).plus(10)`' do
949
+ @layout.context(@view) do
950
+ @layout.constraints do
951
+ @constraint = @layout.max_right.equals(:another_view).times(2).plus(10)
952
+ end
953
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
954
+ end
955
+
956
+ @constraint.constant.should == 10
957
+ @constraint.relationship.should == :lte
958
+ @constraint.multiplier.should == 2
959
+ @constraint.relative_to.should == :another_view
960
+ @constraint.attribute.should == :right
961
+ @constraint.attribute2.should == :right
962
+
963
+ resolved = @constraint.resolve_all(@layout, @view)
964
+ resolved.length.should == 1
965
+ resolved[0].firstItem.should.be.kind_of(UIView)
966
+ resolved[0].firstAttribute.should == NSLayoutAttributeRight
967
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
968
+ resolved[0].secondItem.should == @another_view
969
+ resolved[0].secondAttribute.should == NSLayoutAttributeRight
970
+ resolved[0].multiplier.should == 2
971
+ resolved[0].constant.should == 10
972
+ end
973
+ end
974
+
975
+ describe '`y/top` support' do
976
+ it 'should support `y 10`' do
977
+ @layout.context(@view) do
978
+ @layout.constraints do
979
+ @constraint = @layout.y(10)
980
+ end
981
+ end
982
+
983
+ @constraint.constant.should == 10
984
+ @constraint.relationship.should == :equal
985
+ @constraint.multiplier.should == 1
986
+ @constraint.relative_to.should == :superview
987
+ @constraint.attribute.should == :top
988
+ @constraint.attribute2.should == :top
989
+
990
+ resolved = @constraint.resolve_all(@layout, @view)
991
+ resolved.length.should == 1
992
+ resolved[0].firstItem.should.be.kind_of(UIView)
993
+ resolved[0].firstAttribute.should == NSLayoutAttributeTop
994
+ resolved[0].relation.should == NSLayoutRelationEqual
995
+ resolved[0].secondItem.should == @parent_view
996
+ resolved[0].secondAttribute.should == NSLayoutAttributeTop
997
+ resolved[0].multiplier.should == 1
998
+ resolved[0].constant.should == 10
999
+ end
1000
+ it 'should support `min_y 10`' do
1001
+ @layout.context(@view) do
1002
+ @layout.constraints do
1003
+ @constraint = @layout.min_y(10)
1004
+ end
1005
+ end
1006
+
1007
+ @constraint.constant.should == 10
1008
+ @constraint.relationship.should == :gte
1009
+ @constraint.multiplier.should == 1
1010
+ @constraint.relative_to.should == :superview
1011
+ @constraint.attribute.should == :top
1012
+ @constraint.attribute2.should == :top
1013
+ end
1014
+ it 'should support `max_y 10`' do
1015
+ @layout.context(@view) do
1016
+ @layout.constraints do
1017
+ @constraint = @layout.max_y(10)
1018
+ end
1019
+ end
1020
+
1021
+ @constraint.constant.should == 10
1022
+ @constraint.relationship.should == :lte
1023
+ @constraint.multiplier.should == 1
1024
+ @constraint.relative_to.should == :superview
1025
+ @constraint.attribute.should == :top
1026
+ @constraint.attribute2.should == :top
1027
+ end
1028
+ it 'should support `y.equals(:another_view[, :top])`' do
1029
+ @layout.context(@view) do
1030
+ @layout.constraints do
1031
+ @constraint = @layout.y.equals(:another_view)
1032
+ end
1033
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1034
+ end
1035
+
1036
+ @constraint.constant.should == 0
1037
+ @constraint.relationship.should == :equal
1038
+ @constraint.multiplier.should == 1
1039
+ @constraint.relative_to.should == :another_view
1040
+ @constraint.attribute.should == :top
1041
+ @constraint.attribute2.should == :top
1042
+ end
1043
+ it 'should support `min_y.equals(:another_view[, :top])`' do
1044
+ @layout.context(@view) do
1045
+ @layout.constraints do
1046
+ @constraint = @layout.min_y.equals(:another_view)
1047
+ end
1048
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1049
+ end
1050
+
1051
+ @constraint.constant.should == 0
1052
+ @constraint.relationship.should == :gte
1053
+ @constraint.multiplier.should == 1
1054
+ @constraint.relative_to.should == :another_view
1055
+ @constraint.attribute.should == :top
1056
+ @constraint.attribute2.should == :top
1057
+ end
1058
+ it 'should support `max_y.equals(:another_view[, :top])`' do
1059
+ @layout.context(@view) do
1060
+ @layout.constraints do
1061
+ @constraint = @layout.max_y.equals(:another_view)
1062
+ end
1063
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1064
+ end
1065
+
1066
+ @constraint.constant.should == 0
1067
+ @constraint.relationship.should == :lte
1068
+ @constraint.multiplier.should == 1
1069
+ @constraint.relative_to.should == :another_view
1070
+ @constraint.attribute.should == :top
1071
+ @constraint.attribute2.should == :top
1072
+ end
1073
+ it 'should support `y.equals(:another_view, :bottom)`' do
1074
+ @layout.context(@view) do
1075
+ @layout.constraints do
1076
+ @constraint = @layout.y.equals(:another_view, :bottom)
1077
+ end
1078
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1079
+ end
1080
+
1081
+ @constraint.constant.should == 0
1082
+ @constraint.relationship.should == :equal
1083
+ @constraint.multiplier.should == 1
1084
+ @constraint.relative_to.should == :another_view
1085
+ @constraint.attribute.should == :top
1086
+ @constraint.attribute2.should == :bottom
1087
+ end
1088
+ it 'should support `min_y.equals(:another_view, :bottom)`' do
1089
+ @layout.context(@view) do
1090
+ @layout.constraints do
1091
+ @constraint = @layout.min_y.equals(:another_view, :bottom)
1092
+ end
1093
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1094
+ end
1095
+
1096
+ @constraint.constant.should == 0
1097
+ @constraint.relationship.should == :gte
1098
+ @constraint.multiplier.should == 1
1099
+ @constraint.relative_to.should == :another_view
1100
+ @constraint.attribute.should == :top
1101
+ @constraint.attribute2.should == :bottom
1102
+ end
1103
+ it 'should support `max_y.equals(:another_view, :bottom)`' do
1104
+ @layout.context(@view) do
1105
+ @layout.constraints do
1106
+ @constraint = @layout.max_y.equals(:another_view, :bottom)
1107
+ end
1108
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1109
+ end
1110
+
1111
+ @constraint.constant.should == 0
1112
+ @constraint.relationship.should == :lte
1113
+ @constraint.multiplier.should == 1
1114
+ @constraint.relative_to.should == :another_view
1115
+ @constraint.attribute.should == :top
1116
+ @constraint.attribute2.should == :bottom
1117
+ end
1118
+ it 'should support `y.equals(:another_view, :bottom).plus(10)`' do
1119
+ @layout.context(@view) do
1120
+ @layout.constraints do
1121
+ @constraint = @layout.y.equals(:another_view, :bottom).plus(10)
1122
+ end
1123
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1124
+ end
1125
+
1126
+ @constraint.constant.should == 10
1127
+ @constraint.relationship.should == :equal
1128
+ @constraint.multiplier.should == 1
1129
+ @constraint.relative_to.should == :another_view
1130
+ @constraint.attribute.should == :top
1131
+ @constraint.attribute2.should == :bottom
1132
+ end
1133
+ it 'should support `min_y.equals(:another_view, :bottom).plus(10)`' do
1134
+ @layout.context(@view) do
1135
+ @layout.constraints do
1136
+ @constraint = @layout.min_y.equals(:another_view, :bottom).plus(10)
1137
+ end
1138
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1139
+ end
1140
+
1141
+ @constraint.constant.should == 10
1142
+ @constraint.relationship.should == :gte
1143
+ @constraint.multiplier.should == 1
1144
+ @constraint.relative_to.should == :another_view
1145
+ @constraint.attribute.should == :top
1146
+ @constraint.attribute2.should == :bottom
1147
+ end
1148
+ it 'should support `max_y.equals(:another_view, :bottom).plus(10)`' do
1149
+ @layout.context(@view) do
1150
+ @layout.constraints do
1151
+ @constraint = @layout.max_y.equals(:another_view, :bottom).plus(10)
1152
+ end
1153
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1154
+ end
1155
+
1156
+ @constraint.constant.should == 10
1157
+ @constraint.relationship.should == :lte
1158
+ @constraint.multiplier.should == 1
1159
+ @constraint.relative_to.should == :another_view
1160
+ @constraint.attribute.should == :top
1161
+ @constraint.attribute2.should == :bottom
1162
+ end
1163
+ it 'should support `y.equals(:another_view).times(2).plus(10)`' do
1164
+ @layout.context(@view) do
1165
+ @layout.constraints do
1166
+ @constraint = @layout.y.equals(:another_view).times(2).plus(10)
1167
+ end
1168
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1169
+ end
1170
+
1171
+ @constraint.constant.should == 10
1172
+ @constraint.relationship.should == :equal
1173
+ @constraint.multiplier.should == 2
1174
+ @constraint.relative_to.should == :another_view
1175
+ @constraint.attribute.should == :top
1176
+ @constraint.attribute2.should == :top
1177
+ end
1178
+ it 'should support `min_y.equals(:another_view).times(2).plus(10)`' do
1179
+ @layout.context(@view) do
1180
+ @layout.constraints do
1181
+ @constraint = @layout.min_y.equals(:another_view).times(2).plus(10)
1182
+ end
1183
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1184
+ end
1185
+
1186
+ @constraint.constant.should == 10
1187
+ @constraint.relationship.should == :gte
1188
+ @constraint.multiplier.should == 2
1189
+ @constraint.relative_to.should == :another_view
1190
+ @constraint.attribute.should == :top
1191
+ @constraint.attribute2.should == :top
1192
+ end
1193
+ it 'should support `max_y.equals(:another_view).times(2).plus(10)`' do
1194
+ @layout.context(@view) do
1195
+ @layout.constraints do
1196
+ @constraint = @layout.max_y.equals(:another_view).times(2).plus(10)
1197
+ end
1198
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1199
+ end
1200
+
1201
+ @constraint.constant.should == 10
1202
+ @constraint.relationship.should == :lte
1203
+ @constraint.multiplier.should == 2
1204
+ @constraint.relative_to.should == :another_view
1205
+ @constraint.attribute.should == :top
1206
+ @constraint.attribute2.should == :top
1207
+ end
1208
+ it 'should support `top.equals(:another_view).times(2).plus(10)`' do
1209
+ @layout.context(@view) do
1210
+ @layout.constraints do
1211
+ @constraint = @layout.top.equals(:another_view).times(2).plus(10)
1212
+ end
1213
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1214
+ end
1215
+
1216
+ @constraint.constant.should == 10
1217
+ @constraint.relationship.should == :equal
1218
+ @constraint.multiplier.should == 2
1219
+ @constraint.relative_to.should == :another_view
1220
+ @constraint.attribute.should == :top
1221
+ @constraint.attribute2.should == :top
1222
+ end
1223
+ it 'should support `min_top.equals(:another_view).times(2).plus(10)`' do
1224
+ @layout.context(@view) do
1225
+ @layout.constraints do
1226
+ @constraint = @layout.min_top.equals(:another_view).times(2).plus(10)
1227
+ end
1228
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1229
+ end
1230
+
1231
+ @constraint.constant.should == 10
1232
+ @constraint.relationship.should == :gte
1233
+ @constraint.multiplier.should == 2
1234
+ @constraint.relative_to.should == :another_view
1235
+ @constraint.attribute.should == :top
1236
+ @constraint.attribute2.should == :top
1237
+ end
1238
+ it 'should support `max_top.equals(:another_view).times(2).plus(10)`' do
1239
+ @layout.context(@view) do
1240
+ @layout.constraints do
1241
+ @constraint = @layout.max_top.equals(:another_view).times(2).plus(10)
1242
+ end
1243
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1244
+ end
1245
+
1246
+ @constraint.constant.should == 10
1247
+ @constraint.relationship.should == :lte
1248
+ @constraint.multiplier.should == 2
1249
+ @constraint.relative_to.should == :another_view
1250
+ @constraint.attribute.should == :top
1251
+ @constraint.attribute2.should == :top
1252
+
1253
+ resolved = @constraint.resolve_all(@layout, @view)
1254
+ resolved.length.should == 1
1255
+ resolved[0].firstItem.should.be.kind_of(UIView)
1256
+ resolved[0].firstAttribute.should == NSLayoutAttributeTop
1257
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
1258
+ resolved[0].secondItem.should == @another_view
1259
+ resolved[0].secondAttribute.should == NSLayoutAttributeTop
1260
+ resolved[0].multiplier.should == 2
1261
+ resolved[0].constant.should == 10
1262
+ end
1263
+ end
1264
+
1265
+ describe '`center_y` support' do
1266
+ it 'should support `center_y 10`' do
1267
+ @layout.context(@view) do
1268
+ @layout.constraints do
1269
+ @constraint = @layout.center_y(10)
1270
+ end
1271
+ end
1272
+
1273
+ @constraint.constant.should == 10
1274
+ @constraint.relationship.should == :equal
1275
+ @constraint.multiplier.should == 1
1276
+ @constraint.relative_to.should == :superview
1277
+ @constraint.attribute.should == :center_y
1278
+ @constraint.attribute2.should == :center_y
1279
+
1280
+ resolved = @constraint.resolve_all(@layout, @view)
1281
+ resolved.length.should == 1
1282
+ resolved[0].firstItem.should.be.kind_of(UIView)
1283
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterY
1284
+ resolved[0].relation.should == NSLayoutRelationEqual
1285
+ resolved[0].secondItem.should == @parent_view
1286
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterY
1287
+ resolved[0].multiplier.should == 1
1288
+ resolved[0].constant.should == 10
1289
+ end
1290
+ it 'should support `min_center_y 10`' do
1291
+ @layout.context(@view) do
1292
+ @layout.constraints do
1293
+ @constraint = @layout.min_center_y(10)
1294
+ end
1295
+ end
1296
+
1297
+ @constraint.constant.should == 10
1298
+ @constraint.relationship.should == :gte
1299
+ @constraint.multiplier.should == 1
1300
+ @constraint.relative_to.should == :superview
1301
+ @constraint.attribute.should == :center_y
1302
+ @constraint.attribute2.should == :center_y
1303
+ end
1304
+ it 'should support `max_center_y 10`' do
1305
+ @layout.context(@view) do
1306
+ @layout.constraints do
1307
+ @constraint = @layout.max_center_y(10)
1308
+ end
1309
+ end
1310
+
1311
+ @constraint.constant.should == 10
1312
+ @constraint.relationship.should == :lte
1313
+ @constraint.multiplier.should == 1
1314
+ @constraint.relative_to.should == :superview
1315
+ @constraint.attribute.should == :center_y
1316
+ @constraint.attribute2.should == :center_y
1317
+ end
1318
+ it 'should support `center_y.equals(:another_view[, :center_y])`' do
1319
+ @layout.context(@view) do
1320
+ @layout.constraints do
1321
+ @constraint = @layout.center_y.equals(:another_view)
1322
+ end
1323
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1324
+ end
1325
+
1326
+ @constraint.constant.should == 0
1327
+ @constraint.relationship.should == :equal
1328
+ @constraint.multiplier.should == 1
1329
+ @constraint.relative_to.should == :another_view
1330
+ @constraint.attribute.should == :center_y
1331
+ @constraint.attribute2.should == :center_y
1332
+ end
1333
+ it 'should support `min_center_y.equals(:another_view[, :center_y])`' do
1334
+ @layout.context(@view) do
1335
+ @layout.constraints do
1336
+ @constraint = @layout.min_center_y.equals(:another_view)
1337
+ end
1338
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1339
+ end
1340
+
1341
+ @constraint.constant.should == 0
1342
+ @constraint.relationship.should == :gte
1343
+ @constraint.multiplier.should == 1
1344
+ @constraint.relative_to.should == :another_view
1345
+ @constraint.attribute.should == :center_y
1346
+ @constraint.attribute2.should == :center_y
1347
+ end
1348
+ it 'should support `max_center_y.equals(:another_view[, :center_y])`' do
1349
+ @layout.context(@view) do
1350
+ @layout.constraints do
1351
+ @constraint = @layout.max_center_y.equals(:another_view)
1352
+ end
1353
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1354
+ end
1355
+
1356
+ @constraint.constant.should == 0
1357
+ @constraint.relationship.should == :lte
1358
+ @constraint.multiplier.should == 1
1359
+ @constraint.relative_to.should == :another_view
1360
+ @constraint.attribute.should == :center_y
1361
+ @constraint.attribute2.should == :center_y
1362
+ end
1363
+ it 'should support `center_y.equals(:another_view, :top)`' do
1364
+ @layout.context(@view) do
1365
+ @layout.constraints do
1366
+ @constraint = @layout.center_y.equals(:another_view, :top)
1367
+ end
1368
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1369
+ end
1370
+
1371
+ @constraint.constant.should == 0
1372
+ @constraint.relationship.should == :equal
1373
+ @constraint.multiplier.should == 1
1374
+ @constraint.relative_to.should == :another_view
1375
+ @constraint.attribute.should == :center_y
1376
+ @constraint.attribute2.should == :top
1377
+ end
1378
+ it 'should support `min_center_y.equals(:another_view, :top)`' do
1379
+ @layout.context(@view) do
1380
+ @layout.constraints do
1381
+ @constraint = @layout.min_center_y.equals(:another_view, :top)
1382
+ end
1383
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1384
+ end
1385
+
1386
+ @constraint.constant.should == 0
1387
+ @constraint.relationship.should == :gte
1388
+ @constraint.multiplier.should == 1
1389
+ @constraint.relative_to.should == :another_view
1390
+ @constraint.attribute.should == :center_y
1391
+ @constraint.attribute2.should == :top
1392
+ end
1393
+ it 'should support `max_center_y.equals(:another_view, :top)`' do
1394
+ @layout.context(@view) do
1395
+ @layout.constraints do
1396
+ @constraint = @layout.max_center_y.equals(:another_view, :top)
1397
+ end
1398
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1399
+ end
1400
+
1401
+ @constraint.constant.should == 0
1402
+ @constraint.relationship.should == :lte
1403
+ @constraint.multiplier.should == 1
1404
+ @constraint.relative_to.should == :another_view
1405
+ @constraint.attribute.should == :center_y
1406
+ @constraint.attribute2.should == :top
1407
+ end
1408
+ it 'should support `center_y.equals(:another_view, :top).plus(10)`' do
1409
+ @layout.context(@view) do
1410
+ @layout.constraints do
1411
+ @constraint = @layout.center_y.equals(:another_view, :top).plus(10)
1412
+ end
1413
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1414
+ end
1415
+
1416
+ @constraint.constant.should == 10
1417
+ @constraint.relationship.should == :equal
1418
+ @constraint.multiplier.should == 1
1419
+ @constraint.relative_to.should == :another_view
1420
+ @constraint.attribute.should == :center_y
1421
+ @constraint.attribute2.should == :top
1422
+ end
1423
+ it 'should support `min_center_y.equals(:another_view, :top).plus(10)`' do
1424
+ @layout.context(@view) do
1425
+ @layout.constraints do
1426
+ @constraint = @layout.min_center_y.equals(:another_view, :top).plus(10)
1427
+ end
1428
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1429
+ end
1430
+
1431
+ @constraint.constant.should == 10
1432
+ @constraint.relationship.should == :gte
1433
+ @constraint.multiplier.should == 1
1434
+ @constraint.relative_to.should == :another_view
1435
+ @constraint.attribute.should == :center_y
1436
+ @constraint.attribute2.should == :top
1437
+ end
1438
+ it 'should support `max_center_y.equals(:another_view, :top).plus(10)`' do
1439
+ @layout.context(@view) do
1440
+ @layout.constraints do
1441
+ @constraint = @layout.max_center_y.equals(:another_view, :top).plus(10)
1442
+ end
1443
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1444
+ end
1445
+
1446
+ @constraint.constant.should == 10
1447
+ @constraint.relationship.should == :lte
1448
+ @constraint.multiplier.should == 1
1449
+ @constraint.relative_to.should == :another_view
1450
+ @constraint.attribute.should == :center_y
1451
+ @constraint.attribute2.should == :top
1452
+ end
1453
+ it 'should support `center_y.equals(:another_view).times(2).plus(10)`' do
1454
+ @layout.context(@view) do
1455
+ @layout.constraints do
1456
+ @constraint = @layout.center_y.equals(:another_view).times(2).plus(10)
1457
+ end
1458
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1459
+ end
1460
+
1461
+ @constraint.constant.should == 10
1462
+ @constraint.relationship.should == :equal
1463
+ @constraint.multiplier.should == 2
1464
+ @constraint.relative_to.should == :another_view
1465
+ @constraint.attribute.should == :center_y
1466
+ @constraint.attribute2.should == :center_y
1467
+ end
1468
+ it 'should support `min_center_y.equals(:another_view).times(2).plus(10)`' do
1469
+ @layout.context(@view) do
1470
+ @layout.constraints do
1471
+ @constraint = @layout.min_center_y.equals(:another_view).times(2).plus(10)
1472
+ end
1473
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1474
+ end
1475
+
1476
+ @constraint.constant.should == 10
1477
+ @constraint.relationship.should == :gte
1478
+ @constraint.multiplier.should == 2
1479
+ @constraint.relative_to.should == :another_view
1480
+ @constraint.attribute.should == :center_y
1481
+ @constraint.attribute2.should == :center_y
1482
+ end
1483
+ it 'should support `max_center_y.equals(:another_view).times(2).plus(10)`' do
1484
+ @layout.context(@view) do
1485
+ @layout.constraints do
1486
+ @constraint = @layout.max_center_y.equals(:another_view).times(2).plus(10)
1487
+ end
1488
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1489
+ end
1490
+
1491
+ @constraint.constant.should == 10
1492
+ @constraint.relationship.should == :lte
1493
+ @constraint.multiplier.should == 2
1494
+ @constraint.relative_to.should == :another_view
1495
+ @constraint.attribute.should == :center_y
1496
+ @constraint.attribute2.should == :center_y
1497
+
1498
+ resolved = @constraint.resolve_all(@layout, @view)
1499
+ resolved.length.should == 1
1500
+ resolved[0].firstItem.should.be.kind_of(UIView)
1501
+ resolved[0].firstAttribute.should == NSLayoutAttributeCenterY
1502
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
1503
+ resolved[0].secondItem.should == @another_view
1504
+ resolved[0].secondAttribute.should == NSLayoutAttributeCenterY
1505
+ resolved[0].multiplier.should == 2
1506
+ resolved[0].constant.should == 10
1507
+ end
1508
+ end
1509
+
1510
+ describe '`bottom` support' do
1511
+ it 'should support `bottom 10`' do
1512
+ @layout.context(@view) do
1513
+ @layout.constraints do
1514
+ @constraint = @layout.bottom(10)
1515
+ end
1516
+ end
1517
+
1518
+ @constraint.constant.should == 10
1519
+ @constraint.relationship.should == :equal
1520
+ @constraint.multiplier.should == 1
1521
+ @constraint.relative_to.should == :superview
1522
+ @constraint.attribute.should == :bottom
1523
+ @constraint.attribute2.should == :bottom
1524
+
1525
+ resolved = @constraint.resolve_all(@layout, @view)
1526
+ resolved.length.should == 1
1527
+ resolved[0].firstItem.should.be.kind_of(UIView)
1528
+ resolved[0].firstAttribute.should == NSLayoutAttributeBottom
1529
+ resolved[0].relation.should == NSLayoutRelationEqual
1530
+ resolved[0].secondItem.should == @parent_view
1531
+ resolved[0].secondAttribute.should == NSLayoutAttributeBottom
1532
+ resolved[0].multiplier.should == 1
1533
+ resolved[0].constant.should == 10
1534
+ end
1535
+ it 'should support `min_bottom 10`' do
1536
+ @layout.context(@view) do
1537
+ @layout.constraints do
1538
+ @constraint = @layout.min_bottom(10)
1539
+ end
1540
+ end
1541
+
1542
+ @constraint.constant.should == 10
1543
+ @constraint.relationship.should == :gte
1544
+ @constraint.multiplier.should == 1
1545
+ @constraint.relative_to.should == :superview
1546
+ @constraint.attribute.should == :bottom
1547
+ @constraint.attribute2.should == :bottom
1548
+ end
1549
+ it 'should support `max_bottom 10`' do
1550
+ @layout.context(@view) do
1551
+ @layout.constraints do
1552
+ @constraint = @layout.max_bottom(10)
1553
+ end
1554
+ end
1555
+
1556
+ @constraint.constant.should == 10
1557
+ @constraint.relationship.should == :lte
1558
+ @constraint.multiplier.should == 1
1559
+ @constraint.relative_to.should == :superview
1560
+ @constraint.attribute.should == :bottom
1561
+ @constraint.attribute2.should == :bottom
1562
+ end
1563
+ it 'should support `bottom.equals(:another_view[, :bottom])`' do
1564
+ @layout.context(@view) do
1565
+ @layout.constraints do
1566
+ @constraint = @layout.bottom.equals(:another_view)
1567
+ end
1568
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1569
+ end
1570
+
1571
+ @constraint.constant.should == 0
1572
+ @constraint.relationship.should == :equal
1573
+ @constraint.multiplier.should == 1
1574
+ @constraint.relative_to.should == :another_view
1575
+ @constraint.attribute.should == :bottom
1576
+ @constraint.attribute2.should == :bottom
1577
+ end
1578
+ it 'should support `min_bottom.equals(:another_view[, :bottom])`' do
1579
+ @layout.context(@view) do
1580
+ @layout.constraints do
1581
+ @constraint = @layout.min_bottom.equals(:another_view)
1582
+ end
1583
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1584
+ end
1585
+
1586
+ @constraint.constant.should == 0
1587
+ @constraint.relationship.should == :gte
1588
+ @constraint.multiplier.should == 1
1589
+ @constraint.relative_to.should == :another_view
1590
+ @constraint.attribute.should == :bottom
1591
+ @constraint.attribute2.should == :bottom
1592
+ end
1593
+ it 'should support `max_bottom.equals(:another_view[, :bottom])`' do
1594
+ @layout.context(@view) do
1595
+ @layout.constraints do
1596
+ @constraint = @layout.max_bottom.equals(:another_view)
1597
+ end
1598
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1599
+ end
1600
+
1601
+ @constraint.constant.should == 0
1602
+ @constraint.relationship.should == :lte
1603
+ @constraint.multiplier.should == 1
1604
+ @constraint.relative_to.should == :another_view
1605
+ @constraint.attribute.should == :bottom
1606
+ @constraint.attribute2.should == :bottom
1607
+ end
1608
+ it 'should support `bottom.equals(:another_view, :top)`' do
1609
+ @layout.context(@view) do
1610
+ @layout.constraints do
1611
+ @constraint = @layout.bottom.equals(:another_view, :top)
1612
+ end
1613
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1614
+ end
1615
+
1616
+ @constraint.constant.should == 0
1617
+ @constraint.relationship.should == :equal
1618
+ @constraint.multiplier.should == 1
1619
+ @constraint.relative_to.should == :another_view
1620
+ @constraint.attribute.should == :bottom
1621
+ @constraint.attribute2.should == :top
1622
+ end
1623
+ it 'should support `min_bottom.equals(:another_view, :top)`' do
1624
+ @layout.context(@view) do
1625
+ @layout.constraints do
1626
+ @constraint = @layout.min_bottom.equals(:another_view, :top)
1627
+ end
1628
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1629
+ end
1630
+
1631
+ @constraint.constant.should == 0
1632
+ @constraint.relationship.should == :gte
1633
+ @constraint.multiplier.should == 1
1634
+ @constraint.relative_to.should == :another_view
1635
+ @constraint.attribute.should == :bottom
1636
+ @constraint.attribute2.should == :top
1637
+ end
1638
+ it 'should support `max_bottom.equals(:another_view, :top)`' do
1639
+ @layout.context(@view) do
1640
+ @layout.constraints do
1641
+ @constraint = @layout.max_bottom.equals(:another_view, :top)
1642
+ end
1643
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1644
+ end
1645
+
1646
+ @constraint.constant.should == 0
1647
+ @constraint.relationship.should == :lte
1648
+ @constraint.multiplier.should == 1
1649
+ @constraint.relative_to.should == :another_view
1650
+ @constraint.attribute.should == :bottom
1651
+ @constraint.attribute2.should == :top
1652
+ end
1653
+ it 'should support `bottom.equals(:another_view, :top).plus(10)`' do
1654
+ @layout.context(@view) do
1655
+ @layout.constraints do
1656
+ @constraint = @layout.bottom.equals(:another_view, :top).plus(10)
1657
+ end
1658
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1659
+ end
1660
+
1661
+ @constraint.constant.should == 10
1662
+ @constraint.relationship.should == :equal
1663
+ @constraint.multiplier.should == 1
1664
+ @constraint.relative_to.should == :another_view
1665
+ @constraint.attribute.should == :bottom
1666
+ @constraint.attribute2.should == :top
1667
+ end
1668
+ it 'should support `min_bottom.equals(:another_view, :top).plus(10)`' do
1669
+ @layout.context(@view) do
1670
+ @layout.constraints do
1671
+ @constraint = @layout.min_bottom.equals(:another_view, :top).plus(10)
1672
+ end
1673
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1674
+ end
1675
+
1676
+ @constraint.constant.should == 10
1677
+ @constraint.relationship.should == :gte
1678
+ @constraint.multiplier.should == 1
1679
+ @constraint.relative_to.should == :another_view
1680
+ @constraint.attribute.should == :bottom
1681
+ @constraint.attribute2.should == :top
1682
+ end
1683
+ it 'should support `max_bottom.equals(:another_view, :top).plus(10)`' do
1684
+ @layout.context(@view) do
1685
+ @layout.constraints do
1686
+ @constraint = @layout.max_bottom.equals(:another_view, :top).plus(10)
1687
+ end
1688
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1689
+ end
1690
+
1691
+ @constraint.constant.should == 10
1692
+ @constraint.relationship.should == :lte
1693
+ @constraint.multiplier.should == 1
1694
+ @constraint.relative_to.should == :another_view
1695
+ @constraint.attribute.should == :bottom
1696
+ @constraint.attribute2.should == :top
1697
+ end
1698
+ it 'should support `bottom.equals(:another_view).times(2).plus(10)`' do
1699
+ @layout.context(@view) do
1700
+ @layout.constraints do
1701
+ @constraint = @layout.bottom.equals(:another_view).times(2).plus(10)
1702
+ end
1703
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1704
+ end
1705
+
1706
+ @constraint.constant.should == 10
1707
+ @constraint.relationship.should == :equal
1708
+ @constraint.multiplier.should == 2
1709
+ @constraint.relative_to.should == :another_view
1710
+ @constraint.attribute.should == :bottom
1711
+ @constraint.attribute2.should == :bottom
1712
+ end
1713
+ it 'should support `min_bottom.equals(:another_view).times(2).plus(10)`' do
1714
+ @layout.context(@view) do
1715
+ @layout.constraints do
1716
+ @constraint = @layout.min_bottom.equals(:another_view).times(2).plus(10)
1717
+ end
1718
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1719
+ end
1720
+
1721
+ @constraint.constant.should == 10
1722
+ @constraint.relationship.should == :gte
1723
+ @constraint.multiplier.should == 2
1724
+ @constraint.relative_to.should == :another_view
1725
+ @constraint.attribute.should == :bottom
1726
+ @constraint.attribute2.should == :bottom
1727
+ end
1728
+ it 'should support `max_bottom.equals(:another_view).times(2).plus(10)`' do
1729
+ @layout.context(@view) do
1730
+ @layout.constraints do
1731
+ @constraint = @layout.max_bottom.equals(:another_view).times(2).plus(10)
1732
+ end
1733
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1734
+ end
1735
+
1736
+ @constraint.constant.should == 10
1737
+ @constraint.relationship.should == :lte
1738
+ @constraint.multiplier.should == 2
1739
+ @constraint.relative_to.should == :another_view
1740
+ @constraint.attribute.should == :bottom
1741
+ @constraint.attribute2.should == :bottom
1742
+
1743
+ resolved = @constraint.resolve_all(@layout, @view)
1744
+ resolved.length.should == 1
1745
+ resolved[0].firstItem.should.be.kind_of(UIView)
1746
+ resolved[0].firstAttribute.should == NSLayoutAttributeBottom
1747
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
1748
+ resolved[0].secondItem.should == @another_view
1749
+ resolved[0].secondAttribute.should == NSLayoutAttributeBottom
1750
+ resolved[0].multiplier.should == 2
1751
+ resolved[0].constant.should == 10
1752
+ end
1753
+ end
1754
+
1755
+ describe '`width` support' do
1756
+ it 'should support `width 10`' do
1757
+ @layout.context(@view) do
1758
+ @layout.constraints do
1759
+ @constraint = @layout.width(10)
1760
+ end
1761
+ end
1762
+
1763
+ @constraint.constant.should == 10
1764
+ @constraint.relationship.should == :equal
1765
+ @constraint.multiplier.should == 1
1766
+ @constraint.relative_to.should == nil
1767
+ @constraint.attribute.should == :width
1768
+ @constraint.attribute2.should == :width
1769
+
1770
+ resolved = @constraint.resolve_all(@layout, @view)
1771
+ resolved.length.should == 1
1772
+ resolved[0].firstItem.should.be.kind_of(UIView)
1773
+ resolved[0].firstAttribute.should == NSLayoutAttributeWidth
1774
+ resolved[0].relation.should == NSLayoutRelationEqual
1775
+ resolved[0].secondItem.should == nil
1776
+ resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
1777
+ resolved[0].multiplier.should == 1
1778
+ resolved[0].constant.should == 10
1779
+ end
1780
+ it 'should support `min_width 10`' do
1781
+ @layout.context(@view) do
1782
+ @layout.constraints do
1783
+ @constraint = @layout.min_width(10)
1784
+ end
1785
+ end
1786
+
1787
+ @constraint.constant.should == 10
1788
+ @constraint.relationship.should == :gte
1789
+ @constraint.multiplier.should == 1
1790
+ @constraint.relative_to.should == nil
1791
+ @constraint.attribute.should == :width
1792
+ @constraint.attribute2.should == :width
1793
+ end
1794
+ it 'should support `max_width 10`' do
1795
+ @layout.context(@view) do
1796
+ @layout.constraints do
1797
+ @constraint = @layout.max_width(10)
1798
+ end
1799
+ end
1800
+
1801
+ @constraint.constant.should == 10
1802
+ @constraint.relationship.should == :lte
1803
+ @constraint.multiplier.should == 1
1804
+ @constraint.relative_to.should == nil
1805
+ @constraint.attribute.should == :width
1806
+ @constraint.attribute2.should == :width
1807
+ end
1808
+ it 'should support `width.equals(:another_view[, :width])`' do
1809
+ @layout.context(@view) do
1810
+ @layout.constraints do
1811
+ @constraint = @layout.width.equals(:another_view)
1812
+ end
1813
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1814
+ end
1815
+
1816
+ @constraint.constant.should == 0
1817
+ @constraint.relationship.should == :equal
1818
+ @constraint.multiplier.should == 1
1819
+ @constraint.relative_to.should == :another_view
1820
+ @constraint.attribute.should == :width
1821
+ @constraint.attribute2.should == :width
1822
+ end
1823
+ it 'should support `min_width.equals(:another_view[, :width])`' do
1824
+ @layout.context(@view) do
1825
+ @layout.constraints do
1826
+ @constraint = @layout.min_width.equals(:another_view)
1827
+ end
1828
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1829
+ end
1830
+
1831
+ @constraint.constant.should == 0
1832
+ @constraint.relationship.should == :gte
1833
+ @constraint.multiplier.should == 1
1834
+ @constraint.relative_to.should == :another_view
1835
+ @constraint.attribute.should == :width
1836
+ @constraint.attribute2.should == :width
1837
+ end
1838
+ it 'should support `max_width.equals(:another_view[, :width])`' do
1839
+ @layout.context(@view) do
1840
+ @layout.constraints do
1841
+ @constraint = @layout.max_width.equals(:another_view)
1842
+ end
1843
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1844
+ end
1845
+
1846
+ @constraint.constant.should == 0
1847
+ @constraint.relationship.should == :lte
1848
+ @constraint.multiplier.should == 1
1849
+ @constraint.relative_to.should == :another_view
1850
+ @constraint.attribute.should == :width
1851
+ @constraint.attribute2.should == :width
1852
+ end
1853
+ it 'should support `width.equals(:another_view, :height).plus(10)`' do
1854
+ @layout.context(@view) do
1855
+ @layout.constraints do
1856
+ @constraint = @layout.width.equals(:another_view, :height).plus(10)
1857
+ end
1858
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1859
+ end
1860
+
1861
+ @constraint.constant.should == 10
1862
+ @constraint.relationship.should == :equal
1863
+ @constraint.multiplier.should == 1
1864
+ @constraint.relative_to.should == :another_view
1865
+ @constraint.attribute.should == :width
1866
+ @constraint.attribute2.should == :height
1867
+ end
1868
+ it 'should support `min_width.equals(:another_view, :height).plus(10)`' do
1869
+ @layout.context(@view) do
1870
+ @layout.constraints do
1871
+ @constraint = @layout.min_width.equals(:another_view, :height).plus(10)
1872
+ end
1873
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1874
+ end
1875
+
1876
+ @constraint.constant.should == 10
1877
+ @constraint.relationship.should == :gte
1878
+ @constraint.multiplier.should == 1
1879
+ @constraint.relative_to.should == :another_view
1880
+ @constraint.attribute.should == :width
1881
+ @constraint.attribute2.should == :height
1882
+ end
1883
+ it 'should support `max_width.equals(:another_view, :height).plus(10)`' do
1884
+ @layout.context(@view) do
1885
+ @layout.constraints do
1886
+ @constraint = @layout.max_width.equals(:another_view, :height).plus(10)
1887
+ end
1888
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1889
+ end
1890
+
1891
+ @constraint.constant.should == 10
1892
+ @constraint.relationship.should == :lte
1893
+ @constraint.multiplier.should == 1
1894
+ @constraint.relative_to.should == :another_view
1895
+ @constraint.attribute.should == :width
1896
+ @constraint.attribute2.should == :height
1897
+ end
1898
+ it 'should support `width.equals(:another_view).times(2).plus(10)`' do
1899
+ @layout.context(@view) do
1900
+ @layout.constraints do
1901
+ @constraint = @layout.width.equals(:another_view).times(2).plus(10)
1902
+ end
1903
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1904
+ end
1905
+
1906
+ @constraint.constant.should == 10
1907
+ @constraint.relationship.should == :equal
1908
+ @constraint.multiplier.should == 2
1909
+ @constraint.relative_to.should == :another_view
1910
+ @constraint.attribute.should == :width
1911
+ @constraint.attribute2.should == :width
1912
+ end
1913
+ it 'should support `min_width.equals(:another_view).times(2).plus(10)`' do
1914
+ @layout.context(@view) do
1915
+ @layout.constraints do
1916
+ @constraint = @layout.min_width.equals(:another_view).times(2).plus(10)
1917
+ end
1918
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1919
+ end
1920
+
1921
+ @constraint.constant.should == 10
1922
+ @constraint.relationship.should == :gte
1923
+ @constraint.multiplier.should == 2
1924
+ @constraint.relative_to.should == :another_view
1925
+ @constraint.attribute.should == :width
1926
+ @constraint.attribute2.should == :width
1927
+ end
1928
+ it 'should support `max_width.equals(:another_view).times(2).plus(10)`' do
1929
+ @layout.context(@view) do
1930
+ @layout.constraints do
1931
+ @constraint = @layout.max_width.equals(:another_view).times(2).plus(10)
1932
+ end
1933
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
1934
+ end
1935
+
1936
+ @constraint.constant.should == 10
1937
+ @constraint.relationship.should == :lte
1938
+ @constraint.multiplier.should == 2
1939
+ @constraint.relative_to.should == :another_view
1940
+ @constraint.attribute.should == :width
1941
+ @constraint.attribute2.should == :width
1942
+
1943
+ resolved = @constraint.resolve_all(@layout, @view)
1944
+ resolved.length.should == 1
1945
+ resolved[0].firstItem.should.be.kind_of(UIView)
1946
+ resolved[0].firstAttribute.should == NSLayoutAttributeWidth
1947
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
1948
+ resolved[0].secondItem.should == @another_view
1949
+ resolved[0].secondAttribute.should == NSLayoutAttributeWidth
1950
+ resolved[0].multiplier.should == 2
1951
+ resolved[0].constant.should == 10
1952
+ end
1953
+ end
1954
+
1955
+ describe '`height` support' do
1956
+ it 'should support `height 10`' do
1957
+ @layout.context(@view) do
1958
+ @layout.constraints do
1959
+ @constraint = @layout.height(10)
1960
+ end
1961
+ end
1962
+
1963
+ @constraint.constant.should == 10
1964
+ @constraint.relationship.should == :equal
1965
+ @constraint.multiplier.should == 1
1966
+ @constraint.relative_to.should == nil
1967
+ @constraint.attribute.should == :height
1968
+ @constraint.attribute2.should == :height
1969
+
1970
+ resolved = @constraint.resolve_all(@layout, @view)
1971
+ resolved.length.should == 1
1972
+ resolved[0].firstItem.should.be.kind_of(UIView)
1973
+ resolved[0].firstAttribute.should == NSLayoutAttributeHeight
1974
+ resolved[0].relation.should == NSLayoutRelationEqual
1975
+ resolved[0].secondItem.should == nil
1976
+ resolved[0].secondAttribute.should == NSLayoutAttributeNotAnAttribute
1977
+ resolved[0].multiplier.should == 1
1978
+ resolved[0].constant.should == 10
1979
+ end
1980
+ it 'should support `min_height 10`' do
1981
+ @layout.context(@view) do
1982
+ @layout.constraints do
1983
+ @constraint = @layout.min_height(10)
1984
+ end
1985
+ end
1986
+
1987
+ @constraint.constant.should == 10
1988
+ @constraint.relationship.should == :gte
1989
+ @constraint.multiplier.should == 1
1990
+ @constraint.relative_to.should == nil
1991
+ @constraint.attribute.should == :height
1992
+ @constraint.attribute2.should == :height
1993
+ end
1994
+ it 'should support `max_height 10`' do
1995
+ @layout.context(@view) do
1996
+ @layout.constraints do
1997
+ @constraint = @layout.max_height(10)
1998
+ end
1999
+ end
2000
+
2001
+ @constraint.constant.should == 10
2002
+ @constraint.relationship.should == :lte
2003
+ @constraint.multiplier.should == 1
2004
+ @constraint.relative_to.should == nil
2005
+ @constraint.attribute.should == :height
2006
+ @constraint.attribute2.should == :height
2007
+ end
2008
+ it 'should support `height.equals(:another_view[, :height])`' do
2009
+ @layout.context(@view) do
2010
+ @layout.constraints do
2011
+ @constraint = @layout.height.equals(:another_view)
2012
+ end
2013
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2014
+ end
2015
+
2016
+ @constraint.constant.should == 0
2017
+ @constraint.relationship.should == :equal
2018
+ @constraint.multiplier.should == 1
2019
+ @constraint.relative_to.should == :another_view
2020
+ @constraint.attribute.should == :height
2021
+ @constraint.attribute2.should == :height
2022
+ end
2023
+ it 'should support `min_height.equals(:another_view[, :height])`' do
2024
+ @layout.context(@view) do
2025
+ @layout.constraints do
2026
+ @constraint = @layout.min_height.equals(:another_view)
2027
+ end
2028
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2029
+ end
2030
+
2031
+ @constraint.constant.should == 0
2032
+ @constraint.relationship.should == :gte
2033
+ @constraint.multiplier.should == 1
2034
+ @constraint.relative_to.should == :another_view
2035
+ @constraint.attribute.should == :height
2036
+ @constraint.attribute2.should == :height
2037
+ end
2038
+ it 'should support `max_height.equals(:another_view[, :height])`' do
2039
+ @layout.context(@view) do
2040
+ @layout.constraints do
2041
+ @constraint = @layout.max_height.equals(:another_view)
2042
+ end
2043
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2044
+ end
2045
+
2046
+ @constraint.constant.should == 0
2047
+ @constraint.relationship.should == :lte
2048
+ @constraint.multiplier.should == 1
2049
+ @constraint.relative_to.should == :another_view
2050
+ @constraint.attribute.should == :height
2051
+ @constraint.attribute2.should == :height
2052
+ end
2053
+ it 'should support `height.equals(:another_view).plus(10)`' do
2054
+ @layout.context(@view) do
2055
+ @layout.constraints do
2056
+ @constraint = @layout.height.equals(:another_view).plus(10)
2057
+ end
2058
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2059
+ end
2060
+
2061
+ @constraint.constant.should == 10
2062
+ @constraint.relationship.should == :equal
2063
+ @constraint.multiplier.should == 1
2064
+ @constraint.relative_to.should == :another_view
2065
+ @constraint.attribute.should == :height
2066
+ @constraint.attribute2.should == :height
2067
+ end
2068
+ it 'should support `min_height.equals(:another_view).plus(10)`' do
2069
+ @layout.context(@view) do
2070
+ @layout.constraints do
2071
+ @constraint = @layout.min_height.equals(:another_view).plus(10)
2072
+ end
2073
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2074
+ end
2075
+
2076
+ @constraint.constant.should == 10
2077
+ @constraint.relationship.should == :gte
2078
+ @constraint.multiplier.should == 1
2079
+ @constraint.relative_to.should == :another_view
2080
+ @constraint.attribute.should == :height
2081
+ @constraint.attribute2.should == :height
2082
+ end
2083
+ it 'should support `max_height.equals(:another_view).plus(10)`' do
2084
+ @layout.context(@view) do
2085
+ @layout.constraints do
2086
+ @constraint = @layout.max_height.equals(:another_view).plus(10)
2087
+ end
2088
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2089
+ end
2090
+
2091
+ @constraint.constant.should == 10
2092
+ @constraint.relationship.should == :lte
2093
+ @constraint.multiplier.should == 1
2094
+ @constraint.relative_to.should == :another_view
2095
+ @constraint.attribute.should == :height
2096
+ @constraint.attribute2.should == :height
2097
+ end
2098
+ it 'should support `height.equals(:another_view).times(2).plus(10)`' do
2099
+ @layout.context(@view) do
2100
+ @layout.constraints do
2101
+ @constraint = @layout.height.equals(:another_view).times(2).plus(10)
2102
+ end
2103
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2104
+ end
2105
+
2106
+ @constraint.constant.should == 10
2107
+ @constraint.relationship.should == :equal
2108
+ @constraint.multiplier.should == 2
2109
+ @constraint.relative_to.should == :another_view
2110
+ @constraint.attribute.should == :height
2111
+ @constraint.attribute2.should == :height
2112
+ end
2113
+ it 'should support `min_height.equals(:another_view).times(2).plus(10)`' do
2114
+ @layout.context(@view) do
2115
+ @layout.constraints do
2116
+ @constraint = @layout.min_height.equals(:another_view).times(2).plus(10)
2117
+ end
2118
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2119
+ end
2120
+
2121
+ @constraint.constant.should == 10
2122
+ @constraint.relationship.should == :gte
2123
+ @constraint.multiplier.should == 2
2124
+ @constraint.relative_to.should == :another_view
2125
+ @constraint.attribute.should == :height
2126
+ @constraint.attribute2.should == :height
2127
+ end
2128
+ it 'should support `max_height.equals(:another_view).times(2).plus(10)`' do
2129
+ @layout.context(@view) do
2130
+ @layout.constraints do
2131
+ @constraint = @layout.max_height.equals(:another_view).times(2).plus(10)
2132
+ end
2133
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2134
+ end
2135
+
2136
+ @constraint.constant.should == 10
2137
+ @constraint.relationship.should == :lte
2138
+ @constraint.multiplier.should == 2
2139
+ @constraint.relative_to.should == :another_view
2140
+ @constraint.attribute.should == :height
2141
+ @constraint.attribute2.should == :height
2142
+
2143
+ resolved = @constraint.resolve_all(@layout, @view)
2144
+ resolved.length.should == 1
2145
+ resolved[0].firstItem.should.be.kind_of(UIView)
2146
+ resolved[0].firstAttribute.should == NSLayoutAttributeHeight
2147
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
2148
+ resolved[0].secondItem.should == @another_view
2149
+ resolved[0].secondAttribute.should == NSLayoutAttributeHeight
2150
+ resolved[0].multiplier.should == 2
2151
+ resolved[0].constant.should == 10
2152
+ end
2153
+ end
2154
+
2155
+ describe '`leading` support' do
2156
+ it 'should support `leading 10`' do
2157
+ @layout.context(@view) do
2158
+ @layout.constraints do
2159
+ @constraint = @layout.leading(10)
2160
+ end
2161
+ end
2162
+
2163
+ @constraint.constant.should == 10
2164
+ @constraint.relationship.should == :equal
2165
+ @constraint.multiplier.should == 1
2166
+ @constraint.relative_to.should == :superview
2167
+ @constraint.attribute.should == :leading
2168
+ @constraint.attribute2.should == :leading
2169
+
2170
+ resolved = @constraint.resolve_all(@layout, @view)
2171
+ resolved.length.should == 1
2172
+ resolved[0].firstItem.should.be.kind_of(UIView)
2173
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeading
2174
+ resolved[0].relation.should == NSLayoutRelationEqual
2175
+ resolved[0].secondItem.should == @parent_view
2176
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeading
2177
+ resolved[0].multiplier.should == 1
2178
+ resolved[0].constant.should == 10
2179
+ end
2180
+ it 'should support `min_leading 10`' do
2181
+ @layout.context(@view) do
2182
+ @layout.constraints do
2183
+ @constraint = @layout.min_leading(10)
2184
+ end
2185
+ end
2186
+
2187
+ @constraint.constant.should == 10
2188
+ @constraint.relationship.should == :gte
2189
+ @constraint.multiplier.should == 1
2190
+ @constraint.relative_to.should == :superview
2191
+ @constraint.attribute.should == :leading
2192
+ @constraint.attribute2.should == :leading
2193
+ end
2194
+ it 'should support `max_leading 10`' do
2195
+ @layout.context(@view) do
2196
+ @layout.constraints do
2197
+ @constraint = @layout.max_leading(10)
2198
+ end
2199
+ end
2200
+
2201
+ @constraint.constant.should == 10
2202
+ @constraint.relationship.should == :lte
2203
+ @constraint.multiplier.should == 1
2204
+ @constraint.relative_to.should == :superview
2205
+ @constraint.attribute.should == :leading
2206
+ @constraint.attribute2.should == :leading
2207
+ end
2208
+ it 'should support `leading.equals(:another_view[, :leading])`' do
2209
+ @layout.context(@view) do
2210
+ @layout.constraints do
2211
+ @constraint = @layout.leading.equals(:another_view)
2212
+ end
2213
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2214
+ end
2215
+
2216
+ @constraint.constant.should == 0
2217
+ @constraint.relationship.should == :equal
2218
+ @constraint.multiplier.should == 1
2219
+ @constraint.relative_to.should == :another_view
2220
+ @constraint.attribute.should == :leading
2221
+ @constraint.attribute2.should == :leading
2222
+ end
2223
+ it 'should support `min_leading.equals(:another_view[, :leading])`' do
2224
+ @layout.context(@view) do
2225
+ @layout.constraints do
2226
+ @constraint = @layout.min_leading.equals(:another_view)
2227
+ end
2228
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2229
+ end
2230
+
2231
+ @constraint.constant.should == 0
2232
+ @constraint.relationship.should == :gte
2233
+ @constraint.multiplier.should == 1
2234
+ @constraint.relative_to.should == :another_view
2235
+ @constraint.attribute.should == :leading
2236
+ @constraint.attribute2.should == :leading
2237
+ end
2238
+ it 'should support `max_leading.equals(:another_view[, :leading])`' do
2239
+ @layout.context(@view) do
2240
+ @layout.constraints do
2241
+ @constraint = @layout.max_leading.equals(:another_view)
2242
+ end
2243
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2244
+ end
2245
+
2246
+ @constraint.constant.should == 0
2247
+ @constraint.relationship.should == :lte
2248
+ @constraint.multiplier.should == 1
2249
+ @constraint.relative_to.should == :another_view
2250
+ @constraint.attribute.should == :leading
2251
+ @constraint.attribute2.should == :leading
2252
+ end
2253
+ it 'should support `leading.equals(:another_view).plus(10)`' do
2254
+ @layout.context(@view) do
2255
+ @layout.constraints do
2256
+ @constraint = @layout.leading.equals(:another_view).plus(10)
2257
+ end
2258
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2259
+ end
2260
+
2261
+ @constraint.constant.should == 10
2262
+ @constraint.relationship.should == :equal
2263
+ @constraint.multiplier.should == 1
2264
+ @constraint.relative_to.should == :another_view
2265
+ @constraint.attribute.should == :leading
2266
+ @constraint.attribute2.should == :leading
2267
+ end
2268
+ it 'should support `min_leading.equals(:another_view).plus(10)`' do
2269
+ @layout.context(@view) do
2270
+ @layout.constraints do
2271
+ @constraint = @layout.min_leading.equals(:another_view).plus(10)
2272
+ end
2273
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2274
+ end
2275
+
2276
+ @constraint.constant.should == 10
2277
+ @constraint.relationship.should == :gte
2278
+ @constraint.multiplier.should == 1
2279
+ @constraint.relative_to.should == :another_view
2280
+ @constraint.attribute.should == :leading
2281
+ @constraint.attribute2.should == :leading
2282
+ end
2283
+ it 'should support `max_leading.equals(:another_view).plus(10)`' do
2284
+ @layout.context(@view) do
2285
+ @layout.constraints do
2286
+ @constraint = @layout.max_leading.equals(:another_view).plus(10)
2287
+ end
2288
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2289
+ end
2290
+
2291
+ @constraint.constant.should == 10
2292
+ @constraint.relationship.should == :lte
2293
+ @constraint.multiplier.should == 1
2294
+ @constraint.relative_to.should == :another_view
2295
+ @constraint.attribute.should == :leading
2296
+ @constraint.attribute2.should == :leading
2297
+ end
2298
+ it 'should support `leading.equals(:another_view).times(2).plus(10)`' do
2299
+ @layout.context(@view) do
2300
+ @layout.constraints do
2301
+ @constraint = @layout.leading.equals(:another_view).times(2).plus(10)
2302
+ end
2303
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2304
+ end
2305
+
2306
+ @constraint.constant.should == 10
2307
+ @constraint.relationship.should == :equal
2308
+ @constraint.multiplier.should == 2
2309
+ @constraint.relative_to.should == :another_view
2310
+ @constraint.attribute.should == :leading
2311
+ @constraint.attribute2.should == :leading
2312
+ end
2313
+ it 'should support `min_leading.equals(:another_view).times(2).plus(10)`' do
2314
+ @layout.context(@view) do
2315
+ @layout.constraints do
2316
+ @constraint = @layout.min_leading.equals(:another_view).times(2).plus(10)
2317
+ end
2318
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2319
+ end
2320
+
2321
+ @constraint.constant.should == 10
2322
+ @constraint.relationship.should == :gte
2323
+ @constraint.multiplier.should == 2
2324
+ @constraint.relative_to.should == :another_view
2325
+ @constraint.attribute.should == :leading
2326
+ @constraint.attribute2.should == :leading
2327
+ end
2328
+ it 'should support `max_leading.equals(:another_view).times(2).plus(10)`' do
2329
+ @layout.context(@view) do
2330
+ @layout.constraints do
2331
+ @constraint = @layout.max_leading.equals(:another_view).times(2).plus(10)
2332
+ end
2333
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2334
+ end
2335
+
2336
+ @constraint.constant.should == 10
2337
+ @constraint.relationship.should == :lte
2338
+ @constraint.multiplier.should == 2
2339
+ @constraint.relative_to.should == :another_view
2340
+ @constraint.attribute.should == :leading
2341
+ @constraint.attribute2.should == :leading
2342
+
2343
+ resolved = @constraint.resolve_all(@layout, @view)
2344
+ resolved.length.should == 1
2345
+ resolved[0].firstItem.should.be.kind_of(UIView)
2346
+ resolved[0].firstAttribute.should == NSLayoutAttributeLeading
2347
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
2348
+ resolved[0].secondItem.should == @another_view
2349
+ resolved[0].secondAttribute.should == NSLayoutAttributeLeading
2350
+ resolved[0].multiplier.should == 2
2351
+ resolved[0].constant.should == 10
2352
+ end
2353
+ end
2354
+
2355
+ describe '`trailing` support' do
2356
+ it 'should support `trailing 10`' do
2357
+ @layout.context(@view) do
2358
+ @layout.constraints do
2359
+ @constraint = @layout.trailing(10)
2360
+ end
2361
+ end
2362
+
2363
+ @constraint.constant.should == 10
2364
+ @constraint.relationship.should == :equal
2365
+ @constraint.multiplier.should == 1
2366
+ @constraint.relative_to.should == :superview
2367
+ @constraint.attribute.should == :trailing
2368
+ @constraint.attribute2.should == :trailing
2369
+
2370
+ resolved = @constraint.resolve_all(@layout, @view)
2371
+ resolved.length.should == 1
2372
+ resolved[0].firstItem.should.be.kind_of(UIView)
2373
+ resolved[0].firstAttribute.should == NSLayoutAttributeTrailing
2374
+ resolved[0].relation.should == NSLayoutRelationEqual
2375
+ resolved[0].secondItem.should == @parent_view
2376
+ resolved[0].secondAttribute.should == NSLayoutAttributeTrailing
2377
+ resolved[0].multiplier.should == 1
2378
+ resolved[0].constant.should == 10
2379
+ end
2380
+ it 'should support `min_trailing 10`' do
2381
+ @layout.context(@view) do
2382
+ @layout.constraints do
2383
+ @constraint = @layout.min_trailing(10)
2384
+ end
2385
+ end
2386
+
2387
+ @constraint.constant.should == 10
2388
+ @constraint.relationship.should == :gte
2389
+ @constraint.multiplier.should == 1
2390
+ @constraint.relative_to.should == :superview
2391
+ @constraint.attribute.should == :trailing
2392
+ @constraint.attribute2.should == :trailing
2393
+ end
2394
+ it 'should support `max_trailing 10`' do
2395
+ @layout.context(@view) do
2396
+ @layout.constraints do
2397
+ @constraint = @layout.max_trailing(10)
2398
+ end
2399
+ end
2400
+
2401
+ @constraint.constant.should == 10
2402
+ @constraint.relationship.should == :lte
2403
+ @constraint.multiplier.should == 1
2404
+ @constraint.relative_to.should == :superview
2405
+ @constraint.attribute.should == :trailing
2406
+ @constraint.attribute2.should == :trailing
2407
+ end
2408
+ it 'should support `trailing.equals(:another_view[, :trailing])`' do
2409
+ @layout.context(@view) do
2410
+ @layout.constraints do
2411
+ @constraint = @layout.trailing.equals(:another_view)
2412
+ end
2413
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2414
+ end
2415
+
2416
+ @constraint.constant.should == 0
2417
+ @constraint.relationship.should == :equal
2418
+ @constraint.multiplier.should == 1
2419
+ @constraint.relative_to.should == :another_view
2420
+ @constraint.attribute.should == :trailing
2421
+ @constraint.attribute2.should == :trailing
2422
+ end
2423
+ it 'should support `min_trailing.equals(:another_view[, :trailing])`' do
2424
+ @layout.context(@view) do
2425
+ @layout.constraints do
2426
+ @constraint = @layout.min_trailing.equals(:another_view)
2427
+ end
2428
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2429
+ end
2430
+
2431
+ @constraint.constant.should == 0
2432
+ @constraint.relationship.should == :gte
2433
+ @constraint.multiplier.should == 1
2434
+ @constraint.relative_to.should == :another_view
2435
+ @constraint.attribute.should == :trailing
2436
+ @constraint.attribute2.should == :trailing
2437
+ end
2438
+ it 'should support `max_trailing.equals(:another_view[, :trailing])`' do
2439
+ @layout.context(@view) do
2440
+ @layout.constraints do
2441
+ @constraint = @layout.max_trailing.equals(:another_view)
2442
+ end
2443
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2444
+ end
2445
+
2446
+ @constraint.constant.should == 0
2447
+ @constraint.relationship.should == :lte
2448
+ @constraint.multiplier.should == 1
2449
+ @constraint.relative_to.should == :another_view
2450
+ @constraint.attribute.should == :trailing
2451
+ @constraint.attribute2.should == :trailing
2452
+ end
2453
+ it 'should support `trailing.equals(:another_view).plus(10)`' do
2454
+ @layout.context(@view) do
2455
+ @layout.constraints do
2456
+ @constraint = @layout.trailing.equals(:another_view).plus(10)
2457
+ end
2458
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2459
+ end
2460
+
2461
+ @constraint.constant.should == 10
2462
+ @constraint.relationship.should == :equal
2463
+ @constraint.multiplier.should == 1
2464
+ @constraint.relative_to.should == :another_view
2465
+ @constraint.attribute.should == :trailing
2466
+ @constraint.attribute2.should == :trailing
2467
+ end
2468
+ it 'should support `min_trailing.equals(:another_view).plus(10)`' do
2469
+ @layout.context(@view) do
2470
+ @layout.constraints do
2471
+ @constraint = @layout.min_trailing.equals(:another_view).plus(10)
2472
+ end
2473
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2474
+ end
2475
+
2476
+ @constraint.constant.should == 10
2477
+ @constraint.relationship.should == :gte
2478
+ @constraint.multiplier.should == 1
2479
+ @constraint.relative_to.should == :another_view
2480
+ @constraint.attribute.should == :trailing
2481
+ @constraint.attribute2.should == :trailing
2482
+ end
2483
+ it 'should support `max_trailing.equals(:another_view).plus(10)`' do
2484
+ @layout.context(@view) do
2485
+ @layout.constraints do
2486
+ @constraint = @layout.max_trailing.equals(:another_view).plus(10)
2487
+ end
2488
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2489
+ end
2490
+
2491
+ @constraint.constant.should == 10
2492
+ @constraint.relationship.should == :lte
2493
+ @constraint.multiplier.should == 1
2494
+ @constraint.relative_to.should == :another_view
2495
+ @constraint.attribute.should == :trailing
2496
+ @constraint.attribute2.should == :trailing
2497
+ end
2498
+ it 'should support `trailing.equals(:another_view).times(2).plus(10)`' do
2499
+ @layout.context(@view) do
2500
+ @layout.constraints do
2501
+ @constraint = @layout.trailing.equals(:another_view).times(2).plus(10)
2502
+ end
2503
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2504
+ end
2505
+
2506
+ @constraint.constant.should == 10
2507
+ @constraint.relationship.should == :equal
2508
+ @constraint.multiplier.should == 2
2509
+ @constraint.relative_to.should == :another_view
2510
+ @constraint.attribute.should == :trailing
2511
+ @constraint.attribute2.should == :trailing
2512
+ end
2513
+ it 'should support `min_trailing.equals(:another_view).times(2).plus(10)`' do
2514
+ @layout.context(@view) do
2515
+ @layout.constraints do
2516
+ @constraint = @layout.min_trailing.equals(:another_view).times(2).plus(10)
2517
+ end
2518
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2519
+ end
2520
+
2521
+ @constraint.constant.should == 10
2522
+ @constraint.relationship.should == :gte
2523
+ @constraint.multiplier.should == 2
2524
+ @constraint.relative_to.should == :another_view
2525
+ @constraint.attribute.should == :trailing
2526
+ @constraint.attribute2.should == :trailing
2527
+ end
2528
+ it 'should support `max_trailing.equals(:another_view).times(2).plus(10)`' do
2529
+ @layout.context(@view) do
2530
+ @layout.constraints do
2531
+ @constraint = @layout.max_trailing.equals(:another_view).times(2).plus(10)
2532
+ end
2533
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2534
+ end
2535
+
2536
+ @constraint.constant.should == 10
2537
+ @constraint.relationship.should == :lte
2538
+ @constraint.multiplier.should == 2
2539
+ @constraint.relative_to.should == :another_view
2540
+ @constraint.attribute.should == :trailing
2541
+ @constraint.attribute2.should == :trailing
2542
+
2543
+ resolved = @constraint.resolve_all(@layout, @view)
2544
+ resolved.length.should == 1
2545
+ resolved[0].firstItem.should.be.kind_of(UIView)
2546
+ resolved[0].firstAttribute.should == NSLayoutAttributeTrailing
2547
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
2548
+ resolved[0].secondItem.should == @another_view
2549
+ resolved[0].secondAttribute.should == NSLayoutAttributeTrailing
2550
+ resolved[0].multiplier.should == 2
2551
+ resolved[0].constant.should == 10
2552
+ end
2553
+ end
2554
+
2555
+ describe '`baseline` support' do
2556
+ it 'should support `baseline 10`' do
2557
+ @layout.context(@view) do
2558
+ @layout.constraints do
2559
+ @constraint = @layout.baseline(10)
2560
+ end
2561
+ end
2562
+
2563
+ @constraint.constant.should == 10
2564
+ @constraint.relationship.should == :equal
2565
+ @constraint.multiplier.should == 1
2566
+ @constraint.relative_to.should == :superview
2567
+ @constraint.attribute.should == :baseline
2568
+ @constraint.attribute2.should == :baseline
2569
+
2570
+ resolved = @constraint.resolve_all(@layout, @view)
2571
+ resolved.length.should == 1
2572
+ resolved[0].firstItem.should.be.kind_of(UIView)
2573
+ resolved[0].firstAttribute.should == NSLayoutAttributeBaseline
2574
+ resolved[0].relation.should == NSLayoutRelationEqual
2575
+ resolved[0].secondItem.should == @parent_view
2576
+ resolved[0].secondAttribute.should == NSLayoutAttributeBaseline
2577
+ resolved[0].multiplier.should == 1
2578
+ resolved[0].constant.should == 10
2579
+ end
2580
+ it 'should support `min_baseline 10`' do
2581
+ @layout.context(@view) do
2582
+ @layout.constraints do
2583
+ @constraint = @layout.min_baseline(10)
2584
+ end
2585
+ end
2586
+
2587
+ @constraint.constant.should == 10
2588
+ @constraint.relationship.should == :gte
2589
+ @constraint.multiplier.should == 1
2590
+ @constraint.relative_to.should == :superview
2591
+ @constraint.attribute.should == :baseline
2592
+ @constraint.attribute2.should == :baseline
2593
+ end
2594
+ it 'should support `max_baseline 10`' do
2595
+ @layout.context(@view) do
2596
+ @layout.constraints do
2597
+ @constraint = @layout.max_baseline(10)
2598
+ end
2599
+ end
2600
+
2601
+ @constraint.constant.should == 10
2602
+ @constraint.relationship.should == :lte
2603
+ @constraint.multiplier.should == 1
2604
+ @constraint.relative_to.should == :superview
2605
+ @constraint.attribute.should == :baseline
2606
+ @constraint.attribute2.should == :baseline
2607
+ end
2608
+ it 'should support `baseline.equals(:another_view[, :baseline])`' do
2609
+ @layout.context(@view) do
2610
+ @layout.constraints do
2611
+ @constraint = @layout.baseline.equals(:another_view)
2612
+ end
2613
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2614
+ end
2615
+
2616
+ @constraint.constant.should == 0
2617
+ @constraint.relationship.should == :equal
2618
+ @constraint.multiplier.should == 1
2619
+ @constraint.relative_to.should == :another_view
2620
+ @constraint.attribute.should == :baseline
2621
+ @constraint.attribute2.should == :baseline
2622
+ end
2623
+ it 'should support `min_baseline.equals(:another_view[, :baseline])`' do
2624
+ @layout.context(@view) do
2625
+ @layout.constraints do
2626
+ @constraint = @layout.min_baseline.equals(:another_view)
2627
+ end
2628
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2629
+ end
2630
+
2631
+ @constraint.constant.should == 0
2632
+ @constraint.relationship.should == :gte
2633
+ @constraint.multiplier.should == 1
2634
+ @constraint.relative_to.should == :another_view
2635
+ @constraint.attribute.should == :baseline
2636
+ @constraint.attribute2.should == :baseline
2637
+ end
2638
+ it 'should support `max_baseline.equals(:another_view[, :baseline])`' do
2639
+ @layout.context(@view) do
2640
+ @layout.constraints do
2641
+ @constraint = @layout.max_baseline.equals(:another_view)
2642
+ end
2643
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2644
+ end
2645
+
2646
+ @constraint.constant.should == 0
2647
+ @constraint.relationship.should == :lte
2648
+ @constraint.multiplier.should == 1
2649
+ @constraint.relative_to.should == :another_view
2650
+ @constraint.attribute.should == :baseline
2651
+ @constraint.attribute2.should == :baseline
2652
+ end
2653
+ it 'should support `baseline.equals(:another_view).plus(10)`' do
2654
+ @layout.context(@view) do
2655
+ @layout.constraints do
2656
+ @constraint = @layout.baseline.equals(:another_view).plus(10)
2657
+ end
2658
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2659
+ end
2660
+
2661
+ @constraint.constant.should == 10
2662
+ @constraint.relationship.should == :equal
2663
+ @constraint.multiplier.should == 1
2664
+ @constraint.relative_to.should == :another_view
2665
+ @constraint.attribute.should == :baseline
2666
+ @constraint.attribute2.should == :baseline
2667
+ end
2668
+ it 'should support `min_baseline.equals(:another_view).plus(10)`' do
2669
+ @layout.context(@view) do
2670
+ @layout.constraints do
2671
+ @constraint = @layout.min_baseline.equals(:another_view).plus(10)
2672
+ end
2673
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2674
+ end
2675
+
2676
+ @constraint.constant.should == 10
2677
+ @constraint.relationship.should == :gte
2678
+ @constraint.multiplier.should == 1
2679
+ @constraint.relative_to.should == :another_view
2680
+ @constraint.attribute.should == :baseline
2681
+ @constraint.attribute2.should == :baseline
2682
+ end
2683
+ it 'should support `max_baseline.equals(:another_view).plus(10)`' do
2684
+ @layout.context(@view) do
2685
+ @layout.constraints do
2686
+ @constraint = @layout.max_baseline.equals(:another_view).plus(10)
2687
+ end
2688
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2689
+ end
2690
+
2691
+ @constraint.constant.should == 10
2692
+ @constraint.relationship.should == :lte
2693
+ @constraint.multiplier.should == 1
2694
+ @constraint.relative_to.should == :another_view
2695
+ @constraint.attribute.should == :baseline
2696
+ @constraint.attribute2.should == :baseline
2697
+ end
2698
+ it 'should support `baseline.equals(:another_view).times(2).plus(10)`' do
2699
+ @layout.context(@view) do
2700
+ @layout.constraints do
2701
+ @constraint = @layout.baseline.equals(:another_view).times(2).plus(10)
2702
+ end
2703
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2704
+ end
2705
+
2706
+ @constraint.constant.should == 10
2707
+ @constraint.relationship.should == :equal
2708
+ @constraint.multiplier.should == 2
2709
+ @constraint.relative_to.should == :another_view
2710
+ @constraint.attribute.should == :baseline
2711
+ @constraint.attribute2.should == :baseline
2712
+ end
2713
+ it 'should support `min_baseline.equals(:another_view).times(2).plus(10)`' do
2714
+ @layout.context(@view) do
2715
+ @layout.constraints do
2716
+ @constraint = @layout.min_baseline.equals(:another_view).times(2).plus(10)
2717
+ end
2718
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2719
+ end
2720
+
2721
+ @constraint.constant.should == 10
2722
+ @constraint.relationship.should == :gte
2723
+ @constraint.multiplier.should == 2
2724
+ @constraint.relative_to.should == :another_view
2725
+ @constraint.attribute.should == :baseline
2726
+ @constraint.attribute2.should == :baseline
2727
+ end
2728
+ it 'should support `max_baseline.equals(:another_view).times(2).plus(10)`' do
2729
+ @layout.context(@view) do
2730
+ @layout.constraints do
2731
+ @constraint = @layout.max_baseline.equals(:another_view).times(2).plus(10)
2732
+ end
2733
+ @another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
2734
+ end
2735
+
2736
+ @constraint.constant.should == 10
2737
+ @constraint.relationship.should == :lte
2738
+ @constraint.multiplier.should == 2
2739
+ @constraint.relative_to.should == :another_view
2740
+ @constraint.attribute.should == :baseline
2741
+ @constraint.attribute2.should == :baseline
2742
+
2743
+ resolved = @constraint.resolve_all(@layout, @view)
2744
+ resolved.length.should == 1
2745
+ resolved[0].firstItem.should.be.kind_of(UIView)
2746
+ resolved[0].firstAttribute.should == NSLayoutAttributeBaseline
2747
+ resolved[0].relation.should == NSLayoutRelationLessThanOrEqual
2748
+ resolved[0].secondItem.should == @another_view
2749
+ resolved[0].secondAttribute.should == NSLayoutAttributeBaseline
2750
+ resolved[0].multiplier.should == 2
2751
+ resolved[0].constant.should == 10
2752
+ end
2753
+ end
2754
+
2755
+ end