shoes-core 4.0.0.pre6 → 4.0.0.pre7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-picker +1 -1
  3. data/lib/shoes/app.rb +3 -3
  4. data/lib/shoes/arc.rb +6 -5
  5. data/lib/shoes/arrow.rb +31 -0
  6. data/lib/shoes/background.rb +1 -1
  7. data/lib/shoes/border.rb +1 -1
  8. data/lib/shoes/builtin_methods.rb +1 -1
  9. data/lib/shoes/color.rb +3 -3
  10. data/lib/shoes/color/dsl_helpers.rb +10 -7
  11. data/lib/shoes/color/hex_converter.rb +1 -1
  12. data/lib/shoes/common/attachable.rb +11 -0
  13. data/lib/shoes/common/background_element.rb +8 -0
  14. data/lib/shoes/common/hover.rb +7 -17
  15. data/lib/shoes/common/link_finder.rb +12 -0
  16. data/lib/shoes/common/positioning.rb +1 -1
  17. data/lib/shoes/common/state.rb +1 -1
  18. data/lib/shoes/common/style.rb +9 -4
  19. data/lib/shoes/common/translate.rb +24 -0
  20. data/lib/shoes/common/ui_element.rb +1 -0
  21. data/lib/shoes/common/visibility.rb +1 -1
  22. data/lib/shoes/configuration.rb +2 -2
  23. data/lib/shoes/core/version.rb +3 -1
  24. data/lib/shoes/dimensions.rb +6 -2
  25. data/lib/shoes/dsl.rb +34 -14
  26. data/lib/shoes/font.rb +1 -1
  27. data/lib/shoes/gradient.rb +2 -1
  28. data/lib/shoes/image.rb +2 -2
  29. data/lib/shoes/input_box.rb +2 -2
  30. data/lib/shoes/internal_app.rb +8 -8
  31. data/lib/shoes/line.rb +7 -6
  32. data/lib/shoes/link.rb +5 -6
  33. data/lib/shoes/list_box.rb +2 -2
  34. data/lib/shoes/logger.rb +2 -1
  35. data/lib/shoes/mock.rb +1 -0
  36. data/lib/shoes/mock/arrow.rb +15 -0
  37. data/lib/shoes/mock/rect.rb +2 -1
  38. data/lib/shoes/mock/slot.rb +5 -1
  39. data/lib/shoes/mock/star.rb +2 -1
  40. data/lib/shoes/oval.rb +5 -4
  41. data/lib/shoes/point.rb +2 -1
  42. data/lib/shoes/progress.rb +1 -1
  43. data/lib/shoes/rect.rb +3 -2
  44. data/lib/shoes/shape.rb +14 -9
  45. data/lib/shoes/slot.rb +54 -25
  46. data/lib/shoes/slot_contents.rb +1 -3
  47. data/lib/shoes/star.rb +4 -3
  48. data/lib/shoes/text.rb +5 -0
  49. data/lib/shoes/text_block.rb +9 -9
  50. data/lib/shoes/ui/picker.rb +5 -5
  51. data/lib/shoes/version.rb +3 -1
  52. data/lib/shoes/widget.rb +2 -2
  53. data/lib/shoes/window.rb +6 -0
  54. data/spec/shoes/app_spec.rb +16 -16
  55. data/spec/shoes/arc_spec.rb +1 -1
  56. data/spec/shoes/arrow_spec.rb +28 -0
  57. data/spec/shoes/background_spec.rb +2 -2
  58. data/spec/shoes/border_spec.rb +3 -3
  59. data/spec/shoes/builtin_methods_spec.rb +2 -2
  60. data/spec/shoes/button_spec.rb +4 -2
  61. data/spec/shoes/color_spec.rb +12 -12
  62. data/spec/shoes/common/attachable_spec.rb +32 -0
  63. data/spec/shoes/common/inspect_spec.rb +4 -4
  64. data/spec/shoes/common/remove_spec.rb +5 -5
  65. data/spec/shoes/common/rotate_spec.rb +1 -1
  66. data/spec/shoes/common/style_normalizer_spec.rb +4 -4
  67. data/spec/shoes/common/style_spec.rb +15 -11
  68. data/spec/shoes/common/translate_spec.rb +27 -0
  69. data/spec/shoes/dimension_spec.rb +111 -100
  70. data/spec/shoes/dimensions_spec.rb +344 -303
  71. data/spec/shoes/download_spec.rb +17 -17
  72. data/spec/shoes/flow_spec.rb +2 -2
  73. data/spec/shoes/framework_learning_spec.rb +3 -1
  74. data/spec/shoes/helpers/fake_absolute_element.rb +3 -2
  75. data/spec/shoes/helpers/fake_element.rb +3 -2
  76. data/spec/shoes/input_box_spec.rb +2 -2
  77. data/spec/shoes/internal_app_spec.rb +14 -14
  78. data/spec/shoes/link_spec.rb +18 -19
  79. data/spec/shoes/list_box_spec.rb +9 -8
  80. data/spec/shoes/oval_spec.rb +1 -1
  81. data/spec/shoes/point_spec.rb +3 -3
  82. data/spec/shoes/renamed_delegate_spec.rb +2 -2
  83. data/spec/shoes/shape_spec.rb +20 -20
  84. data/spec/shoes/shared_examples/common_methods.rb +2 -2
  85. data/spec/shoes/shared_examples/dsl.rb +2 -2
  86. data/spec/shoes/shared_examples/dsl/flow.rb +1 -1
  87. data/spec/shoes/shared_examples/dsl/pattern.rb +2 -2
  88. data/spec/shoes/shared_examples/dsl/rgb.rb +2 -2
  89. data/spec/shoes/shared_examples/dsl/shape.rb +11 -7
  90. data/spec/shoes/shared_examples/dsl/star.rb +44 -44
  91. data/spec/shoes/shared_examples/dsl/style.rb +1 -1
  92. data/spec/shoes/shared_examples/dsl/text_elements.rb +6 -3
  93. data/spec/shoes/shared_examples/dsl/video.rb +1 -1
  94. data/spec/shoes/shared_examples/dsl_app_context.rb +6 -5
  95. data/spec/shoes/shared_examples/hover.rb +2 -2
  96. data/spec/shoes/shared_examples/shared_element_method.rb +2 -2
  97. data/spec/shoes/shared_examples/slot.rb +32 -21
  98. data/spec/shoes/shared_examples/style.rb +1 -1
  99. data/spec/shoes/slot_spec.rb +24 -7
  100. data/spec/shoes/span_spec.rb +5 -5
  101. data/spec/shoes/spec_helper.rb +1 -1
  102. data/spec/shoes/stack_spec.rb +5 -5
  103. data/spec/shoes/text_block_dimensions_spec.rb +6 -3
  104. data/spec/shoes/text_block_spec.rb +13 -7
  105. data/spec/shoes/text_spec.rb +22 -0
  106. data/spec/shoes/ui/picker_spec.rb +3 -3
  107. data/spec/shoes/url_spec.rb +4 -4
  108. data/spec/shoes/widget_spec.rb +1 -1
  109. data/spec/shoes_spec.rb +3 -3
  110. data/spec/spec_helper.rb +8 -1
  111. metadata +17 -4
  112. data/bin/shoes +0 -1
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::Common::Translate do
4
+ let(:test_class) do
5
+ Class.new do
6
+ include Shoes::Common::Translate
7
+
8
+ attr_reader :translate
9
+
10
+ def initialize(translate)
11
+ @translate = translate
12
+ end
13
+ end
14
+ end
15
+
16
+ it 'allows nil' do
17
+ subject = test_class.new(nil)
18
+ expect(subject.translate_left).to eq(0)
19
+ expect(subject.translate_top).to eq(0)
20
+ end
21
+
22
+ it 'sets values' do
23
+ subject = test_class.new([10, 20])
24
+ expect(subject.translate_left).to eq(10)
25
+ expect(subject.translate_top).to eq(20)
26
+ end
27
+ end
@@ -1,35 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shoes::Dimension do
4
- subject {Shoes::Dimension.new parent_dimension}
5
- let(:start) {10}
6
- let(:extent) {21}
7
- let(:parent_element_start) {34}
8
- let(:parent_element_end) {83}
9
- let(:parent_element_extent) {600}
10
- let(:parent_dimension) { double 'parent_dimension',
11
- element_start: parent_element_start,
12
- element_end: parent_element_end,
13
- element_extent: parent_element_extent }
4
+ subject { Shoes::Dimension.new parent_dimension }
5
+ let(:start) { 10 }
6
+ let(:extent) { 21 }
7
+ let(:parent_element_start) { 34 }
8
+ let(:parent_element_end) { 83 }
9
+ let(:parent_element_extent) { 600 }
10
+ let(:parent_dimension) do
11
+ double 'parent_dimension',
12
+ element_start: parent_element_start,
13
+ element_end: parent_element_end,
14
+ element_extent: parent_element_extent
15
+ end
14
16
 
15
17
  ONE_PIXEL = 1 unless const_defined?(:ONE_PIXEL) && ONE_PIXEL == 1
16
18
 
17
19
  describe 'initialization' do
18
20
  describe 'without arguments (even no parent)' do
19
- subject {Shoes::Dimension.new nil}
20
-
21
- its(:start) {should eq nil}
22
- its(:end) {should eq nil}
23
- its(:extent) {should eq nil}
24
- its(:margin_start) {should eq 0}
25
- its(:margin_end) {should eq 0}
26
- its(:displace_start) {should eq 0}
27
- it {is_expected.not_to be_positioned}
28
- it {is_expected.not_to be_absolute_position}
21
+ subject { Shoes::Dimension.new nil }
22
+
23
+ its(:start) { should eq nil }
24
+ its(:end) { should eq nil }
25
+ its(:extent) { should eq nil }
26
+ its(:margin_start) { should eq 0 }
27
+ its(:margin_end) { should eq 0 }
28
+ its(:displace_start) { should eq 0 }
29
+ it { is_expected.not_to be_positioned }
30
+ it { is_expected.not_to be_absolute_position }
29
31
  end
30
32
 
31
33
  describe 'with a parent and being positioned itself' do
32
- subject {Shoes::Dimension.new parent_dimension}
34
+ subject { Shoes::Dimension.new parent_dimension }
33
35
 
34
36
  TESTING_OFFSET = 11
35
37
 
@@ -38,12 +40,12 @@ describe Shoes::Dimension do
38
40
  subject.extent = 10
39
41
  end
40
42
 
41
- its(:start) {should eq TESTING_OFFSET}
42
- its(:end) {should eq parent_element_end - subject.element_end}
43
+ its(:start) { should eq TESTING_OFFSET }
44
+ its(:end) { should eq parent_element_end - subject.element_end }
43
45
  end
44
46
 
45
47
  describe 'start as center' do
46
- subject {Shoes::Dimension.new parent_dimension, true}
48
+ subject { Shoes::Dimension.new parent_dimension, true }
47
49
 
48
50
  it 'takes start as the center' do
49
51
  subject.extent = 100
@@ -54,12 +56,15 @@ describe Shoes::Dimension do
54
56
  end
55
57
 
56
58
  describe '#extent' do
57
- let(:parent_element_extent) {600}
58
- let(:parent_extent) {580}
59
- let(:parent) {double 'parent', element_extent: parent_element_extent,
60
- extent: parent_extent}
59
+ let(:parent_element_extent) { 600 }
60
+ let(:parent_extent) { 580 }
61
+
62
+ let(:parent) do
63
+ double 'parent', element_extent: parent_element_extent,
64
+ extent: parent_extent
65
+ end
61
66
 
62
- subject {Shoes::Dimension.new parent}
67
+ subject { Shoes::Dimension.new parent }
63
68
 
64
69
  it 'gets and sets' do
65
70
  subject.extent = extent
@@ -127,13 +132,13 @@ describe Shoes::Dimension do
127
132
  it 'handles negative percent values' do
128
133
  subject.extent = '-10%'
129
134
  expect(subject.extent).to be_within(ONE_PIXEL).of 0.9 *
130
- parent_element_extent
135
+ parent_element_extent
131
136
  end
132
137
 
133
138
  it 'handles percent values with floats' do
134
139
  subject.extent = '20.5%'
135
140
  expect(subject.extent).to be_within(ONE_PIXEL).of 0.205 *
136
- parent_element_extent
141
+ parent_element_extent
137
142
  end
138
143
 
139
144
  it 'returns nil for invalid strings' do
@@ -144,14 +149,14 @@ describe Shoes::Dimension do
144
149
  end
145
150
 
146
151
  describe '#start' do
147
- let(:start) {23}
152
+ let(:start) { 23 }
148
153
 
149
154
  before :each do
150
155
  subject.start = start
151
156
  end
152
157
 
153
- its(:start) {should eq start}
154
- it {is_expected.to be_absolute_position}
158
+ its(:start) { should eq start }
159
+ it { is_expected.to be_absolute_position }
155
160
 
156
161
  it 'can set a start relative to parent element_extent' do
157
162
  subject.start = 0.3
@@ -167,7 +172,7 @@ describe Shoes::Dimension do
167
172
  end
168
173
 
169
174
  context '#without a parent' do
170
- let(:parent_dimension) {nil}
175
+ let(:parent_dimension) { nil }
171
176
 
172
177
  it 'just takes the relative value' do
173
178
  subject.start = 0.8
@@ -177,19 +182,19 @@ describe Shoes::Dimension do
177
182
  end
178
183
 
179
184
  describe 'with no parent but set dimensions' do
180
- subject {Shoes::Dimension.new}
185
+ subject { Shoes::Dimension.new }
181
186
 
182
187
  before :each do
183
188
  subject.absolute_start = 23
184
189
  subject.extent = 45
185
190
  end
186
191
 
187
- its(:end) {should be_nil}
188
- its(:start) {should be_nil}
192
+ its(:end) { should be_nil }
193
+ its(:start) { should be_nil }
189
194
  end
190
195
 
191
196
  describe '#absolute_start' do
192
- let(:absolute_start) {8}
197
+ let(:absolute_start) { 8 }
193
198
 
194
199
  before :each do
195
200
  subject.absolute_start = absolute_start
@@ -199,7 +204,7 @@ describe Shoes::Dimension do
199
204
  expect(subject.absolute_start).to eq absolute_start
200
205
  end
201
206
 
202
- it {is_expected.to be_positioned}
207
+ it { is_expected.to be_positioned }
203
208
  end
204
209
 
205
210
  describe '#absolute_end' do
@@ -217,19 +222,19 @@ describe Shoes::Dimension do
217
222
  end
218
223
 
219
224
  describe '#margins' do
220
- let(:margin_start) {11}
221
- let(:margin_end) {17}
225
+ let(:margin_start) { 11 }
226
+ let(:margin_end) { 17 }
222
227
 
223
228
  before :each do
224
229
  subject.margin_start = margin_start
225
230
  subject.margin_end = margin_end
226
231
  end
227
232
 
228
- its(:margin_start) {should eq margin_start}
229
- its(:margin_end) {should eq margin_end}
233
+ its(:margin_start) { should eq margin_start }
234
+ its(:margin_end) { should eq margin_end }
230
235
 
231
236
  context 'absolute_start set' do
232
- let(:absolute_start) {7}
237
+ let(:absolute_start) { 7 }
233
238
 
234
239
  before :each do
235
240
  subject.absolute_start = absolute_start
@@ -244,7 +249,7 @@ describe Shoes::Dimension do
244
249
  end
245
250
 
246
251
  context 'extent set' do
247
- let(:extent) {67}
252
+ let(:extent) { 67 }
248
253
 
249
254
  before :each do
250
255
  subject.extent = extent
@@ -256,60 +261,64 @@ describe Shoes::Dimension do
256
261
 
257
262
  it 'does influence element_end' do
258
263
  expect(subject.element_end).to eq absolute_start + extent -
259
- margin_end - ONE_PIXEL
264
+ margin_end - ONE_PIXEL
260
265
  end
261
266
  end
262
267
 
263
268
  context 'element_extent set' do
264
- let(:element_extent) {77}
269
+ let(:element_extent) { 77 }
265
270
 
266
271
  before :each do
267
272
  subject.element_extent = element_extent
268
273
  end
269
274
 
270
- its(:element_extent) {should eq element_extent}
271
- its(:extent) {should eq element_extent + margin_start + margin_end}
272
- its(:element_end) {should eq subject.element_start + element_extent -
273
- ONE_PIXEL}
275
+ its(:element_extent) { should eq element_extent }
276
+ its(:extent) { should eq element_extent + margin_start + margin_end }
277
+ its(:element_end) do
278
+ should eq subject.element_start + element_extent - ONE_PIXEL
279
+ end
274
280
  end
275
281
 
276
282
  describe 'relative margins' do
277
- let(:margin_start) {0.1}
278
- let(:margin_end) {0.2}
283
+ let(:margin_start) { 0.1 }
284
+ let(:margin_end) { 0.2 }
279
285
 
280
- its(:margin_start) {should be_within(ONE_PIXEL).of 0.1 *
281
- parent_element_extent}
282
- its(:margin_end) {should be_within(ONE_PIXEL).of 0.2 *
283
- parent_element_extent}
286
+ its(:margin_start) do
287
+ should be_within(ONE_PIXEL).of 0.1 * parent_element_extent
288
+ end
289
+
290
+ its(:margin_end) do
291
+ should be_within(ONE_PIXEL).of 0.2 * parent_element_extent
292
+ end
284
293
  end
285
294
  end
286
295
  end
287
296
 
288
297
  describe '#in_bounds?' do
289
- let(:absolute_start) {20}
290
- let(:extent) {100}
291
- let(:absolute_end) {20 + 100 - ONE_PIXEL} # -1 due to pixel counting adjustment
298
+ let(:absolute_start) { 20 }
299
+ let(:extent) { 100 }
300
+ let(:absolute_end) { 20 + 100 - ONE_PIXEL } # -1 due to pixel counting adjustment
292
301
 
293
302
  before :each do
294
303
  subject.absolute_start = absolute_start
295
304
  subject.extent = extent
296
305
  end
297
306
 
298
- its(:absolute_end) {should eq absolute_end}
299
-
300
- it {is_expected.to be_in_bounds absolute_start}
301
- it {is_expected.to be_in_bounds absolute_end}
302
- it {is_expected.to be_in_bounds absolute_start + ONE_PIXEL}
303
- it {is_expected.to be_in_bounds absolute_end - ONE_PIXEL}
304
- it {is_expected.to be_in_bounds 40}
305
- it {is_expected.to be_in_bounds 105}
306
- it {is_expected.to be_in_bounds 20.021}
307
- it {is_expected.not_to be_in_bounds absolute_end + ONE_PIXEL}
308
- it {is_expected.not_to be_in_bounds absolute_start - ONE_PIXEL }
309
- it {is_expected.not_to be_in_bounds(-5)}
310
- it {is_expected.not_to be_in_bounds 0}
311
- it {is_expected.not_to be_in_bounds 150}
312
- it {is_expected.not_to be_in_bounds 123178}
307
+ its(:absolute_end) { should eq absolute_end }
308
+
309
+ it { is_expected.to be_in_bounds absolute_start }
310
+ it { is_expected.to be_in_bounds absolute_end }
311
+ it { is_expected.to be_in_bounds absolute_start + ONE_PIXEL }
312
+ it { is_expected.to be_in_bounds absolute_end - ONE_PIXEL }
313
+ it { is_expected.to be_in_bounds 40 }
314
+ it { is_expected.to be_in_bounds 105 }
315
+ it { is_expected.to be_in_bounds 20.021 }
316
+ it { is_expected.not_to be_in_bounds absolute_end + ONE_PIXEL }
317
+ it { is_expected.not_to be_in_bounds absolute_start - ONE_PIXEL }
318
+ it { is_expected.not_to be_in_bounds(-5) }
319
+ it { is_expected.not_to be_in_bounds 0 }
320
+ it { is_expected.not_to be_in_bounds 150 }
321
+ it { is_expected.not_to be_in_bounds 123_178 }
313
322
  end
314
323
 
315
324
  it 'can displace the placement' do
@@ -346,12 +355,12 @@ describe Shoes::Dimension do
346
355
  end
347
356
 
348
357
  describe Shoes::ParentDimension do
349
- let(:parent) {Shoes::Dimension.new}
350
- let(:parent_start) {7}
351
- let(:parent_extent) {27}
352
- let(:margin) {5}
358
+ let(:parent) { Shoes::Dimension.new }
359
+ let(:parent_start) { 7 }
360
+ let(:parent_extent) { 27 }
361
+ let(:margin) { 5 }
353
362
 
354
- subject {Shoes::ParentDimension.new parent}
363
+ subject { Shoes::ParentDimension.new parent }
355
364
 
356
365
  before :each do
357
366
  parent.start = parent_start
@@ -359,19 +368,19 @@ describe Shoes::Dimension do
359
368
  end
360
369
 
361
370
  describe 'it takes some parent values if no values are set' do
362
- its(:extent) {should eq parent_extent}
371
+ its(:extent) { should eq parent_extent }
363
372
 
364
- its(:margin_start) {should eq 0}
365
- its(:margin_end) {should eq 0}
373
+ its(:margin_start) { should eq 0 }
374
+ its(:margin_end) { should eq 0 }
366
375
 
367
376
  context 'with parent absolute_start set' do
368
377
  before :each do
369
378
  parent.absolute_start = 11
370
379
  end
371
380
 
372
- its(:absolute_start) {should eq parent.element_start}
373
- its(:element_start) {should eq parent.element_start}
374
- its(:element_end) {should eq parent.element_end}
381
+ its(:absolute_start) { should eq parent.element_start }
382
+ its(:element_start) { should eq parent.element_start }
383
+ its(:element_end) { should eq parent.element_end }
375
384
  end
376
385
 
377
386
  context 'but it takes the parent margins into account' do
@@ -380,7 +389,7 @@ describe Shoes::Dimension do
380
389
  parent.margin_end = margin
381
390
  end
382
391
 
383
- its(:extent) {is_expected.to eq 17}
392
+ its(:extent) { is_expected.to eq 17 }
384
393
  end
385
394
  end
386
395
 
@@ -391,9 +400,9 @@ describe Shoes::Dimension do
391
400
  parent.absolute_start = 17
392
401
  end
393
402
 
394
- its(:start) {should eq start}
395
- its(:extent) {should eq extent}
396
- its(:absolute_start) {should eq 17}
403
+ its(:start) { should eq start }
404
+ its(:extent) { should eq extent }
405
+ its(:absolute_start) { should eq 17 }
397
406
 
398
407
  it 'can still handle special values like a negative extent' do
399
408
  subject.extent = -10
@@ -412,15 +421,17 @@ describe Shoes::Dimension do
412
421
  end
413
422
 
414
423
  describe 'it obeys parent bounds' do
415
- let(:parent_dimension) { double 'parent_dimension',
416
- element_start: 10,
417
- element_end: 20,
418
- absolute_start: 10,
419
- absolute_end: 20,
420
- extent: 10,
421
- element_extent: 10 }
422
-
423
- subject {Shoes::ParentDimension.new parent_dimension}
424
+ let(:parent_dimension) do
425
+ double 'parent_dimension',
426
+ element_start: 10,
427
+ element_end: 20,
428
+ absolute_start: 10,
429
+ absolute_end: 20,
430
+ extent: 10,
431
+ element_extent: 10
432
+ end
433
+
434
+ subject { Shoes::ParentDimension.new parent_dimension }
424
435
 
425
436
  it "gets the parent element_extent" do
426
437
  expect(subject.extent).to eq(10)
@@ -1,33 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shoes::Dimensions do
4
- let(:parent_left) {left}
5
- let(:parent_top) {top}
6
- let(:parent_width) {width}
7
- let(:parent_height) {height}
8
- let(:parent) {Shoes::AbsoluteDimensions.new parent_left, parent_top, parent_width, parent_height}
9
-
10
- let(:left) {10}
11
- let(:top) {20}
12
- let(:width) {100}
13
- let(:height) {150}
14
- let(:right) {17}
15
- let(:bottom) {23}
4
+ let(:parent_left) { left }
5
+ let(:parent_top) { top }
6
+ let(:parent_width) { width }
7
+ let(:parent_height) { height }
8
+ let(:parent) { Shoes::AbsoluteDimensions.new parent_left, parent_top, parent_width, parent_height }
9
+
10
+ let(:left) { 10 }
11
+ let(:top) { 20 }
12
+ let(:width) { 100 }
13
+ let(:height) { 150 }
14
+ let(:right) { 17 }
15
+ let(:bottom) { 23 }
16
16
  let(:opts) { {} }
17
- subject {Shoes::Dimensions.new parent, left, top, width, height, opts}
17
+ subject { Shoes::Dimensions.new parent, left, top, width, height, opts }
18
18
 
19
19
  shared_context 'margins' do
20
- let(:margin_left) {3}
21
- let(:margin_top) {5}
22
- let(:margin_right) {7}
23
- let(:margin_bottom) {11}
24
- let(:opts) { {margin_left: margin_left, margin_top: margin_top,
25
- margin_right: margin_right, margin_bottom: margin_bottom } }
20
+ let(:margin_left) { 3 }
21
+ let(:margin_top) { 5 }
22
+ let(:margin_right) { 7 }
23
+ let(:margin_bottom) { 11 }
24
+ let(:opts) do
25
+ {
26
+ margin_left: margin_left,
27
+ margin_top: margin_top,
28
+ margin_right: margin_right,
29
+ margin_bottom: margin_bottom
30
+ }
31
+ end
26
32
  end
27
33
 
28
34
  shared_context 'element dimensions set' do
29
- let(:element_width) {43}
30
- let(:element_height) {29}
35
+ let(:element_width) { 43 }
36
+ let(:element_height) { 29 }
31
37
 
32
38
  before :each do
33
39
  subject.element_width = element_width
@@ -41,66 +47,66 @@ describe Shoes::Dimensions do
41
47
  include InspectHelpers
42
48
 
43
49
  describe 'without arguments (defaults)' do
44
- subject {Shoes::Dimensions.new parent}
45
-
46
- its(:left) {should be_nil}
47
- its(:top) {should be_nil}
48
- its(:width) {should eq nil}
49
- its(:height) {should eq nil}
50
- its(:absolutely_positioned?) {should be_falsey}
51
- its(:absolute_x_position?) {should be_falsey}
52
- its(:absolute_y_position?) {should be_falsey}
53
- its(:absolute_left_position?) {should be_falsey}
54
- its(:absolute_top_position?) {should be_falsey}
55
- its(:absolute_right_position?) {should be_falsey}
56
- its(:absolute_bottom_position?) {should be_falsey}
57
- its(:margin) {should == [0, 0, 0, 0]}
58
- its(:margin_left) {should == 0}
59
- its(:margin_top) {should == 0}
60
- its(:margin_right) {should == 0}
61
- its(:margin_bottom) {should == 0}
62
- its(:element_width) {should == nil}
63
- its(:element_height) {should == nil}
64
- its(:to_s) {should == "(Shoes::Dimensions)"}
65
- its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]_,_[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/)}
50
+ subject { Shoes::Dimensions.new parent }
51
+
52
+ its(:left) { should be_nil }
53
+ its(:top) { should be_nil }
54
+ its(:width) { should eq nil }
55
+ its(:height) { should eq nil }
56
+ its(:absolutely_positioned?) { should be_falsey }
57
+ its(:absolute_x_position?) { should be_falsey }
58
+ its(:absolute_y_position?) { should be_falsey }
59
+ its(:absolute_left_position?) { should be_falsey }
60
+ its(:absolute_top_position?) { should be_falsey }
61
+ its(:absolute_right_position?) { should be_falsey }
62
+ its(:absolute_bottom_position?) { should be_falsey }
63
+ its(:margin) { should == [0, 0, 0, 0] }
64
+ its(:margin_left) { should be_zero }
65
+ its(:margin_top) { should be_zero }
66
+ its(:margin_right) { should be_zero }
67
+ its(:margin_bottom) { should be_zero }
68
+ its(:element_width) { should be_nil }
69
+ its(:element_height) { should be_nil }
70
+ its(:to_s) { should == "(Shoes::Dimensions)" }
71
+ its(:inspect) { should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]_,_[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/) }
66
72
  end
67
73
 
68
74
  describe 'with 2 arguments' do
69
- subject {Shoes::Dimensions.new parent, left, top}
70
-
71
- its(:left) {should eq left}
72
- its(:top) {should eq top}
73
- its(:width) {should eq nil}
74
- its(:height) {should eq nil}
75
- its(:absolutely_positioned?) {should be_truthy}
76
- its(:absolute_x_position?) {should be_truthy}
77
- its(:absolute_y_position?) {should be_truthy}
78
- its(:absolute_left_position?) {should be_truthy}
79
- its(:absolute_top_position?) {should be_truthy}
80
- its(:absolute_right_position?) {should be_falsey}
81
- its(:absolute_bottom_position?) {should be_falsey}
82
- its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/)}
75
+ subject { Shoes::Dimensions.new parent, left, top }
76
+
77
+ its(:left) { should eq left }
78
+ its(:top) { should eq top }
79
+ its(:width) { should eq nil }
80
+ its(:height) { should eq nil }
81
+ its(:absolutely_positioned?) { should be_truthy }
82
+ its(:absolute_x_position?) { should be_truthy }
83
+ its(:absolute_y_position?) { should be_truthy }
84
+ its(:absolute_left_position?) { should be_truthy }
85
+ its(:absolute_top_position?) { should be_truthy }
86
+ its(:absolute_right_position?) { should be_falsey }
87
+ its(:absolute_bottom_position?) { should be_falsey }
88
+ its(:inspect) { should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] _x_[)]/) }
83
89
  end
84
90
 
85
91
  describe 'with 4 arguments' do
86
- subject {Shoes::Dimensions.new parent, left, top, width, height}
92
+ subject { Shoes::Dimensions.new parent, left, top, width, height }
87
93
 
88
- its(:left) {should eq left}
89
- its(:top) {should eq top}
90
- its(:width) {should eq width}
91
- its(:height) {should eq height}
92
- its(:element_width) {should == width}
93
- its(:element_height) {should == height}
94
- its(:inspect) {should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] #{width}x#{height}[)]/)}
94
+ its(:left) { should eq left }
95
+ its(:top) { should eq top }
96
+ its(:width) { should eq width }
97
+ its(:height) { should eq height }
98
+ its(:element_width) { should == width }
99
+ its(:element_height) { should == height }
100
+ its(:inspect) { should match(/[(]Shoes::Dimensions:#{shoes_object_id_pattern} relative:[(]#{left},#{top}[)]->[(]_,_[)] absolute:[(]_,_[)]->[(]_,_[)] #{width}x#{height}[)]/) }
95
101
  end
96
102
 
97
103
  describe 'with relative width and height' do
98
- subject {Shoes::Dimensions.new parent, left, top, 0.5, 0.5}
104
+ subject { Shoes::Dimensions.new parent, left, top, 0.5, 0.5 }
99
105
 
100
- its(:left) {should eq left}
101
- its(:top) {should eq top}
102
- its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
103
- its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
106
+ its(:left) { should eq left }
107
+ its(:top) { should eq top }
108
+ its(:width) { should be_within(ONE_PIXEL).of 0.5 * parent.width }
109
+ its(:height) { should be_within(ONE_PIXEL).of 0.5 * parent.height }
104
110
 
105
111
  describe 'width/height change of the parent' do
106
112
  # note that here the first assertion/call is necessary as otherwise
@@ -121,12 +127,12 @@ describe Shoes::Dimensions do
121
127
  end
122
128
 
123
129
  describe 'a parent with margins' do
124
- let(:parent) {Shoes::AbsoluteDimensions.new parent_left,
125
- parent_top,
126
- parent_width,
127
- parent_height,
128
- margin: 20}
129
- subject {Shoes::Dimensions.new parent, left, top, 1.0, 1.0}
130
+ let(:parent) do
131
+ Shoes::AbsoluteDimensions.new parent_left, parent_top, parent_width,
132
+ parent_height, margin: 20
133
+ end
134
+
135
+ subject { Shoes::Dimensions.new parent, left, top, 1.0, 1.0 }
130
136
 
131
137
  it 'uses the element_width to calculate its own relative width' do
132
138
  expect(subject.width).to eq parent.element_width
@@ -136,147 +142,157 @@ describe Shoes::Dimensions do
136
142
  expect(subject.width).to be < parent.width
137
143
  end
138
144
 
139
- its(:height) {should eq parent.element_height}
145
+ its(:height) { should eq parent.element_height }
140
146
  end
141
147
  end
142
148
 
143
149
  describe 'with percentages' do
144
150
  describe 'with whole integers' do
145
- subject {Shoes::Dimensions.new parent, left, top, "50%", "50%"}
146
- its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
147
- its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
151
+ subject { Shoes::Dimensions.new parent, left, top, "50%", "50%" }
152
+ its(:width) { should be_within(ONE_PIXEL).of 0.5 * parent.width }
153
+ its(:height) { should be_within(ONE_PIXEL).of 0.5 * parent.height }
148
154
  end
149
155
 
150
156
  describe 'with floats' do
151
- subject {Shoes::Dimensions.new parent, left, top, "50.0%", "50.00%"}
152
- its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
153
- its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
157
+ subject { Shoes::Dimensions.new parent, left, top, "50.0%", "50.00%" }
158
+ its(:width) { should be_within(ONE_PIXEL).of 0.5 * parent.width }
159
+ its(:height) { should be_within(ONE_PIXEL).of 0.5 * parent.height }
154
160
  end
155
161
 
156
162
  describe 'with negatives' do
157
- subject {Shoes::Dimensions.new parent, left, top, "-10.0%", "-10.00%"}
158
- its(:width) {should be_within(ONE_PIXEL).of 0.9 * parent.width}
159
- its(:height) {should be_within(ONE_PIXEL).of 0.9 * parent.height}
163
+ subject { Shoes::Dimensions.new parent, left, top, "-10.0%", "-10.00%" }
164
+ its(:width) { should be_within(ONE_PIXEL).of 0.9 * parent.width }
165
+ its(:height) { should be_within(ONE_PIXEL).of 0.9 * parent.height }
160
166
  end
161
167
 
162
168
  describe 'with padded strings' do
163
- subject {Shoes::Dimensions.new parent, left, top, " 50 % ", "\t- 50 %\n"}
164
- its(:width) {should be_within(ONE_PIXEL).of 0.5 * parent.width}
165
- its(:height) {should be_within(ONE_PIXEL).of 0.5 * parent.height}
169
+ subject do
170
+ Shoes::Dimensions.new parent, left, top, " 50 % ", "\t- 50 %\n"
171
+ end
172
+
173
+ its(:width) { should be_within(ONE_PIXEL).of 0.5 * parent.width }
174
+ its(:height) { should be_within(ONE_PIXEL).of 0.5 * parent.height }
166
175
  end
167
176
  end
168
177
 
169
178
  describe 'with strings' do
170
179
  describe 'with integer strings' do
171
- subject {Shoes::Dimensions.new parent, "22", "20", "10", "10"}
180
+ subject { Shoes::Dimensions.new parent, "22", "20", "10", "10" }
172
181
 
173
- its(:left) {should eq 22}
174
- its(:top) {should eq 20}
175
- its(:width) {should eq 10}
176
- its(:height) {should eq 10}
182
+ its(:left) { should eq 22 }
183
+ its(:top) { should eq 20 }
184
+ its(:width) { should eq 10 }
185
+ its(:height) { should eq 10 }
177
186
  end
178
187
 
179
188
  describe 'with strings px' do
180
- subject {Shoes::Dimensions.new parent, "10px", "10px", "0px", "100px"}
189
+ subject { Shoes::Dimensions.new parent, "10px", "10px", "0px", "100px" }
181
190
 
182
- its(:left) {should eq 10}
183
- its(:top) {should eq 10}
184
- its(:width) {should eq 0}
185
- its(:height) {should eq 100}
191
+ its(:left) { should eq 10 }
192
+ its(:top) { should eq 10 }
193
+ its(:width) { should eq 0 }
194
+ its(:height) { should eq 100 }
186
195
  end
187
196
 
188
197
  describe 'white space with px is also ok' do
189
- subject {Shoes::Dimensions.new parent, "10 px", "20 px", "30px", "55 px"}
198
+ subject do
199
+ Shoes::Dimensions.new parent, "10 px", "20 px", "30px", "55 px"
200
+ end
190
201
 
191
- its(:left) {should eq 10}
192
- its(:top) {should eq 20}
193
- its(:width) {should eq 30}
194
- its(:height) {should eq 55}
202
+ its(:left) { should eq 10 }
203
+ its(:top) { should eq 20 }
204
+ its(:width) { should eq 30 }
205
+ its(:height) { should eq 55 }
195
206
  end
196
207
 
197
208
  describe 'with invalid integer strings' do
198
- subject {Shoes::Dimensions.new parent, "p100px", "Hell0", "hell0", "glob"}
209
+ subject do
210
+ Shoes::Dimensions.new parent, "p100px", "Hell0", "hell0", "glob"
211
+ end
199
212
 
200
- its(:left) {should be_nil}
201
- its(:top) {should be_nil}
202
- its(:width) {should be_nil}
203
- its(:height) {should be_nil}
213
+ its(:left) { should be_nil }
214
+ its(:top) { should be_nil }
215
+ its(:width) { should be_nil }
216
+ its(:height) { should be_nil }
204
217
  end
205
218
 
206
219
  describe 'with negative values' do
207
- let(:parent_width) {200}
208
- let(:parent_height) {300}
209
- subject {Shoes::Dimensions.new parent, "- 100", "-20px", "- 50px", "- 80"}
220
+ let(:parent_width) { 200 }
221
+ let(:parent_height) { 300 }
210
222
 
211
- its(:left) {should eq(-100)}
212
- its(:top) {should eq(-20)}
213
- its(:width) {should eq(parent_width - 50)}
214
- its(:height) {should eq(parent_height - 80)}
223
+ subject do
224
+ Shoes::Dimensions.new parent, "- 100", "-20px", "- 50px", "- 80"
225
+ end
226
+
227
+ its(:left) { should eq(-100) }
228
+ its(:top) { should eq(-20) }
229
+ its(:width) { should eq(parent_width - 50) }
230
+ its(:height) { should eq(parent_height - 80) }
215
231
  end
216
232
  end
217
233
 
218
234
  describe 'with negative width and height' do
219
235
  let(:width) { -50 }
220
236
  let(:height) { -50 }
221
- subject {Shoes::Dimensions.new parent, left, top, width, height}
237
+ subject { Shoes::Dimensions.new parent, left, top, width, height }
222
238
 
223
- its(:width) {should eq parent.width + width}
224
- its(:height) {should eq parent.height + height}
239
+ its(:width) { should eq parent.width + width }
240
+ its(:height) { should eq parent.height + height }
225
241
  end
226
242
 
227
243
  describe 'with relative negative width and height' do
228
- let(:width) {-0.2}
229
- let(:height) {-0.2}
244
+ let(:width) { -0.2 }
245
+ let(:height) { -0.2 }
230
246
 
231
- its(:width) {should be_within(ONE_PIXEL).of 0.8 * parent.width}
232
- its(:height) {should be_within(ONE_PIXEL).of 0.8 * parent.height}
247
+ its(:width) { should be_within(ONE_PIXEL).of 0.8 * parent.width }
248
+ its(:height) { should be_within(ONE_PIXEL).of 0.8 * parent.height }
233
249
  end
234
250
 
235
251
  describe 'with a hash' do
236
- subject { Shoes::Dimensions.new parent, left: left,
237
- top: top,
238
- width: width,
239
- height: height }
240
-
241
- its(:left) {should eq left}
242
- its(:top) {should eq top}
243
- its(:width) {should eq width}
244
- its(:height) {should eq height}
245
- its(:absolutely_positioned?) {should be_truthy}
246
- its(:absolute_x_position?) {should be_truthy}
247
- its(:absolute_y_position?) {should be_truthy}
252
+ subject do
253
+ Shoes::Dimensions.new parent, left: left, top: top, width: width,
254
+ height: height
255
+ end
256
+
257
+ its(:left) { should eq left }
258
+ its(:top) { should eq top }
259
+ its(:width) { should eq width }
260
+ its(:height) { should eq height }
261
+ its(:absolutely_positioned?) { should be_truthy }
262
+ its(:absolute_x_position?) { should be_truthy }
263
+ its(:absolute_y_position?) { should be_truthy }
248
264
 
249
265
  context 'missing width' do
250
- subject { Shoes::Dimensions.new parent, left: left,
251
- top: top,
252
- height: height }
266
+ subject do
267
+ Shoes::Dimensions.new parent, left: left, top: top, height: height
268
+ end
253
269
 
254
- its(:width) {should eq nil}
270
+ its(:width) { should eq nil }
255
271
  end
256
272
 
257
273
  describe 'with right and bottom' do
258
- subject {Shoes::Dimensions.new parent, right: right, bottom: bottom}
274
+ subject { Shoes::Dimensions.new parent, right: right, bottom: bottom }
259
275
 
260
- its(:right) {should eq right}
261
- its(:bottom) {should eq bottom}
262
- its(:absolute_x_position?) {should be_truthy}
263
- its(:absolute_y_position?) {should be_truthy}
264
- its(:absolute_left_position?) {should be_falsey}
265
- its(:absolute_top_position?) {should be_falsey}
266
- its(:absolute_right_position?) {should be_truthy}
267
- its(:absolute_bottom_position?) {should be_truthy}
276
+ its(:right) { should eq right }
277
+ its(:bottom) { should eq bottom }
278
+ its(:absolute_x_position?) { should be_truthy }
279
+ its(:absolute_y_position?) { should be_truthy }
280
+ its(:absolute_left_position?) { should be_falsey }
281
+ its(:absolute_top_position?) { should be_falsey }
282
+ its(:absolute_right_position?) { should be_truthy }
283
+ its(:absolute_bottom_position?) { should be_truthy }
268
284
  end
269
285
  end
270
286
 
271
287
  describe 'absolute_left and _top' do
272
- its(:absolute_left) {should eq nil}
273
- its(:absolute_top) {should eq nil}
274
- it {is_expected.not_to be_positioned}
288
+ its(:absolute_left) { should eq nil }
289
+ its(:absolute_top) { should eq nil }
290
+ it { is_expected.not_to be_positioned }
275
291
  end
276
292
 
277
293
  describe 'absolute extra values' do
278
- let(:absolute_left) {7}
279
- let(:absolute_top) {13}
294
+ let(:absolute_left) { 7 }
295
+ let(:absolute_top) { 13 }
280
296
 
281
297
  before :each do
282
298
  subject.absolute_left = absolute_left
@@ -321,12 +337,12 @@ describe Shoes::Dimensions do
321
337
 
322
338
  it 'returns an element_right' do
323
339
  expect(subject.element_right).to eq subject.element_left +
324
- element_width - ONE_PIXEL
340
+ element_width - ONE_PIXEL
325
341
  end
326
342
 
327
343
  it 'returns an element_bottom' do
328
344
  expect(subject.element_bottom).to eq subject.element_top +
329
- element_height - ONE_PIXEL
345
+ element_height - ONE_PIXEL
330
346
  end
331
347
  end
332
348
  end
@@ -385,7 +401,8 @@ describe Shoes::Dimensions do
385
401
  end
386
402
 
387
403
  it 'sets height to element_height plus margins' do
388
- expect(subject.height).to eq margin_top + element_height + margin_bottom
404
+ expect(subject.height).to eq margin_top + element_height +
405
+ margin_bottom
389
406
  end
390
407
 
391
408
  it 'sets that value for element_width' do
@@ -401,12 +418,12 @@ describe Shoes::Dimensions do
401
418
 
402
419
  describe 'centered (e.g. left and top are seen as coords for the center)' do
403
420
  describe '5 arguments' do
404
- subject {Shoes::Dimensions.new parent, 100, 50, 40, 20, center: true}
421
+ subject { Shoes::Dimensions.new parent, 100, 50, 40, 20, center: true }
405
422
 
406
- its(:left) {should eq 80}
407
- its(:top) {should eq 40}
408
- its(:width) {should eq 40}
409
- its(:height) {should eq 20}
423
+ its(:left) { should eq 80 }
424
+ its(:top) { should eq 40 }
425
+ its(:width) { should eq 40 }
426
+ its(:height) { should eq 20 }
410
427
 
411
428
  it 'reacts to a width change' do
412
429
  expect(subject.left).to eq(80)
@@ -422,31 +439,30 @@ describe Shoes::Dimensions do
422
439
  end
423
440
 
424
441
  describe 'hash' do
425
- subject {Shoes::Dimensions.new parent, left: 100,
426
- top: 50,
427
- width: 40,
428
- height: 20,
429
- center: true }
442
+ subject do
443
+ Shoes::Dimensions.new parent, left: 100, top: 50, width: 40, height: 20,
444
+ center: true
445
+ end
430
446
 
431
- its(:left) {should eq 80}
432
- its(:top) {should eq 40}
433
- its(:width) {should eq 40}
434
- its(:height) {should eq 20}
447
+ its(:left) { should eq 80 }
448
+ its(:top) { should eq 40 }
449
+ its(:width) { should eq 40 }
450
+ its(:height) { should eq 20 }
435
451
  end
436
452
  end
437
453
 
438
454
  describe 'additional dimension methods' do
439
455
  describe 'without height and width' do
440
- let(:width) {nil}
441
- let(:height) {nil}
456
+ let(:width) { nil }
457
+ let(:height) { nil }
442
458
  end
443
459
  end
444
460
 
445
461
  describe 'in_bounds?' do
446
- let(:left) {10}
447
- let(:top) {20}
448
- let(:width) {100}
449
- let(:height) {150}
462
+ let(:left) { 10 }
463
+ let(:top) { 20 }
464
+ let(:width) { 100 }
465
+ let(:height) { 150 }
450
466
 
451
467
  describe 'absolute position same as offset' do
452
468
  before :each do
@@ -454,94 +470,103 @@ describe Shoes::Dimensions do
454
470
  subject.absolute_top = top
455
471
  end
456
472
 
457
- it {is_expected.to be_in_bounds 30, 40}
458
- it {is_expected.to be_in_bounds left, top}
459
- it {is_expected.to be_in_bounds left + width - ONE_PIXEL,
460
- top + height - ONE_PIXEL}
461
- it {is_expected.not_to be_in_bounds left + width, top + height}
462
- it {is_expected.not_to be_in_bounds 30, top + height}
463
- it {is_expected.not_to be_in_bounds left + width, 40}
464
- it {is_expected.not_to be_in_bounds 0, 0}
465
- it {is_expected.not_to be_in_bounds 0, 40}
466
- it {is_expected.not_to be_in_bounds 40, 0}
467
- it {is_expected.not_to be_in_bounds 200, 50}
468
- it {is_expected.not_to be_in_bounds 80, 400}
469
- it {is_expected.not_to be_in_bounds 1000, 1000}
473
+ it { is_expected.to be_in_bounds 30, 40 }
474
+ it { is_expected.to be_in_bounds left, top }
475
+
476
+ it do
477
+ is_expected.to be_in_bounds left + width - ONE_PIXEL,
478
+ top + height - ONE_PIXEL
479
+ end
480
+
481
+ it { is_expected.not_to be_in_bounds left + width, top + height }
482
+ it { is_expected.not_to be_in_bounds 30, top + height }
483
+ it { is_expected.not_to be_in_bounds left + width, 40 }
484
+ it { is_expected.not_to be_in_bounds 0, 0 }
485
+ it { is_expected.not_to be_in_bounds 0, 40 }
486
+ it { is_expected.not_to be_in_bounds 40, 0 }
487
+ it { is_expected.not_to be_in_bounds 200, 50 }
488
+ it { is_expected.not_to be_in_bounds 80, 400 }
489
+ it { is_expected.not_to be_in_bounds 1000, 1000 }
470
490
  end
471
491
 
472
492
  describe 'with absolute position differing from relative' do
473
- let(:absolute_left) {150}
474
- let(:absolute_top) {50}
493
+ let(:absolute_left) { 150 }
494
+ let(:absolute_top) { 50 }
475
495
 
476
496
  before :each do
477
497
  subject.absolute_left = absolute_left
478
498
  subject.absolute_top = absolute_top
479
499
  end
480
500
 
481
- it {is_expected.not_to be_in_bounds 30, 40}
482
- it {is_expected.not_to be_in_bounds left, top}
483
- it {is_expected.not_to be_in_bounds 149, 75}
484
- it {is_expected.to be_in_bounds 200, absolute_top}
485
- it {is_expected.to be_in_bounds absolute_left, absolute_top}
486
- it {is_expected.to be_in_bounds absolute_left + width - ONE_PIXEL,
487
- absolute_top + height - ONE_PIXEL
488
- }
489
- it {is_expected.not_to be_in_bounds 80, 400}
501
+ it { is_expected.not_to be_in_bounds 30, 40 }
502
+ it { is_expected.not_to be_in_bounds left, top }
503
+ it { is_expected.not_to be_in_bounds 149, 75 }
504
+ it { is_expected.to be_in_bounds 200, absolute_top }
505
+ it { is_expected.to be_in_bounds absolute_left, absolute_top }
506
+
507
+ it do
508
+ is_expected.to be_in_bounds absolute_left + width - ONE_PIXEL,
509
+ absolute_top + height - ONE_PIXEL
510
+ end
511
+
512
+ it { is_expected.not_to be_in_bounds 80, 400 }
490
513
  end
491
514
  end
492
515
 
493
516
  describe 'absolute positioning' do
494
- subject {Shoes::Dimensions.new parent}
495
- its(:absolutely_positioned?) {should be_falsey}
517
+ subject { Shoes::Dimensions.new parent }
518
+ its(:absolutely_positioned?) { should be_falsey }
496
519
 
497
520
  shared_examples_for 'absolute_x_position' do
498
- its(:absolute_x_position?) {should be_truthy}
499
- its(:absolute_y_position?) {should be_falsey}
500
- its(:absolutely_positioned?) {should be_truthy}
521
+ its(:absolute_x_position?) { should be_truthy }
522
+ its(:absolute_y_position?) { should be_falsey }
523
+ its(:absolutely_positioned?) { should be_truthy }
501
524
  end
502
525
 
503
526
  describe 'changing left' do
504
- before :each do subject.left = left end
527
+ before { subject.left = left }
505
528
  it_behaves_like 'absolute_x_position'
506
529
  end
507
530
 
508
531
  describe 'chaning right' do
509
- before :each do subject.right = right end
532
+ before { subject.right = right }
510
533
  it_behaves_like 'absolute_x_position'
511
534
  end
512
535
 
513
536
  shared_examples_for 'absolute_y_position' do
514
- its(:absolute_x_position?) {should be_falsey}
515
- its(:absolute_y_position?) {should be_truthy}
516
- its(:absolutely_positioned?) {should be_truthy}
537
+ its(:absolute_x_position?) { should be_falsey }
538
+ its(:absolute_y_position?) { should be_truthy }
539
+ its(:absolutely_positioned?) { should be_truthy }
517
540
  end
518
541
 
519
542
  describe 'changing top' do
520
- before :each do subject.top = top end
543
+ before { subject.top = top }
521
544
  it_behaves_like 'absolute_y_position'
522
545
  end
523
546
 
524
547
  describe 'changing bottom' do
525
- before :each do subject.bottom = bottom end
548
+ before { subject.bottom = bottom }
526
549
  it_behaves_like 'absolute_y_position'
527
550
  end
528
551
  end
529
552
 
530
553
  describe 'margins' do
531
554
  describe 'creation with single margin value' do
532
- let(:margin) {13}
533
- subject {Shoes::Dimensions.new parent, width: width, height: height,
534
- margin: margin}
535
-
536
- its(:margin) {should == [margin, margin, margin, margin]}
537
- its(:margin_left) {should == margin}
538
- its(:margin_top) {should == margin}
539
- its(:margin_right) {should == margin}
540
- its(:margin_bottom) {should == margin}
541
- its(:width) {should == width}
542
- its(:height) {should == height}
543
- its(:element_width) {should == width - 2 * margin}
544
- its(:element_height) {should == height - 2 * margin}
555
+ let(:margin) { 13 }
556
+ subject do
557
+ Shoes::Dimensions.new parent, width: width, height: height,
558
+ margin: margin
559
+ end
560
+
561
+ its(:margin) { should == [margin, margin, margin, margin] }
562
+ its(:margin_left) { should == margin }
563
+ its(:margin_top) { should == margin }
564
+ its(:margin_right) { should == margin }
565
+ its(:margin_bottom) { should == margin }
566
+ its(:width) { should == width }
567
+ its(:height) { should == height }
568
+ its(:element_width) { should == width - 2 * margin }
569
+ its(:element_height) { should == height - 2 * margin }
545
570
 
546
571
  it 'adapts margin when one of the margins is changed' do
547
572
  subject.margin_right = 7
@@ -560,39 +585,46 @@ describe Shoes::Dimensions do
560
585
  end
561
586
 
562
587
  describe 'creation with all distinct margin values' do
563
- let(:margin_left) {3}
564
- let(:margin_top) {7}
565
- let(:margin_right) {11}
566
- let(:margin_bottom) {17}
588
+ let(:margin_left) { 3 }
589
+ let(:margin_top) { 7 }
590
+ let(:margin_right) { 11 }
591
+ let(:margin_bottom) { 17 }
567
592
 
568
593
  shared_examples_for 'all distinct margins' do
569
- its(:margin) {should == [margin_left, margin_top, margin_right, margin_bottom]}
570
- its(:margin_left) {should == margin_left}
571
- its(:margin_top) {should == margin_top}
572
- its(:margin_right) {should == margin_right}
573
- its(:margin_bottom) {should == margin_bottom}
574
- its(:width) {should == width}
575
- its(:height) {should == height}
576
- its(:element_width) {should == width - (margin_left + margin_right)}
577
- its(:element_height) {should == height - (margin_top + margin_bottom)}
594
+ its(:margin) do
595
+ should == [margin_left, margin_top, margin_right, margin_bottom]
596
+ end
597
+ its(:margin_left) { should == margin_left }
598
+ its(:margin_top) { should == margin_top }
599
+ its(:margin_right) { should == margin_right }
600
+ its(:margin_bottom) { should == margin_bottom }
601
+ its(:width) { should == width }
602
+ its(:height) { should == height }
603
+ its(:element_width) { should == width - (margin_left + margin_right) }
604
+ its(:element_height) { should == height - (margin_top + margin_bottom) }
578
605
  end
579
606
 
580
607
  describe 'setting margins separetely through hash' do
581
- subject {Shoes::Dimensions.new parent, width: width,
582
- height: height,
583
- margin_left: margin_left,
584
- margin_top: margin_top,
585
- margin_right: margin_right,
586
- margin_bottom: margin_bottom}
608
+ subject do
609
+ Shoes::Dimensions.new parent, width: width,
610
+ height: height,
611
+ margin_left: margin_left,
612
+ margin_top: margin_top,
613
+ margin_right: margin_right,
614
+ margin_bottom: margin_bottom
615
+ end
616
+
587
617
  it_behaves_like 'all distinct margins'
588
618
  end
589
619
 
590
620
  describe 'setting margins through margin array' do
591
- subject {Shoes::Dimensions.new parent,
592
- width: width,
593
- height: height,
594
- margin: [margin_left, margin_top,
595
- margin_right, margin_bottom]}
621
+ subject do
622
+ Shoes::Dimensions.new parent, width: width,
623
+ height: height,
624
+ margin: [margin_left, margin_top,
625
+ margin_right, margin_bottom]
626
+ end
627
+
596
628
  it_behaves_like 'all distinct margins'
597
629
  end
598
630
  end
@@ -606,21 +638,21 @@ describe Shoes::Dimensions do
606
638
  end
607
639
 
608
640
  describe 'displace_left' do
609
- let(:displace_left) {3}
641
+ let(:displace_left) { 3 }
610
642
  it 'modifies the value of element_left' do
611
643
  expect do
612
644
  subject.displace_left = displace_left
613
- end.to change {subject.element_left}.by(displace_left)
645
+ end.to change { subject.element_left }.by(displace_left)
614
646
  end
615
647
 
616
648
  it 'does not modify the value of absolute_left' do
617
649
  expect do
618
650
  subject.displace_left = displace_left
619
- end.not_to change {subject.absolute_left}
651
+ end.not_to change { subject.absolute_left }
620
652
  end
621
653
 
622
654
  context 'via opts' do
623
- subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_left: 10)}
655
+ subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_left: 10) }
624
656
  it 'modifies element_left' do
625
657
  expect(subject.element_left).to eql(10)
626
658
  end
@@ -628,22 +660,22 @@ describe Shoes::Dimensions do
628
660
  end
629
661
 
630
662
  describe 'displace_top' do
631
- let(:displace_top) {7}
663
+ let(:displace_top) { 7 }
632
664
 
633
665
  it 'modifies the value of element_top' do
634
666
  expect do
635
667
  subject.displace_top = displace_top
636
- end.to change {subject.element_top}.by(displace_top)
668
+ end.to change { subject.element_top }.by(displace_top)
637
669
  end
638
670
 
639
671
  it 'does not modify the value of absolute_top' do
640
672
  expect do
641
673
  subject.displace_top = displace_top
642
- end.not_to change {subject.absolute_top}
674
+ end.not_to change { subject.absolute_top }
643
675
  end
644
676
 
645
677
  context 'via opts' do
646
- subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_top: 10)}
678
+ subject { Shoes::Dimensions.new(nil, 0, 0, 0, 0, displace_top: 10) }
647
679
  it 'modifies element_top' do
648
680
  expect(subject.element_top).to eql(10)
649
681
  end
@@ -651,23 +683,30 @@ describe Shoes::Dimensions do
651
683
  end
652
684
  end
653
685
 
654
- it {is_expected.to be_takes_up_space}
686
+ it { is_expected.to be_takes_up_space }
655
687
 
656
688
  describe 'left/top/right/bottom not set so get them relative to parent' do
657
- let(:parent) {double 'parent', x_dimension: x_dimension,
658
- y_dimension: y_dimension}
689
+ let(:parent) do
690
+ double 'parent', x_dimension: x_dimension, y_dimension: y_dimension
691
+ end
692
+
693
+ let(:x_dimension) do
694
+ double 'parent x dimension', element_start: parent_left,
695
+ element_end: parent_right
696
+ end
659
697
 
660
- let(:x_dimension) {double 'parent x dimension', element_start: parent_left,
661
- element_end: parent_right}
662
- let(:y_dimension) {double 'parent y dimension', element_start: parent_top,
663
- element_end: parent_bottom}
664
- let(:parent_right) {parent_left + 20}
665
- let(:parent_bottom) {parent_top + 30}
698
+ let(:y_dimension) do
699
+ double 'parent y dimension', element_start: parent_top,
700
+ element_end: parent_bottom
701
+ end
702
+
703
+ let(:parent_right) { parent_left + 20 }
704
+ let(:parent_bottom) { parent_top + 30 }
666
705
 
667
- let(:width) {3}
668
- let(:height) {5}
706
+ let(:width) { 3 }
707
+ let(:height) { 5 }
669
708
 
670
- subject {Shoes::Dimensions.new parent, width: width, height: height}
709
+ subject { Shoes::Dimensions.new parent, width: width, height: height }
671
710
 
672
711
  describe 'positioned at the start' do
673
712
  before :each do
@@ -676,10 +715,10 @@ describe Shoes::Dimensions do
676
715
  subject.absolute_top = parent_top
677
716
  end
678
717
 
679
- its(:left) {should eq 0}
680
- its(:top) {should eq 0}
681
- its(:right) {should eq parent_right - subject.element_right}
682
- its(:bottom) {should eq parent_bottom - subject.element_bottom}
718
+ its(:left) { should eq 0 }
719
+ its(:top) { should eq 0 }
720
+ its(:right) { should eq parent_right - subject.element_right }
721
+ its(:bottom) { should eq parent_bottom - subject.element_bottom }
683
722
  end
684
723
 
685
724
  describe 'positioned with an offset' do
@@ -690,17 +729,17 @@ describe Shoes::Dimensions do
690
729
  subject.absolute_top = parent_top + TEST_OFFSET
691
730
  end
692
731
 
693
- its(:left) {should eq TEST_OFFSET}
694
- its(:top) {should eq TEST_OFFSET}
695
- its(:right) {should eq parent_right - subject.element_right}
696
- its(:bottom) {should eq parent_bottom - subject.element_bottom}
732
+ its(:left) { should eq TEST_OFFSET }
733
+ its(:top) { should eq TEST_OFFSET }
734
+ its(:right) { should eq parent_right - subject.element_right }
735
+ its(:bottom) { should eq parent_bottom - subject.element_bottom }
697
736
  end
698
737
  end
699
738
 
700
739
  describe Shoes::AbsoluteDimensions do
701
- subject {Shoes::AbsoluteDimensions.new left, top, width, height}
740
+ subject { Shoes::AbsoluteDimensions.new left, top, width, height }
702
741
  describe 'not adapting floats to parent values' do
703
- subject {Shoes::AbsoluteDimensions.new left, top, 1.04, 2.10}
742
+ subject { Shoes::AbsoluteDimensions.new left, top, 1.04, 2.10 }
704
743
  it 'does not adapt width' do
705
744
  expect(subject.width).to be_within(0.01).of 1.04
706
745
  end
@@ -713,20 +752,22 @@ describe Shoes::Dimensions do
713
752
 
714
753
  describe Shoes::ParentDimensions do
715
754
  describe 'takes some parent values if not specified' do
716
- let(:parent) {Shoes::Dimensions.new nil, parent_left, parent_top,
717
- parent_width, parent_height,
718
- margin: 20}
719
- subject {Shoes::ParentDimensions.new parent}
755
+ let(:parent) do
756
+ Shoes::Dimensions.new nil, parent_left, parent_top, parent_width,
757
+ parent_height, margin: 20
758
+ end
759
+
760
+ subject { Shoes::ParentDimensions.new parent }
720
761
 
721
- its(:left) {should eq nil}
722
- its(:top) {should eq nil}
723
- its(:width) {should eq parent.element_width}
724
- its(:height) {should eq parent.element_height}
762
+ its(:left) { should eq nil }
763
+ its(:top) { should eq nil }
764
+ its(:width) { should eq parent.element_width }
765
+ its(:height) { should eq parent.element_height }
725
766
 
726
- its(:margin_left) {should eq 0}
727
- its(:margin_top) {should eq 0}
728
- its(:margin_right) {should eq 0}
729
- its(:margin_bottom) {should eq 0}
767
+ its(:margin_left) { should eq 0 }
768
+ its(:margin_top) { should eq 0 }
769
+ its(:margin_right) { should eq 0 }
770
+ its(:margin_bottom) { should eq 0 }
730
771
 
731
772
  context 'with parent absolute_left/top set' do
732
773
  before :each do
@@ -734,20 +775,20 @@ describe Shoes::Dimensions do
734
775
  parent.absolute_top = top
735
776
  end
736
777
 
737
- its(:absolute_left) {should eq parent.element_left}
738
- its(:absolute_top) {should eq parent.element_top}
739
- its(:element_left) {should eq parent.element_left}
740
- its(:element_top) {should eq parent.element_top}
778
+ its(:absolute_left) { should eq parent.element_left }
779
+ its(:absolute_top) { should eq parent.element_top }
780
+ its(:element_left) { should eq parent.element_left }
781
+ its(:element_top) { should eq parent.element_top }
741
782
  end
742
783
  end
743
784
 
744
785
  describe 'otherwise it takes its own values' do
745
- subject {Shoes::ParentDimensions.new parent, left, top, width, height}
786
+ subject { Shoes::ParentDimensions.new parent, left, top, width, height }
746
787
 
747
- its(:left) {should eq left}
748
- its(:top) {should eq top}
749
- its(:width) {should eq width}
750
- its(:height) {should eq height}
788
+ its(:left) { should eq left }
789
+ its(:top) { should eq top }
790
+ its(:width) { should eq width }
791
+ its(:height) { should eq height }
751
792
 
752
793
  it 'can also still handle special values like a negative width' do
753
794
  subject.width = -10
@@ -764,7 +805,7 @@ end
764
805
 
765
806
  describe Shoes::DimensionsDelegations do
766
807
  describe 'with a DSL class and a dimensions method' do
767
- let(:dimensions) {double('dimensions')}
808
+ let(:dimensions) { double('dimensions') }
768
809
 
769
810
  class DummyClass
770
811
  include Shoes::DimensionsDelegations
@@ -800,7 +841,7 @@ describe Shoes::DimensionsDelegations do
800
841
  end
801
842
 
802
843
  describe 'with any backend class that has a defined dsl method' do
803
- let(:dsl) {double 'dsl'}
844
+ let(:dsl) { double 'dsl' }
804
845
 
805
846
  class AnotherDummyClass
806
847
  include Shoes::BackendDimensionsDelegations
@@ -821,7 +862,7 @@ describe Shoes::DimensionsDelegations do
821
862
 
822
863
  it 'does not forward calls to parent' do
823
864
  expect(dsl).not_to receive :parent
824
- expect {subject.parent}.to raise_error(NoMethodError)
865
+ expect { subject.parent }.to raise_error(NoMethodError)
825
866
  end
826
867
  end
827
868
  end