shoes-dsl 4.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +84 -0
  3. data/Gemfile +24 -0
  4. data/Guardfile +11 -0
  5. data/LICENSE +31 -0
  6. data/README.md +201 -0
  7. data/ext/install/Rakefile +29 -0
  8. data/ext/install/shoes.bat +9 -0
  9. data/fonts/Coolvetica.ttf +0 -0
  10. data/fonts/Lacuna.ttf +0 -0
  11. data/lib/shoes/animation.rb +56 -0
  12. data/lib/shoes/app.rb +131 -0
  13. data/lib/shoes/arc.rb +25 -0
  14. data/lib/shoes/background.rb +24 -0
  15. data/lib/shoes/border.rb +24 -0
  16. data/lib/shoes/builtin_methods.rb +77 -0
  17. data/lib/shoes/button.rb +30 -0
  18. data/lib/shoes/check_button.rb +44 -0
  19. data/lib/shoes/color.rb +385 -0
  20. data/lib/shoes/common/background_element.rb +9 -0
  21. data/lib/shoes/common/changeable.rb +34 -0
  22. data/lib/shoes/common/clickable.rb +24 -0
  23. data/lib/shoes/common/inspect.rb +14 -0
  24. data/lib/shoes/common/positioning.rb +30 -0
  25. data/lib/shoes/common/registration.rb +33 -0
  26. data/lib/shoes/common/remove.rb +10 -0
  27. data/lib/shoes/common/state.rb +18 -0
  28. data/lib/shoes/common/style.rb +152 -0
  29. data/lib/shoes/common/style_normalizer.rb +16 -0
  30. data/lib/shoes/common/ui_element.rb +11 -0
  31. data/lib/shoes/common/visibility.rb +40 -0
  32. data/lib/shoes/configuration.rb +96 -0
  33. data/lib/shoes/dialog.rb +27 -0
  34. data/lib/shoes/dimension.rb +239 -0
  35. data/lib/shoes/dimensions.rb +209 -0
  36. data/lib/shoes/download.rb +121 -0
  37. data/lib/shoes/dsl.rb +591 -0
  38. data/lib/shoes/font.rb +49 -0
  39. data/lib/shoes/gradient.rb +31 -0
  40. data/lib/shoes/image.rb +29 -0
  41. data/lib/shoes/image_pattern.rb +12 -0
  42. data/lib/shoes/input_box.rb +60 -0
  43. data/lib/shoes/internal_app.rb +219 -0
  44. data/lib/shoes/key_event.rb +17 -0
  45. data/lib/shoes/line.rb +87 -0
  46. data/lib/shoes/link.rb +59 -0
  47. data/lib/shoes/link_hover.rb +5 -0
  48. data/lib/shoes/list_box.rb +50 -0
  49. data/lib/shoes/logger.rb +66 -0
  50. data/lib/shoes/logger/ruby.rb +18 -0
  51. data/lib/shoes/mock.rb +31 -0
  52. data/lib/shoes/mock/animation.rb +8 -0
  53. data/lib/shoes/mock/app.rb +47 -0
  54. data/lib/shoes/mock/arc.rb +9 -0
  55. data/lib/shoes/mock/background.rb +10 -0
  56. data/lib/shoes/mock/border.rb +7 -0
  57. data/lib/shoes/mock/button.rb +10 -0
  58. data/lib/shoes/mock/check.rb +25 -0
  59. data/lib/shoes/mock/clickable.rb +8 -0
  60. data/lib/shoes/mock/common_methods.rb +12 -0
  61. data/lib/shoes/mock/dialog.rb +13 -0
  62. data/lib/shoes/mock/download.rb +18 -0
  63. data/lib/shoes/mock/font.rb +17 -0
  64. data/lib/shoes/mock/image.rb +13 -0
  65. data/lib/shoes/mock/image_pattern.rb +9 -0
  66. data/lib/shoes/mock/input_box.rb +30 -0
  67. data/lib/shoes/mock/keypress.rb +10 -0
  68. data/lib/shoes/mock/keyrelease.rb +10 -0
  69. data/lib/shoes/mock/line.rb +14 -0
  70. data/lib/shoes/mock/link.rb +12 -0
  71. data/lib/shoes/mock/list_box.rb +19 -0
  72. data/lib/shoes/mock/oval.rb +12 -0
  73. data/lib/shoes/mock/progress.rb +10 -0
  74. data/lib/shoes/mock/radio.rb +27 -0
  75. data/lib/shoes/mock/rect.rb +14 -0
  76. data/lib/shoes/mock/shape.rb +20 -0
  77. data/lib/shoes/mock/slot.rb +16 -0
  78. data/lib/shoes/mock/sound.rb +8 -0
  79. data/lib/shoes/mock/star.rb +14 -0
  80. data/lib/shoes/mock/text_block.rb +36 -0
  81. data/lib/shoes/mock/timer.rb +8 -0
  82. data/lib/shoes/not_implemented_error.rb +4 -0
  83. data/lib/shoes/oval.rb +20 -0
  84. data/lib/shoes/point.rb +54 -0
  85. data/lib/shoes/progress.rb +25 -0
  86. data/lib/shoes/radio.rb +16 -0
  87. data/lib/shoes/rect.rb +21 -0
  88. data/lib/shoes/renamed_delegate.rb +15 -0
  89. data/lib/shoes/shape.rb +158 -0
  90. data/lib/shoes/slot.rb +271 -0
  91. data/lib/shoes/slot_contents.rb +50 -0
  92. data/lib/shoes/sound.rb +18 -0
  93. data/lib/shoes/span.rb +16 -0
  94. data/lib/shoes/star.rb +45 -0
  95. data/lib/shoes/text.rb +24 -0
  96. data/lib/shoes/text_block.rb +143 -0
  97. data/lib/shoes/text_block_dimensions.rb +52 -0
  98. data/lib/shoes/timer.rb +12 -0
  99. data/lib/shoes/url.rb +44 -0
  100. data/lib/shoes/version.rb +3 -0
  101. data/lib/shoes/widget.rb +69 -0
  102. data/manifests/common.rb +34 -0
  103. data/manifests/shoes-dsl.rb +34 -0
  104. data/shoes-dsl.gemspec +19 -0
  105. data/spec/code_coverage.rb +14 -0
  106. data/spec/shoes/animation_spec.rb +65 -0
  107. data/spec/shoes/app_spec.rb +484 -0
  108. data/spec/shoes/arc_spec.rb +51 -0
  109. data/spec/shoes/background_spec.rb +53 -0
  110. data/spec/shoes/border_spec.rb +47 -0
  111. data/spec/shoes/builtin_methods_spec.rb +110 -0
  112. data/spec/shoes/button_spec.rb +44 -0
  113. data/spec/shoes/check_spec.rb +35 -0
  114. data/spec/shoes/cli_spec.rb +15 -0
  115. data/spec/shoes/color_spec.rb +408 -0
  116. data/spec/shoes/common/inspect_spec.rb +26 -0
  117. data/spec/shoes/common/remove_spec.rb +38 -0
  118. data/spec/shoes/common/style_normalizer_spec.rb +28 -0
  119. data/spec/shoes/common/style_spec.rb +147 -0
  120. data/spec/shoes/configuration_spec.rb +36 -0
  121. data/spec/shoes/constants_spec.rb +38 -0
  122. data/spec/shoes/dialog_spec.rb +163 -0
  123. data/spec/shoes/dimension_spec.rb +407 -0
  124. data/spec/shoes/dimensions_spec.rb +837 -0
  125. data/spec/shoes/download_spec.rb +142 -0
  126. data/spec/shoes/flow_spec.rb +133 -0
  127. data/spec/shoes/font_spec.rb +37 -0
  128. data/spec/shoes/framework_learning_spec.rb +30 -0
  129. data/spec/shoes/gradient_spec.rb +32 -0
  130. data/spec/shoes/helpers/fake_element.rb +17 -0
  131. data/spec/shoes/helpers/inspect_helpers.rb +5 -0
  132. data/spec/shoes/helpers/sample17_helper.rb +66 -0
  133. data/spec/shoes/image_spec.rb +49 -0
  134. data/spec/shoes/images/shoe.jpg +0 -0
  135. data/spec/shoes/input_box_spec.rb +80 -0
  136. data/spec/shoes/integration_spec.rb +20 -0
  137. data/spec/shoes/internal_app_spec.rb +141 -0
  138. data/spec/shoes/keypress_spec.rb +11 -0
  139. data/spec/shoes/keyrelease_spec.rb +12 -0
  140. data/spec/shoes/line_spec.rb +49 -0
  141. data/spec/shoes/link_spec.rb +105 -0
  142. data/spec/shoes/list_box_spec.rb +74 -0
  143. data/spec/shoes/logger/ruby_spec.rb +8 -0
  144. data/spec/shoes/logger_spec.rb +45 -0
  145. data/spec/shoes/oval_spec.rb +24 -0
  146. data/spec/shoes/point_spec.rb +71 -0
  147. data/spec/shoes/progress_spec.rb +54 -0
  148. data/spec/shoes/radio_spec.rb +32 -0
  149. data/spec/shoes/rect_spec.rb +39 -0
  150. data/spec/shoes/renamed_delegate_spec.rb +70 -0
  151. data/spec/shoes/shape_spec.rb +95 -0
  152. data/spec/shoes/shared_examples/button.rb +6 -0
  153. data/spec/shoes/shared_examples/changeable.rb +26 -0
  154. data/spec/shoes/shared_examples/clickable.rb +5 -0
  155. data/spec/shoes/shared_examples/common_methods.rb +35 -0
  156. data/spec/shoes/shared_examples/dimensions.rb +32 -0
  157. data/spec/shoes/shared_examples/dsl.rb +44 -0
  158. data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
  159. data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
  160. data/spec/shoes/shared_examples/dsl/background.rb +26 -0
  161. data/spec/shoes/shared_examples/dsl/border.rb +10 -0
  162. data/spec/shoes/shared_examples/dsl/button.rb +5 -0
  163. data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
  164. data/spec/shoes/shared_examples/dsl/check.rb +11 -0
  165. data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
  166. data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
  167. data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
  168. data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
  169. data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
  170. data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
  171. data/spec/shoes/shared_examples/dsl/image.rb +21 -0
  172. data/spec/shoes/shared_examples/dsl/line.rb +9 -0
  173. data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
  174. data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
  175. data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
  176. data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
  177. data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
  178. data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
  179. data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
  180. data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
  181. data/spec/shoes/shared_examples/dsl/star.rb +48 -0
  182. data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
  183. data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
  184. data/spec/shoes/shared_examples/dsl/style.rb +32 -0
  185. data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
  186. data/spec/shoes/shared_examples/dsl/video.rb +5 -0
  187. data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
  188. data/spec/shoes/shared_examples/hover_leave.rb +11 -0
  189. data/spec/shoes/shared_examples/parent.rb +6 -0
  190. data/spec/shoes/shared_examples/scroll.rb +41 -0
  191. data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
  192. data/spec/shoes/shared_examples/slot.rb +331 -0
  193. data/spec/shoes/shared_examples/state.rb +19 -0
  194. data/spec/shoes/shared_examples/style.rb +82 -0
  195. data/spec/shoes/slot_spec.rb +130 -0
  196. data/spec/shoes/sound_spec.rb +15 -0
  197. data/spec/shoes/span_spec.rb +112 -0
  198. data/spec/shoes/spec_helper.rb +24 -0
  199. data/spec/shoes/stack_spec.rb +79 -0
  200. data/spec/shoes/star_spec.rb +31 -0
  201. data/spec/shoes/text_block_dimensions_spec.rb +75 -0
  202. data/spec/shoes/text_block_spec.rb +270 -0
  203. data/spec/shoes/url_spec.rb +68 -0
  204. data/spec/shoes/widget_spec.rb +70 -0
  205. data/spec/shoes_spec.rb +44 -0
  206. data/spec/spec_helper.rb +18 -0
  207. data/static/Shoes.icns +0 -0
  208. data/static/shoes-icon.png +0 -0
  209. metadata +354 -0
@@ -0,0 +1,51 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Arc do
4
+ include_context "dsl app"
5
+ let(:parent) { app }
6
+
7
+ let(:left) { 13 }
8
+ let(:top) { 44 }
9
+ let(:width) { 200 }
10
+ let(:height) { 300 }
11
+ let(:start_angle) { 0 }
12
+ let(:end_angle) { Shoes::TWO_PI }
13
+
14
+ context "basic" do
15
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle) }
16
+
17
+ it_behaves_like "object with style" do
18
+ let(:subject_without_style) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle) }
19
+ let(:subject_with_style) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle, arg_styles) }
20
+ end
21
+ it_behaves_like "object with dimensions"
22
+ it_behaves_like "left, top as center", :start_angle, :end_angle
23
+ it_behaves_like "object with parent"
24
+
25
+ #it_styles_with :art_styles, :center, :dimensions, :radius
26
+
27
+ it "is a Shoes::Arc" do
28
+ expect(arc.class).to be(Shoes::Arc)
29
+ end
30
+
31
+ its(:angle1) { should eq(0) }
32
+ its(:angle2) { should eq(Shoes::TWO_PI) }
33
+ its(:wedge) { should eq(false) }
34
+ end
35
+
36
+ context "relative dimensions" do
37
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, relative_width, relative_height, start_angle, end_angle) }
38
+ it_behaves_like "object with relative dimensions"
39
+ end
40
+
41
+ context "negative dimensions" do
42
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, -width, -height, 0, Shoes::TWO_PI) }
43
+ it_behaves_like "object with negative dimensions"
44
+ end
45
+
46
+ context "with wedge: true" do
47
+ subject(:arc) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle, wedge: true) }
48
+
49
+ its(:wedge) { should eq(true) }
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Background do
4
+ include_context "dsl app"
5
+
6
+ let(:left) { 10 }
7
+ let(:top) { 20 }
8
+ let(:width) { 100 }
9
+ let(:height) { 200 }
10
+
11
+ let(:blue) { Shoes::COLORS[:blue] }
12
+ let(:input_opts){ {left: left, top: top, width: width, height: height, color: blue} }
13
+ subject(:background) { Shoes::Background.new(app, parent, blue, input_opts) }
14
+
15
+ it "retains app" do
16
+ expect(background.app).to eq(app)
17
+ end
18
+
19
+ it "creates gui object" do
20
+ expect(background.gui).not_to be_nil
21
+ end
22
+
23
+ it_behaves_like "object with style" do
24
+ subject(:background) { Shoes::Background.new(app, parent, Shoes::COLORS[:black]) }
25
+ let(:subject_without_style) { Shoes::Background.new(app, parent, blue) }
26
+ let(:subject_with_style) { Shoes::Background.new(app, parent, blue, arg_styles) }
27
+ end
28
+
29
+ it_behaves_like "object with dimensions"
30
+
31
+ describe "relative dimensions from parent" do
32
+ subject { Shoes::Background.new(app, parent, blue, relative_opts) }
33
+ it_behaves_like "object with relative dimensions"
34
+ end
35
+
36
+ context "negative dimensions" do
37
+ subject { Shoes::Background.new(app, parent, blue, negative_opts) }
38
+ it_behaves_like "object with negative dimensions"
39
+ end
40
+
41
+ describe '#needs_to_be_positioned?' do
42
+ context 'without absolute dimensions' do
43
+ let(:input_opts) {{}}
44
+ it {is_expected.not_to be_needs_to_be_positioned}
45
+ end
46
+
47
+ context 'with absolute dimensions' do
48
+ it {is_expected.to be_needs_to_be_positioned}
49
+ end
50
+ end
51
+
52
+ it {is_expected.not_to be_takes_up_space}
53
+ end
@@ -0,0 +1,47 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ shared_examples_for "basic border" do
4
+ it "retains app" do
5
+ expect(subject.app).to eq(app)
6
+ end
7
+
8
+ it "creates gui object" do
9
+ expect(subject.gui).not_to be_nil
10
+ end
11
+ end
12
+
13
+ describe Shoes::Border do
14
+ include_context "dsl app"
15
+ let(:parent) { Shoes::FakeElement.new nil, left, top, width, height}
16
+ let(:opts){ {left: left, top: top, width: width, height: height} }
17
+
18
+ let(:left) { 10 }
19
+ let(:top) { 20 }
20
+ let(:width) { 100 }
21
+ let(:height) { 200 }
22
+
23
+ let(:blue) { Shoes::COLORS[:blue] }
24
+
25
+ subject { Shoes::Border.new(app, parent, blue, opts) }
26
+
27
+ it_behaves_like "basic border"
28
+ it_behaves_like "object with style" do
29
+ subject { Shoes::Border.new(app, parent, Shoes::COLORS[:black]) }
30
+ let(:subject_without_style) { Shoes::Border.new(app, parent, blue) }
31
+ let(:subject_with_style) { Shoes::Border.new(app, parent, blue, arg_styles) }
32
+ end
33
+ it_behaves_like "object with dimensions"
34
+
35
+ describe "relative dimensions from parent" do
36
+ subject { Shoes::Border.new(app, parent, blue, relative_opts) }
37
+ it_behaves_like "object with relative dimensions"
38
+ end
39
+
40
+ describe "negative dimensions" do
41
+ subject { Shoes::Border.new(app, parent, blue, negative_opts) }
42
+ it_behaves_like "object with negative dimensions"
43
+ end
44
+
45
+ it {is_expected.not_to be_takes_up_space}
46
+ it {is_expected.not_to be_needs_to_be_positioned}
47
+ end
@@ -0,0 +1,110 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::BuiltinMethods do
4
+ let(:input_blk) { Proc.new {} }
5
+ let(:app) { Shoes::App.new({}, &input_blk) }
6
+ let(:logger) { double("logger") }
7
+
8
+ before :each do
9
+ Shoes::LOG.clear
10
+ allow(Shoes).to receive(:logger) { logger }
11
+ end
12
+
13
+ describe 'Shoes.p' do
14
+ it 'adds a debug to the log with an inspected object' do
15
+ Shoes.p 'message'
16
+ expect(Shoes::LOG).to include ['debug', 'message'.inspect]
17
+ end
18
+
19
+ it 'also handles object the way they should be handled' do
20
+ Shoes.p []
21
+ expect(Shoes::LOG).to include ['debug', '[]']
22
+ end
23
+ end
24
+
25
+ describe "info" do
26
+ before :each do
27
+ allow(logger).to receive(:info)
28
+ app.info("test")
29
+ end
30
+
31
+ it "sets Shoes::LOG" do
32
+ expect(Shoes::LOG).to eq([["info", "test"]])
33
+ end
34
+
35
+ it "sends message to logger" do
36
+ expect(logger).to have_received(:info)
37
+ end
38
+ end
39
+
40
+ describe "debug" do
41
+ before :each do
42
+ allow(logger).to receive(:debug)
43
+ app.debug("test")
44
+ end
45
+
46
+ it "sets Shoes::LOG" do
47
+ expect(Shoes::LOG).to eq([["debug", "test"]])
48
+ end
49
+
50
+ it "sends message to logger" do
51
+ expect(logger).to have_received(:debug)
52
+ end
53
+ end
54
+
55
+ describe "warn" do
56
+ before :each do
57
+ allow(logger).to receive(:warn)
58
+ app.warn("test")
59
+ end
60
+
61
+ it "sets Shoes::LOG" do
62
+ expect(Shoes::LOG).to eq([["warn", "test"]])
63
+ end
64
+
65
+ it "sends message to logger" do
66
+ expect(logger).to have_received(:warn)
67
+ end
68
+ end
69
+
70
+ describe "error" do
71
+ before :each do
72
+ allow(logger).to receive(:error)
73
+ app.error("test")
74
+ end
75
+
76
+ it "sets Shoes::LOG" do
77
+ expect(Shoes::LOG).to eq([["error", "test"]])
78
+ end
79
+
80
+ it "sends message to logger" do
81
+ expect(logger).to have_received(:error)
82
+ end
83
+ end
84
+
85
+ # just testing responds to things since the implementation is tested
86
+ # elsewhere
87
+ describe 'are builtin methods are also available from Shoes' do
88
+ builtin_methods = [:alert, :ask, :ask_color, :ask_open_file, :ask_save_file,
89
+ :ask_open_folder, :ask_save_folder, :confirm, :color,
90
+ :debug, :error, :font, :gradient, :gray, :rgb, :info,
91
+ :pattern, :warn]
92
+
93
+ builtin_methods.each do |method|
94
+ it "responds to #{method}" do
95
+ expect(Shoes).to respond_to method
96
+ end
97
+ end
98
+
99
+
100
+ describe 'does not get to the nitty gritty helper_methods' do
101
+ helper_methods = [:image_file?, :image_pattern]
102
+
103
+ helper_methods.each do |method|
104
+ it "does not respond to #{method}" do
105
+ expect(Shoes).not_to respond_to method
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,44 @@
1
+ require "shoes/spec_helper"
2
+
3
+ describe Shoes::Button do
4
+ include_context "dsl app"
5
+ let(:input_opts) { {:left => left, :top => top, :width => width,
6
+ :height => height, :margin => margin, :state => "disabled"} }
7
+
8
+ let(:left) { 13 }
9
+ let(:top) { 44 }
10
+ let(:width) { 131 }
11
+ let(:height) { 137 }
12
+ let(:margin) { 14 }
13
+
14
+ subject(:button) { Shoes::Button.new(app, parent, "text", input_opts, input_block) }
15
+
16
+ it_behaves_like "movable object"
17
+ it_behaves_like "object with state"
18
+ it_behaves_like "object with style" do
19
+ let(:subject_without_style) { Shoes::Button.new(app, parent, "text") }
20
+ let(:subject_with_style) { Shoes::Button.new(app, parent, "text", arg_styles) }
21
+ end
22
+ it_behaves_like "object with dimensions"
23
+
24
+ it { is_expected.to respond_to :click }
25
+ it { is_expected.to respond_to :focus }
26
+
27
+ describe "initialize" do
28
+ its(:parent) { should eq(parent) }
29
+ its(:text) { should eq("text") }
30
+ its(:width) { should eq(131) }
31
+ its(:height) { should eq(137) }
32
+ its(:state) { should eq("disabled") }
33
+ end
34
+
35
+ describe "relative dimensions" do
36
+ subject { Shoes::Button.new(app, parent, "text", relative_opts, input_block) }
37
+ it_behaves_like "object with relative dimensions"
38
+ end
39
+
40
+ describe "negative dimensions" do
41
+ subject { Shoes::Button.new(app, parent, "text", negative_opts, input_block) }
42
+ it_behaves_like "object with negative dimensions"
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Check do
4
+ include_context "dsl app"
5
+
6
+ subject { Shoes::Check.new(app, parent, input_opts, input_block) }
7
+
8
+ it_behaves_like "checkable"
9
+ it_behaves_like "object with state"
10
+ it_behaves_like "object with style" do
11
+ let(:subject_without_style) { Shoes::Check.new(app, parent) }
12
+ let(:subject_with_style) { Shoes::Check.new(app, parent, arg_styles) }
13
+ end
14
+
15
+ describe "dimensions" do
16
+ let(:left) { 10 }
17
+ let(:top) { 20 }
18
+ let(:width) { 100 }
19
+ let(:height) { 200 }
20
+ let(:input_opts){ {left: left, top: top, width: width, height: height} }
21
+ subject { Shoes::Check.new(app, parent, input_opts) }
22
+
23
+ it_behaves_like "object with dimensions"
24
+
25
+ describe "takes relative dimensions from parent" do
26
+ subject { Shoes::Check.new(app, parent, relative_opts) }
27
+ it_behaves_like "object with relative dimensions"
28
+ end
29
+
30
+ describe "negative dimensions" do
31
+ subject { Shoes::Check.new(app, parent, negative_opts) }
32
+ it_behaves_like "object with negative dimensions"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::CLI do
4
+ subject {Shoes::CLI.new}
5
+
6
+ before :each do
7
+ allow(subject).to receive :package
8
+ end
9
+
10
+ it 'does not raise an error for a normal packaging command #624' do
11
+ expect do
12
+ subject.run ['-p', 'swt:app', 'test/simple-sound.rb']
13
+ end.not_to raise_error
14
+ end
15
+ end
@@ -0,0 +1,408 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Color do
4
+ describe ".create" do
5
+ let(:color) { Shoes::Color.new(40, 50, 60) }
6
+
7
+ it "accepts color" do
8
+ expect(Shoes::Color.create(color)).to eq(color)
9
+ end
10
+
11
+ it "accepts string" do
12
+ expect(Shoes::Color.create("28323c")).to eq(color)
13
+ end
14
+ end
15
+
16
+ shared_examples_for "black" do
17
+ its(:class) { should eq(Shoes::Color) }
18
+ its(:red) { should eq(0) }
19
+ its(:green) { should eq(0) }
20
+ its(:blue) { should eq(0) }
21
+ its(:hex) { should eq("#000000") }
22
+ it { is_expected.to be_black }
23
+ it { is_expected.not_to be_white }
24
+ end
25
+
26
+ shared_examples "color with bad arguments" do
27
+ it "raises ArgumentError" do
28
+ expect(subject).to raise_error(ArgumentError)
29
+ end
30
+ end
31
+
32
+ context "with wrong number of arguments" do
33
+ subject { lambda { Shoes::Color.new(10, 10) } }
34
+ it_behaves_like "color with bad arguments"
35
+ end
36
+
37
+ context "with too many hex chars" do
38
+ subject { lambda { Shoes::Color.new("a1b2c3d") } }
39
+ it_behaves_like "color with bad arguments"
40
+ end
41
+
42
+ context "with too few hex chars" do
43
+ subject { lambda { Shoes::Color.new("a1") } }
44
+ it_behaves_like "color with bad arguments"
45
+ end
46
+
47
+ context "with invalid hex chars" do
48
+ subject { lambda { Shoes::Color.new("#g01234") } }
49
+ it_behaves_like "color with bad arguments"
50
+ end
51
+
52
+ context "hex" do
53
+ let(:rgb) { Shoes::Color.new(0, 0, 0, 255) }
54
+
55
+ context "with '#000000'" do
56
+ subject { Shoes::Color.new("#000000") }
57
+ it { is_expected.to eq(rgb) }
58
+ end
59
+
60
+ context "with '000000'" do
61
+ subject { Shoes::Color.new("000000") }
62
+ it { is_expected.to eq(rgb) }
63
+ end
64
+
65
+ context "with '000'" do
66
+ subject { Shoes::Color.new("000") }
67
+ it { is_expected.to eq(rgb) }
68
+ end
69
+
70
+ context "with '#000'" do
71
+ subject { Shoes::Color.new("#000") }
72
+ it { is_expected.to eq(rgb) }
73
+ end
74
+
75
+ context "with '#FFF'" do
76
+ let(:rgb) { Shoes::Color.new(255, 255, 255) }
77
+ subject { Shoes::Color.new("#FFF") }
78
+ it { is_expected.to eq(rgb) }
79
+ end
80
+
81
+ context "with '#fff'" do
82
+ let(:rgb) { Shoes::Color.new(255, 255, 255) }
83
+ subject { Shoes::Color.new("#fff") }
84
+ it { is_expected.to eq(rgb) }
85
+ end
86
+ end
87
+
88
+ context "rgb" do
89
+ context "black" do
90
+ context "with optional alpha" do
91
+ subject { Shoes::Color.new(0, 0, 0, 0) }
92
+ it_behaves_like "black"
93
+ its(:alpha) { should eq(0) }
94
+ end
95
+
96
+ context "without optional alpha" do
97
+ subject { Shoes::Color.new(0, 0, 0) }
98
+ it_behaves_like "black"
99
+ its(:alpha) { should eq(255) }
100
+ end
101
+
102
+ context "using floats" do
103
+ context "with optional alpha" do
104
+ subject { Shoes::Color.new(0.0, 0.0, 0.0, 0.0) }
105
+ it_behaves_like "black"
106
+ its(:alpha) { should eq(0) }
107
+ end
108
+
109
+ context "without optional alpha" do
110
+ subject { Shoes::Color.new(0.0, 0.0, 0.0) }
111
+ it_behaves_like "black"
112
+ its(:alpha) { should eq(255) }
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "inspect" do
118
+ include InspectHelpers
119
+
120
+ # Using patterns here so we can handle the variable hex string identifier
121
+ let(:rgb_pattern) { 'rgb[(]10, 20, 30[)]' }
122
+ let(:inspect_pattern) { "[(]Shoes::Color:#{shoes_object_id_pattern} #{rgb_pattern} alpha:40[)]$" }
123
+ subject(:color) { Shoes::Color.new(10, 20, 30, 40) }
124
+
125
+ its(:to_s) { should match(rgb_pattern) }
126
+ its(:inspect) { should match(inspect_pattern) }
127
+ end
128
+
129
+ context "white" do
130
+ subject { Shoes::Color.new(255, 255, 255) }
131
+ it { is_expected.to be_white }
132
+ it { is_expected.not_to be_black }
133
+ end
134
+
135
+ context "peru" do
136
+ shared_examples_for "peru" do
137
+ its(:class) { should eq(Shoes::Color) }
138
+ its(:red) { should eq(205) }
139
+ its(:green) { should eq(133) }
140
+ its(:blue) { should eq(63) }
141
+ it { is_expected.not_to be_black }
142
+ it { is_expected.not_to be_white }
143
+ end
144
+
145
+ context "with optional alpha" do
146
+ subject { Shoes::Color.new(205, 133, 63, 100) }
147
+ it_behaves_like("peru")
148
+ its(:alpha) { should eq(100) }
149
+ end
150
+
151
+ context "without optional alpha" do
152
+ subject { Shoes::Color.new(205, 133, 63) }
153
+ it_behaves_like("peru")
154
+ its(:alpha) { should eq(255) }
155
+ end
156
+
157
+ context "using floats" do
158
+ let(:red) { 0.805 }
159
+ let(:green) { 0.52 }
160
+ let(:blue) { 0.248 }
161
+ let(:alpha) { 0.392 }
162
+
163
+ context "with optional alpha" do
164
+ subject { Shoes::Color.new(red, green, blue, alpha) }
165
+ it_behaves_like "peru"
166
+ its(:alpha) { should eq(100) }
167
+ end
168
+
169
+ context "without optional alpha" do
170
+ subject { Shoes::Color.new(red, green, blue) }
171
+ it_behaves_like "peru"
172
+ its(:alpha) { should eq(255) }
173
+ end
174
+ end
175
+ end
176
+
177
+ describe "light and dark" do
178
+ let(:lightgreen) { Shoes::Color.new(144, 238, 144) }
179
+ let(:darkgreen) { Shoes::Color.new(0, 100, 0) }
180
+ let(:mediumseagreen) { Shoes::Color.new(60, 179, 113) }
181
+
182
+ specify "light color is light" do
183
+ expect(lightgreen).to be_light
184
+ expect(mediumseagreen).not_to be_light
185
+ expect(darkgreen).not_to be_light
186
+ end
187
+
188
+ specify "dark color is dark" do
189
+ expect(lightgreen).not_to be_dark
190
+ expect(mediumseagreen).not_to be_dark
191
+ expect(darkgreen).to be_dark
192
+ end
193
+ end
194
+
195
+ describe "transparency" do
196
+ let(:transparent) { Shoes::Color.new(25, 25, 112, 0) }
197
+ let(:semi) { Shoes::Color.new(25, 25, 112, 100) }
198
+ let(:opaque) { Shoes::Color.new(25, 25, 25) }
199
+
200
+ specify "only transparent colors are transparent" do
201
+ expect(transparent).to be_transparent
202
+ expect(semi).not_to be_transparent
203
+ expect(opaque).not_to be_transparent
204
+ end
205
+
206
+ specify "only opaque colors should be opaque" do
207
+ expect(transparent).not_to be_opaque
208
+ expect(semi).not_to be_opaque
209
+ expect(opaque).to be_opaque
210
+ end
211
+ end
212
+
213
+ describe "comparable" do
214
+ let(:color_1) { Shoes::Color.new(255, 69, 0) }
215
+ let(:red) {Shoes::Color.new 255, 0, 0}
216
+ let(:green) {Shoes::Color.new 0, 255, 0}
217
+
218
+ it "is equal when values are equal" do
219
+ color_2 = Shoes::Color.new(255, 69, 0)
220
+ expect(color_1).to eq(color_2)
221
+ end
222
+
223
+ it "is less than when darker" do
224
+ color_2 = Shoes::Color.new(255, 70, 0)
225
+ expect(color_1).to be < color_2
226
+ end
227
+
228
+ it "is greater than when lighter" do
229
+ color_2 = Shoes::Color.new(255, 68, 0)
230
+ expect(color_1).to be > color_2
231
+ end
232
+
233
+ it 'does not claim for full red and full green to be equal' do
234
+ expect(red).not_to eq green
235
+ end
236
+
237
+ it 'claims that a color is the same as itself' do
238
+ expect(green).to eq green
239
+ end
240
+
241
+ context "same rgb values" do
242
+ let(:color_2) { Shoes::Color.new(255, 69, 0, 254) }
243
+ it "is less than when less opaque" do
244
+ expect(color_2).to be < color_1
245
+ end
246
+
247
+ it "is greater than when more opaque" do
248
+ expect(color_1).to be > color_2
249
+ end
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "Shoes built-in colors" do
256
+ class MockApp
257
+ include Shoes::DSL
258
+ end
259
+
260
+ subject { MockApp.new }
261
+
262
+ its(:papayawhip) { should eq(Shoes::Color.new(255, 239, 213)) }
263
+ its(:aquamarine) { should eq(Shoes::Color.new(127, 255, 212)) }
264
+ its(:tomato) { should eq(Shoes::Color.new(255, 99, 71)) }
265
+ end
266
+
267
+ describe "Shoes built in gray" do
268
+ let(:app) { Shoes::App.new }
269
+
270
+ it "creates a dsl method for gray" do
271
+ expect(app).to respond_to(:gray)
272
+ end
273
+
274
+ specify "gray with no parameters is [128, 128, 128, OPAQUE]" do
275
+ expect(app.gray).to eq(Shoes::Color.new(128, 128, 128))
276
+ end
277
+
278
+ specify "single parameter specifies the gray level" do
279
+ expect(app.gray(64)).to eq(Shoes::Color.new(64, 64, 64))
280
+ end
281
+
282
+ specify "two parameters specifies the gray level and opacity" do
283
+ expect(app.gray(13, 57)).to eq(Shoes::Color.new(13, 13, 13, 57))
284
+ end
285
+
286
+ specify "float parameters should be normalised" do
287
+ expect(app.gray(1.0, 0.5)).to eq(Shoes::Color.new( 255, 255, 255, 128 ))
288
+ end
289
+
290
+ it 'hangles 0.93 right as well' do
291
+ result_93 = (0.93 * 255).to_i
292
+ expect(app.gray(0.93)).to eq(Shoes::Color.new(result_93, result_93, result_93))
293
+ end
294
+
295
+ it 'also has a grey alias for our BE friends' do
296
+ expect(app).to respond_to :grey
297
+ end
298
+ end
299
+
300
+ # Differences between this implementation and Red Shoes
301
+ describe "differences from Red Shoes" do
302
+ let(:white) { Shoes::Color.new(255, 255, 255) }
303
+ let(:transparent_black) { Shoes::Color.new(0, 0, 0, 0) }
304
+
305
+ context "integers" do
306
+ specify "too-large values become 255" do
307
+ expect(Shoes::Color.new(256, 256, 256, 256)).to eq(white)
308
+ end
309
+
310
+ specify "too-small values become 0" do
311
+ expect(Shoes::Color.new(-1, -1, -1, -1)).to eq(transparent_black)
312
+ end
313
+ end
314
+
315
+ context "floats" do
316
+ specify "too-large values become 255" do
317
+ expect(Shoes::Color.new(1.1, 1.1, 1.1, 1.1)).to eq(white)
318
+ end
319
+
320
+ specify "too-small values become 0" do
321
+ expect(Shoes::Color.new(-0.1, -0.1, -0.1, -0.1)).to eq(transparent_black)
322
+ end
323
+ end
324
+
325
+ # These specifications describe how this implementation differs from Red Shoes.
326
+ # These are examples of what Red Shoes _does_ do, and what this implementation
327
+ # _does not_ do.
328
+ describe "unusual input" do
329
+ let(:baseline) { Shoes::Color.new(50, 0, 200) }
330
+
331
+ describe "too-large values" do
332
+ specify "red does not get modulo-256'd into bounds" do
333
+ expect(Shoes::Color.new(306, 0, 200)).not_to eq(baseline)
334
+ expect(Shoes::Color.new(1.197, 0, 200)).not_to eq(baseline)
335
+ end
336
+
337
+ specify "green does not get modulo-256'd into bounds" do
338
+ expect(Shoes::Color.new(50, 256, 200)).not_to eq(baseline)
339
+ expect(Shoes::Color.new(50, 2.005, 200)).not_to eq(baseline)
340
+ end
341
+
342
+ specify "blue does not get modulo-256'd into bounds" do
343
+ expect(Shoes::Color.new(50, 0, 456)).not_to eq(baseline)
344
+ expect(Shoes::Color.new(50, 0, 2.7913137254902)).not_to eq(baseline)
345
+ end
346
+ end
347
+
348
+ describe "negative values" do
349
+ specify "-1 does not become 255" do
350
+ expect(Shoes::Color.new(-1, -1, -1, -1)).not_to eq(Shoes::Color.new(255, 255, 255))
351
+ end
352
+
353
+ specify "256 and neighbors" do
354
+ expect(Shoes::Color.new(-256, -255, -257)).not_to eq(Shoes::Color.new(0, 1, 255))
355
+ end
356
+
357
+ specify "float behaviour" do
358
+ expect(Shoes::Color.new(-1.0, -0.5, -0.0)).not_to eq(Shoes::Color.new(0, 128, 1))
359
+ end
360
+ end
361
+
362
+ describe "edge cases" do
363
+ specify "0.0 does not become 1" do
364
+ expect(Shoes::Color.new(0.0, 0.0, 0.0)).not_to eq(Shoes::Color.new(1, 1, 1))
365
+ end
366
+
367
+ specify "1.0 does not become 0" do
368
+ expect(Shoes::Color.new(1.0, 1.0, 1.0)).not_to eq(Shoes::Color.new(0, 0, 0))
369
+ end
370
+ end
371
+ end
372
+ end
373
+
374
+ describe Shoes::Color::DSLHelpers do
375
+ class ColorDSLHelperTest
376
+ include Shoes::Color::DSLHelpers
377
+ end
378
+
379
+ subject {ColorDSLHelperTest.new}
380
+
381
+ describe '#pattern' do
382
+ it 'creates an image pattern when fed a string for which a file exists' do
383
+ allow(File).to receive_messages(exist?: true)
384
+ my_path = '/some/path/to/image.png'
385
+ image_pattern = subject.pattern(my_path)
386
+ expect(image_pattern.path).to eq my_path
387
+ end
388
+
389
+ it 'raises an argument error for bad input like a single number' do
390
+ expect {subject.pattern(1)}.to raise_error(ArgumentError)
391
+ end
392
+
393
+ it 'creates a gradient given 2 arguments' do
394
+ expect(subject).to receive(:gradient)
395
+ subject.pattern([10, 10, 10], [30, 30, 30])
396
+ end
397
+ end
398
+
399
+ describe '#gradient' do
400
+ it 'raises an argument error for no arguments supplied' do
401
+ expect{subject.gradient}.to raise_error ArgumentError
402
+ end
403
+
404
+ it 'raises an argument error for too many (> 2) args supplied' do
405
+ expect{subject.gradient 1, 2, 3}.to raise_error ArgumentError
406
+ end
407
+ end
408
+ end