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,74 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::ListBox do
4
+ include_context "dsl app"
5
+ let(:input_opts) { { items: items, left: left, top: top, width: width,
6
+ height: height } }
7
+
8
+ let(:items) {["Wine", "Vodka", "Water"]}
9
+
10
+ let(:left) { 10 }
11
+ let(:top) { 20 }
12
+ let(:width) { 100 }
13
+ let(:height) { 200 }
14
+
15
+ subject(:list_box) { Shoes::ListBox.new(app, parent, input_opts, input_block) }
16
+
17
+ it_behaves_like "an element that can respond to change"
18
+ it_behaves_like "object with style" do
19
+ let(:subject_without_style) { Shoes::ListBox.new(app, parent) }
20
+ let(:subject_with_style) { Shoes::ListBox.new(app, parent, arg_styles) }
21
+ end
22
+ it_behaves_like "object with state"
23
+ it_behaves_like "object with dimensions"
24
+
25
+ describe "relative dimensions from parent" do
26
+ subject { Shoes::ListBox.new(app, parent, relative_opts, input_block) }
27
+ it_behaves_like "object with relative dimensions"
28
+ end
29
+
30
+ describe "negative dimensions" do
31
+ subject { Shoes::ListBox.new(app, parent, negative_opts, input_block) }
32
+ it_behaves_like "object with negative dimensions"
33
+ end
34
+
35
+ it "contains the correct items" do
36
+ expect(subject.items).to eq(["Wine", "Vodka", "Water"])
37
+ end
38
+
39
+ it "changes the items" do
40
+ list_box.items = ["Pie", "Apple", "Pig"]
41
+ expect(list_box.items).to eq(["Pie", "Apple", "Pig"])
42
+ end
43
+
44
+ describe 'Choosing' do
45
+ it "allows us to choose an option" do
46
+ expect(list_box).to respond_to(:choose)
47
+ end
48
+
49
+ def expect_gui_choose_with(string)
50
+ expect_any_instance_of(Shoes.configuration.backend::ListBox).
51
+ to receive(:choose).with string
52
+ end
53
+
54
+ it "should call @gui.choose when we choose something" do
55
+ expect_gui_choose_with "Wine"
56
+ list_box.choose "Wine"
57
+ end
58
+
59
+ it 'should call @gui.choose when the choose option is passed' do
60
+ expect_gui_choose_with 'Wine'
61
+ Shoes::ListBox.new app, parent, input_opts.merge(choose: 'Wine')
62
+ end
63
+ end
64
+
65
+ it "should delegate #text to the backend" do
66
+ expect_any_instance_of(Shoes.configuration.backend::ListBox).
67
+ to receive(:text).and_return("Sneakers & Sandals")
68
+ expect(list_box.text).to eq("Sneakers & Sandals")
69
+ end
70
+
71
+ it 'has the initialized text elements' do
72
+ expect(subject.items).to eq items
73
+ end
74
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::Logger::Ruby do
4
+ it "delegates to a Logger instance" do
5
+ expect_any_instance_of(::Logger).to receive(:debug).with("Foo bar baz!")
6
+ subject.debug("Foo bar baz!")
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shoes::Logger do
4
+ let(:awesome_logger) { Class.new }
5
+ after { Shoes::Logger.unregister(:awesome_logger) }
6
+
7
+ describe ".register" do
8
+ it "allows new loggers to be registered" do
9
+ Shoes::Logger.register(:awesome_logger, awesome_logger)
10
+ end
11
+ end
12
+
13
+ describe ".get" do
14
+ before { Shoes::Logger.register(:awesome_logger, awesome_logger) }
15
+
16
+ it "retrieves a registered logger" do
17
+ expect(Shoes::Logger.get(:awesome_logger)).to equal(awesome_logger)
18
+ end
19
+ end
20
+
21
+ describe "default logger" do
22
+ let(:logger) { Shoes.logger }
23
+
24
+ it "is a ruby logger" do
25
+ expect(logger).to be_an_instance_of(Shoes::Logger::Ruby)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe Shoes::Logger::Ruby do
31
+ let(:logdevice) { StringIO.new }
32
+ subject(:logger) { Shoes::Logger::Ruby.new logdevice }
33
+
34
+ it "logs messages with format 'LEVEL: Message'" do
35
+ logger.info "Message"
36
+ expect(logdevice.string).to eq("INFO: Message\n")
37
+ end
38
+
39
+ it "defaults to STDERR" do
40
+ allow(STDERR).to receive(:write)
41
+ logger = Shoes::Logger::Ruby.new
42
+ logger.error "Message"
43
+ expect(STDERR).to have_received(:write)
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Oval do
4
+ include_context "dsl app"
5
+
6
+ let(:left) { 20 }
7
+ let(:top) { 30 }
8
+ let(:width) { 100 }
9
+ let(:height) { 200 }
10
+
11
+ describe "basic" do
12
+ subject { Shoes::Oval.new(app, parent, left, top, width, height) }
13
+ it_behaves_like "object with style" do
14
+ let(:subject_without_style) { Shoes::Oval.new(app, parent, left, top, width, height) }
15
+ let(:subject_with_style) { Shoes::Oval.new(app, parent, left, top, width, height, arg_styles) }
16
+ end
17
+ it_behaves_like "object with dimensions"
18
+ it_behaves_like "movable object"
19
+ it_behaves_like "left, top as center"
20
+ it_behaves_like "object with parent"
21
+
22
+ #it_styles_with :art_styles, :center, :dimensions, :radius
23
+ end
24
+ end
@@ -0,0 +1,71 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Point do
4
+ subject { Shoes::Point.new(40, 50) }
5
+ let(:other_point) { Shoes::Point.new(10, 60) }
6
+
7
+ its(:x) { should eq(40) }
8
+ its(:y) { should eq(50) }
9
+
10
+ it "#left works on either point" do
11
+ expect(subject.left(other_point)).to eq(10)
12
+ expect(other_point.left(subject)).to eq(10)
13
+ end
14
+
15
+ it "#top works on either point" do
16
+ expect(subject.top(other_point)).to eq(50)
17
+ expect(other_point.top(subject)).to eq(50)
18
+ end
19
+
20
+ describe "equality" do
21
+ it "requires x and y to be equal" do
22
+ expect(subject).to eq(Shoes::Point.new 40, 50)
23
+ expect(subject).not_to eq(Shoes::Point.new 41, 50)
24
+ expect(subject).not_to eq(Shoes::Point.new 40, 51)
25
+ end
26
+
27
+ it "works with other (x,y) objects" do
28
+ expect(subject).to eq(Struct.new(:x, :y).new(40, 50))
29
+ end
30
+ end
31
+
32
+ describe "#to" do
33
+ it "positive" do
34
+ expect(subject.to(24, 166)).to eq(Shoes::Point.new(64, 216))
35
+ end
36
+
37
+ it "negative" do
38
+ expect(subject.to(-24, -166)).to eq(Shoes::Point.new(16, -116))
39
+ end
40
+ end
41
+
42
+ it "calculates width of rectangle created with other point" do
43
+ expect(subject.width(other_point)).to eq(30)
44
+ expect(other_point.width(subject)).to eq(30)
45
+ end
46
+
47
+ it "calculates height of rectangle created with other point" do
48
+ expect(subject.height(other_point)).to eq(10)
49
+ expect(other_point.height(subject)).to eq(10)
50
+ end
51
+
52
+ describe "converting to string" do
53
+ include InspectHelpers
54
+
55
+ it "looks like (x,y)" do
56
+ expect(subject.to_s).to eq("(40,50)")
57
+ end
58
+
59
+ it "inspects like (Shoes::Point:0x01234567 (x,y))" do
60
+ expect(subject.inspect).to match(/[(]Shoes::Point:#{shoes_object_id_pattern} [(]40,50[)][)]/)
61
+ end
62
+
63
+ describe "with nil values" do
64
+ subject { Shoes::Point.new(nil, nil) }
65
+
66
+ it "looks like (nil,nil)" do
67
+ expect(subject.to_s).to eq("(_,_)")
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,54 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Progress do
4
+ include_context "dsl app"
5
+ let(:input_opts) { { left: left, top: top, width: width, height: height } }
6
+
7
+ let(:left) { 10 }
8
+ let(:top) { 20 }
9
+ let(:width) { 100 }
10
+ let(:height) { 200 }
11
+
12
+ subject(:progress) { Shoes::Progress.new(app, parent, input_opts, input_block) }
13
+
14
+ it { is_expected.to respond_to :fraction }
15
+ it { is_expected.to respond_to :fraction= }
16
+
17
+ it_behaves_like "object with dimensions"
18
+
19
+ it_behaves_like "object with style" do
20
+ let(:subject_without_style) { Shoes::Progress.new(app, parent) }
21
+ let(:subject_with_style) { Shoes::Progress.new(app, parent, arg_styles) }
22
+ end
23
+
24
+ context "initialize" do
25
+ let(:input_opts) { { fraction: 50 } }
26
+
27
+ it "sets fraction" do
28
+ expect_any_instance_of(Shoes.configuration.backend::Progress).to receive(:fraction=).with(50)
29
+ expect(progress).not_to be_nil
30
+ end
31
+ end
32
+
33
+ context "setting fraction" do
34
+ it "sets on gui" do
35
+ expect(progress.gui).to receive(:fraction=).with(0.5)
36
+ progress.fraction = 0.5
37
+ end
38
+
39
+ it "sets on self" do
40
+ progress.fraction = 0.5
41
+ expect(progress.fraction).to eq(0.5)
42
+ end
43
+ end
44
+
45
+ describe "relative dimensions from parent" do
46
+ subject { Shoes::Progress.new(app, parent, relative_opts, input_block) }
47
+ it_behaves_like "object with relative dimensions"
48
+ end
49
+
50
+ describe "negative dimensions" do
51
+ subject { Shoes::Progress.new(app, parent, negative_opts, input_block) }
52
+ it_behaves_like "object with negative dimensions"
53
+ end
54
+ end
@@ -0,0 +1,32 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Radio do
4
+ include_context "dsl app"
5
+
6
+ subject(:radio) { Shoes::Radio.new(app, parent, group, input_opts, input_block) }
7
+ let(:group) { :a_group }
8
+
9
+ it_behaves_like "checkable"
10
+ it_behaves_like "object with state"
11
+
12
+ it_behaves_like "object with style" do
13
+ let(:subject_without_style) { Shoes::Radio.new(app, parent, group) }
14
+ let(:subject_with_style) { Shoes::Radio.new(app, parent, group, arg_styles) }
15
+ end
16
+
17
+ # only one radio in a group can be checked
18
+
19
+ describe "#initialize" do
20
+ it "sets accessors" do
21
+ expect(radio.parent).to eq(parent)
22
+ expect(radio.group).to eq(group)
23
+ end
24
+ end
25
+
26
+ describe "#group=" do
27
+ it "changes the group" do
28
+ radio.group = "New Group"
29
+ expect(radio.group).to eq("New Group")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ shared_examples_for "basic rect" do
4
+ it "retains app" do
5
+ expect(rect.app).to eq(app)
6
+ end
7
+
8
+ it "creates gui object" do
9
+ expect(rect.gui).not_to be_nil
10
+ end
11
+ end
12
+
13
+ describe Shoes::Rect do
14
+ include_context "dsl app"
15
+
16
+ let(:parent) { app }
17
+ let(:left) { 44 }
18
+ let(:top) { 66 }
19
+ let(:width) { 111 }
20
+ let(:height) { 333 }
21
+ subject(:rect) { Shoes::Rect.new(app, parent, left, top, width, height) }
22
+
23
+ describe '#style' do
24
+ it 'restyles handed in fill colors (even the weird ones)' do
25
+ subject.style fill: 'fff'
26
+ expect(subject.style[:fill]).to eq Shoes::Color.new 255, 255, 255
27
+ end
28
+ end
29
+
30
+ it_behaves_like "basic rect"
31
+ it_behaves_like "object with style" do
32
+ let(:subject_without_style) { Shoes::Rect.new(app, parent, left, top, width, height) }
33
+ let(:subject_with_style) { Shoes::Rect.new(app, parent, left, top, width, height, arg_styles) }
34
+ end
35
+ it_behaves_like "object with dimensions"
36
+ it_behaves_like "movable object"
37
+ it_behaves_like "left, top as center"
38
+ it_behaves_like 'object with parent'
39
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe RenamedDelegate do
4
+
5
+ class ToDelegate
6
+ def method_key
7
+ end
8
+
9
+ def abcd
10
+ end
11
+
12
+ def key
13
+ end
14
+
15
+ def bla_key
16
+ end
17
+
18
+ def method_something
19
+ end
20
+
21
+ def key_something
22
+ end
23
+ end
24
+
25
+ class TestClass
26
+ extend RenamedDelegate
27
+
28
+ attr_reader :delegate
29
+
30
+ def initialize(delegate)
31
+ @delegate = delegate
32
+ end
33
+ end
34
+
35
+ TestClass.renamed_delegate_to :delegate,
36
+ ToDelegate.public_instance_methods(false),
37
+ {'key' => 'shoes', 'something' => 'awesome'}
38
+
39
+ let(:delegate) {double('delegate').as_null_object}
40
+ subject {TestClass.new delegate}
41
+
42
+ def test_renaming(new_name, old_name)
43
+ subject.public_send new_name
44
+ expect(delegate).to have_received old_name
45
+ end
46
+
47
+ it 'delegates method_shoes to method_key' do
48
+ test_renaming :method_shoes, :method_key
49
+ end
50
+
51
+ it 'delegates shoes to key' do
52
+ test_renaming :shoes, :key
53
+ end
54
+
55
+ it 'delegates bla_shoes to bla_key' do
56
+ test_renaming :bla_shoes, :bla_key
57
+ end
58
+
59
+ it 'delegates method_awesome to method_something' do
60
+ test_renaming :method_awesome, :method_something
61
+ end
62
+
63
+ it 'also applies multiple renamings' do
64
+ test_renaming :shoes_awesome, :key_something
65
+ end
66
+
67
+ it 'does not define a method for methods without renamings' do
68
+ expect(subject).not_to respond_to :abcd
69
+ end
70
+ end
@@ -0,0 +1,95 @@
1
+ require 'shoes/spec_helper'
2
+
3
+ describe Shoes::Shape do
4
+ include_context "dsl app"
5
+
6
+ let(:style) { Hash.new }
7
+ let(:draw) { Proc.new { } }
8
+
9
+ subject { Shoes::Shape.new app, parent, style, draw }
10
+
11
+ it_behaves_like "object with style" do
12
+ let(:subject_without_style) { Shoes::Shape.new(app, parent) }
13
+ let(:subject_with_style) { Shoes::Shape.new(app, parent, arg_styles) }
14
+ end
15
+
16
+ it_behaves_like "movable object"
17
+
18
+ describe "octagon" do
19
+ let(:draw) {
20
+ Proc.new {
21
+ xs = [200, 300, 370, 370, 300, 200, 130, 130]
22
+ ys = [100, 100, 170, 270, 340, 340, 270, 170]
23
+ move_to xs.first, ys.first
24
+ xs.zip(ys).each do |x, y|
25
+ line_to(x, y)
26
+ end
27
+ line_to xs.first, ys.first
28
+ }
29
+ }
30
+
31
+ its(:left) { should be_nil }
32
+ its(:top) { should be_nil }
33
+ its(:left_bound) { should eq(130) }
34
+ its(:top_bound) { should eq(100) }
35
+ its(:right_bound) { should eq(370) }
36
+ its(:bottom_bound) { should eq(340) }
37
+ its(:width) { should eq(app.width) }
38
+ its(:height) { should eq app.height }
39
+
40
+ it_behaves_like "movable object"
41
+
42
+ describe "when created with left and top values" do
43
+ let(:style) { {left: 10, top: 100} }
44
+
45
+ its(:left) { should eq(10) }
46
+ its(:top) { should eq(100) }
47
+ its(:left_bound) { should eq(130) }
48
+ its(:top_bound) { should eq(100) }
49
+ its(:right_bound) { should eq(370) }
50
+ its(:bottom_bound) { should eq(340) }
51
+ its(:width) { should eq(app.width) }
52
+ its(:height) { should eq app.height }
53
+ end
54
+ end
55
+
56
+ describe "curve" do
57
+ let(:draw) {
58
+ Proc.new {
59
+ move_to 10, 10
60
+ curve_to 20, 30, 100, 200, 50, 50
61
+ }
62
+ }
63
+
64
+ its(:left_bound) { should eq(10) }
65
+ its(:top_bound) { should eq(10) }
66
+ its(:right_bound) { should eq(100) }
67
+ its(:bottom_bound) { should eq(200) }
68
+ its(:width) { should eq(app.width) }
69
+ its(:height) { should eq app.height }
70
+
71
+ it_behaves_like "movable object"
72
+ end
73
+
74
+ describe "arc" do
75
+ let(:draw) {
76
+ Proc.new {
77
+ arc 10, 10, 100, 100, Shoes::PI, Shoes::TWO_PI
78
+ }
79
+ }
80
+
81
+ it_behaves_like "movable object"
82
+ end
83
+
84
+ describe "accesses app" do
85
+ let(:draw) {
86
+ Proc.new {
87
+ background Shoes::COLORS[:red]
88
+ stroke Shoes::COLORS[:blue]
89
+ rect 10, 10, 100, 100
90
+ }
91
+ }
92
+
93
+ it_behaves_like "movable object"
94
+ end
95
+ end