motion-kit 0.0.1 → 0.9.0

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