shoes-core 4.0.0.pre7 → 4.0.0.pre8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shoes/arc.rb +10 -13
  3. data/lib/shoes/arrow.rb +1 -11
  4. data/lib/shoes/background.rb +0 -3
  5. data/lib/shoes/border.rb +0 -3
  6. data/lib/shoes/button.rb +4 -1
  7. data/lib/shoes/check_button.rb +0 -1
  8. data/lib/shoes/common/art_element.rb +21 -0
  9. data/lib/shoes/common/background_element.rb +10 -0
  10. data/lib/shoes/common/clickable.rb +2 -0
  11. data/lib/shoes/common/rotate.rb +1 -2
  12. data/lib/shoes/common/ui_element.rb +10 -1
  13. data/lib/shoes/core/version.rb +1 -1
  14. data/lib/shoes/download.rb +47 -29
  15. data/lib/shoes/dsl.rb +99 -40
  16. data/lib/shoes/font.rb +0 -4
  17. data/lib/shoes/http_request.rb +91 -0
  18. data/lib/shoes/image.rb +0 -1
  19. data/lib/shoes/input_box.rb +0 -1
  20. data/lib/shoes/internal_app.rb +1 -1
  21. data/lib/shoes/line.rb +25 -11
  22. data/lib/shoes/link.rb +10 -4
  23. data/lib/shoes/list_box.rb +0 -1
  24. data/lib/shoes/mock/app.rb +6 -0
  25. data/lib/shoes/mock/clickable.rb +3 -0
  26. data/lib/shoes/mock/font.rb +0 -4
  27. data/lib/shoes/oval.rb +3 -13
  28. data/lib/shoes/progress.rb +0 -1
  29. data/lib/shoes/rect.rb +1 -11
  30. data/lib/shoes/shape.rb +16 -8
  31. data/lib/shoes/slot.rb +2 -1
  32. data/lib/shoes/star.rb +8 -11
  33. data/lib/shoes/text_block.rb +0 -1
  34. data/lib/shoes/ui/picker.rb +29 -8
  35. data/lib/shoes/version.rb +1 -1
  36. metadata +8 -231
  37. data/Guardfile +0 -5
  38. data/Rakefile +0 -1
  39. data/bin/shoes-stub +0 -62
  40. data/ext/install/Rakefile +0 -39
  41. data/ext/install/shoes.bat +0 -17
  42. data/lib/rubygems_plugin.rb +0 -24
  43. data/shoes-core.gemspec +0 -22
  44. data/spec/shoes/animation_spec.rb +0 -71
  45. data/spec/shoes/app_spec.rb +0 -454
  46. data/spec/shoes/arc_spec.rb +0 -52
  47. data/spec/shoes/arrow_spec.rb +0 -28
  48. data/spec/shoes/background_spec.rb +0 -47
  49. data/spec/shoes/border_spec.rb +0 -46
  50. data/spec/shoes/builtin_methods_spec.rb +0 -122
  51. data/spec/shoes/button_spec.rb +0 -55
  52. data/spec/shoes/check_spec.rb +0 -36
  53. data/spec/shoes/color_spec.rb +0 -429
  54. data/spec/shoes/common/attachable_spec.rb +0 -32
  55. data/spec/shoes/common/inspect_spec.rb +0 -26
  56. data/spec/shoes/common/remove_spec.rb +0 -37
  57. data/spec/shoes/common/rotate_spec.rb +0 -13
  58. data/spec/shoes/common/style_normalizer_spec.rb +0 -28
  59. data/spec/shoes/common/style_spec.rb +0 -197
  60. data/spec/shoes/common/translate_spec.rb +0 -27
  61. data/spec/shoes/configuration_spec.rb +0 -51
  62. data/spec/shoes/constants_spec.rb +0 -39
  63. data/spec/shoes/dialog_spec.rb +0 -169
  64. data/spec/shoes/dimension_spec.rb +0 -451
  65. data/spec/shoes/dimensions_spec.rb +0 -868
  66. data/spec/shoes/download_spec.rb +0 -198
  67. data/spec/shoes/flow_spec.rb +0 -132
  68. data/spec/shoes/font_spec.rb +0 -36
  69. data/spec/shoes/framework_learning_spec.rb +0 -31
  70. data/spec/shoes/gradient_spec.rb +0 -31
  71. data/spec/shoes/helpers/fake_absolute_element.rb +0 -31
  72. data/spec/shoes/helpers/fake_element.rb +0 -25
  73. data/spec/shoes/helpers/inspect_helpers.rb +0 -5
  74. data/spec/shoes/helpers/sample17_helper.rb +0 -65
  75. data/spec/shoes/image_spec.rb +0 -69
  76. data/spec/shoes/images/shoe.jpg +0 -0
  77. data/spec/shoes/input_box_spec.rb +0 -80
  78. data/spec/shoes/integration_spec.rb +0 -19
  79. data/spec/shoes/internal_app_spec.rb +0 -148
  80. data/spec/shoes/keypress_spec.rb +0 -11
  81. data/spec/shoes/keyrelease_spec.rb +0 -11
  82. data/spec/shoes/line_spec.rb +0 -120
  83. data/spec/shoes/link_spec.rb +0 -149
  84. data/spec/shoes/list_box_spec.rb +0 -87
  85. data/spec/shoes/logger/ruby_spec.rb +0 -8
  86. data/spec/shoes/logger_spec.rb +0 -45
  87. data/spec/shoes/oval_spec.rb +0 -25
  88. data/spec/shoes/packager_spec.rb +0 -25
  89. data/spec/shoes/point_spec.rb +0 -99
  90. data/spec/shoes/progress_spec.rb +0 -54
  91. data/spec/shoes/radio_spec.rb +0 -32
  92. data/spec/shoes/rect_spec.rb +0 -40
  93. data/spec/shoes/renamed_delegate_spec.rb +0 -69
  94. data/spec/shoes/shape_spec.rb +0 -119
  95. data/spec/shoes/shared_examples/button.rb +0 -6
  96. data/spec/shoes/shared_examples/changeable.rb +0 -26
  97. data/spec/shoes/shared_examples/clickable.rb +0 -5
  98. data/spec/shoes/shared_examples/common_methods.rb +0 -35
  99. data/spec/shoes/shared_examples/dimensions.rb +0 -32
  100. data/spec/shoes/shared_examples/dsl.rb +0 -44
  101. data/spec/shoes/shared_examples/dsl/animate.rb +0 -29
  102. data/spec/shoes/shared_examples/dsl/arc.rb +0 -45
  103. data/spec/shoes/shared_examples/dsl/background.rb +0 -26
  104. data/spec/shoes/shared_examples/dsl/border.rb +0 -10
  105. data/spec/shoes/shared_examples/dsl/button.rb +0 -5
  106. data/spec/shoes/shared_examples/dsl/cap.rb +0 -6
  107. data/spec/shoes/shared_examples/dsl/check.rb +0 -11
  108. data/spec/shoes/shared_examples/dsl/edit_box.rb +0 -8
  109. data/spec/shoes/shared_examples/dsl/edit_line.rb +0 -8
  110. data/spec/shoes/shared_examples/dsl/editable_element.rb +0 -29
  111. data/spec/shoes/shared_examples/dsl/fill.rb +0 -27
  112. data/spec/shoes/shared_examples/dsl/flow.rb +0 -15
  113. data/spec/shoes/shared_examples/dsl/gradient.rb +0 -62
  114. data/spec/shoes/shared_examples/dsl/image.rb +0 -21
  115. data/spec/shoes/shared_examples/dsl/line.rb +0 -9
  116. data/spec/shoes/shared_examples/dsl/nofill.rb +0 -6
  117. data/spec/shoes/shared_examples/dsl/nostroke.rb +0 -6
  118. data/spec/shoes/shared_examples/dsl/oval.rb +0 -88
  119. data/spec/shoes/shared_examples/dsl/pattern.rb +0 -34
  120. data/spec/shoes/shared_examples/dsl/progress.rb +0 -7
  121. data/spec/shoes/shared_examples/dsl/rect.rb +0 -92
  122. data/spec/shoes/shared_examples/dsl/rgb.rb +0 -28
  123. data/spec/shoes/shared_examples/dsl/shape.rb +0 -61
  124. data/spec/shoes/shared_examples/dsl/star.rb +0 -110
  125. data/spec/shoes/shared_examples/dsl/stroke.rb +0 -30
  126. data/spec/shoes/shared_examples/dsl/strokewidth.rb +0 -19
  127. data/spec/shoes/shared_examples/dsl/style.rb +0 -32
  128. data/spec/shoes/shared_examples/dsl/text_elements.rb +0 -84
  129. data/spec/shoes/shared_examples/dsl/video.rb +0 -5
  130. data/spec/shoes/shared_examples/dsl_app_context.rb +0 -11
  131. data/spec/shoes/shared_examples/hover.rb +0 -78
  132. data/spec/shoes/shared_examples/parent.rb +0 -6
  133. data/spec/shoes/shared_examples/scroll.rb +0 -41
  134. data/spec/shoes/shared_examples/shared_element_method.rb +0 -60
  135. data/spec/shoes/shared_examples/slot.rb +0 -441
  136. data/spec/shoes/shared_examples/state.rb +0 -26
  137. data/spec/shoes/shared_examples/style.rb +0 -77
  138. data/spec/shoes/slot_spec.rb +0 -176
  139. data/spec/shoes/sound_spec.rb +0 -16
  140. data/spec/shoes/span_spec.rb +0 -112
  141. data/spec/shoes/spec_helper.rb +0 -24
  142. data/spec/shoes/stack_spec.rb +0 -79
  143. data/spec/shoes/star_spec.rb +0 -49
  144. data/spec/shoes/text_block_dimensions_spec.rb +0 -77
  145. data/spec/shoes/text_block_spec.rb +0 -314
  146. data/spec/shoes/text_spec.rb +0 -22
  147. data/spec/shoes/ui/picker_spec.rb +0 -69
  148. data/spec/shoes/url_spec.rb +0 -67
  149. data/spec/shoes/widget_spec.rb +0 -78
  150. data/spec/shoes_spec.rb +0 -41
  151. data/spec/spec_helper.rb +0 -27
@@ -1,52 +0,0 @@
1
- require '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
- it_behaves_like "object with hover"
25
-
26
- # it_styles_with :art_styles, :center, :dimensions, :radius
27
-
28
- it "is a Shoes::Arc" do
29
- expect(arc.class).to be(Shoes::Arc)
30
- end
31
-
32
- its(:angle1) { should eq(0) }
33
- its(:angle2) { should eq(Shoes::TWO_PI) }
34
- its(:wedge) { should eq(false) }
35
- end
36
-
37
- context "relative dimensions" do
38
- subject(:arc) { Shoes::Arc.new(app, parent, left, top, relative_width, relative_height, start_angle, end_angle) }
39
- it_behaves_like "object with relative dimensions"
40
- end
41
-
42
- context "negative dimensions" do
43
- subject(:arc) { Shoes::Arc.new(app, parent, left, top, -width, -height, 0, Shoes::TWO_PI) }
44
- it_behaves_like "object with negative dimensions"
45
- end
46
-
47
- context "with wedge: true" do
48
- subject(:arc) { Shoes::Arc.new(app, parent, left, top, width, height, start_angle, end_angle, wedge: true) }
49
-
50
- its(:wedge) { should eq(true) }
51
- end
52
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Arrow do
4
- include_context "dsl app"
5
-
6
- let(:parent) { app }
7
- let(:left) { 44 }
8
- let(:top) { 66 }
9
- let(:width) { 111 }
10
- let(:height) { 111 }
11
- subject(:arrow) { Shoes::Arrow.new(app, parent, left, top, width) }
12
-
13
- describe '#style' do
14
- it 'restyles handed in fill colors (even the weird ones)' do
15
- subject.style fill: 'fff'
16
- expect(subject.style[:fill]).to eq Shoes::Color.new 255, 255, 255
17
- end
18
- end
19
-
20
- it_behaves_like "object with style" do
21
- let(:subject_without_style) { Shoes::Arrow.new(app, parent, left, top, width) }
22
- let(:subject_with_style) { Shoes::Arrow.new(app, parent, left, top, width, arg_styles) }
23
- end
24
- it_behaves_like "object with dimensions"
25
- it_behaves_like "movable object"
26
- it_behaves_like 'object with parent'
27
- it_behaves_like "object with hover"
28
- end
@@ -1,47 +0,0 @@
1
- require '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
- before do
16
- parent.height = height + 2
17
- parent.width = width + 2
18
- end
19
-
20
- it "retains app" do
21
- expect(background.app).to eq(app)
22
- end
23
-
24
- it "creates gui object" do
25
- expect(background.gui).not_to be_nil
26
- end
27
-
28
- it_behaves_like "object with style" do
29
- subject(:background) { Shoes::Background.new(app, parent, Shoes::COLORS[:black]) }
30
- let(:subject_without_style) { Shoes::Background.new(app, parent, blue) }
31
- let(:subject_with_style) { Shoes::Background.new(app, parent, blue, arg_styles) }
32
- end
33
-
34
- it_behaves_like "object with dimensions"
35
-
36
- describe "relative dimensions from parent" do
37
- subject { Shoes::Background.new(app, parent, blue, relative_opts) }
38
- it_behaves_like "object with relative dimensions"
39
- end
40
-
41
- context "negative dimensions" do
42
- subject { Shoes::Background.new(app, parent, blue, negative_opts) }
43
- it_behaves_like "object with negative dimensions"
44
- end
45
-
46
- it { is_expected.not_to be_takes_up_space }
47
- end
@@ -1,46 +0,0 @@
1
- require '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
- end
@@ -1,122 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::BuiltinMethods do
4
- let(:input_blk) { proc {} }
5
- let(:app) { Shoes::App.new({}, &input_blk) }
6
- let(:logger) { double("logger") }
7
- let(:dialog) { double('dialog') }
8
-
9
- before :each do
10
- Shoes::LOG.clear
11
- allow(Shoes).to receive(:logger) { logger }
12
- end
13
-
14
- describe 'Shoes.p' do
15
- it 'adds a debug to the log with an inspected object' do
16
- Shoes.p 'message'
17
- expect(Shoes::LOG).to include ['debug', 'message'.inspect]
18
- end
19
-
20
- it 'also handles object the way they should be handled' do
21
- Shoes.p []
22
- expect(Shoes::LOG).to include ['debug', '[]']
23
- end
24
- end
25
-
26
- %w(info debug warn error).each do |level|
27
- describe "##{level}" do
28
- before :each do
29
- allow(logger).to receive(level)
30
- app.public_send(level, "test")
31
- end
32
-
33
- it 'sets Shoes::LOG' do
34
- expect(Shoes::LOG).to eq([[level, 'test']])
35
- end
36
-
37
- it 'sends message to logger' do
38
- expect(logger).to have_received(level)
39
- end
40
- end
41
- end
42
-
43
- %w(open_file save_file open_folder save_folder).each do |chooser_action|
44
- describe "#ask_#{chooser_action}" do
45
- before do
46
- allow(Shoes::Dialog).to receive(:new).and_return(dialog)
47
- expect(dialog).to receive(:dialog_chooser).and_return(dialog)
48
- end
49
-
50
- it 'creates a new chooser dialog' do
51
- expect(app.public_send("ask_#{chooser_action}")).to eq(dialog)
52
- end
53
- end
54
- end
55
-
56
- # just testing responds to things since the implementation is tested
57
- # elsewhere
58
- describe 'are builtin methods are also available from Shoes' do
59
- builtin_methods = [:alert, :ask, :ask_color, :ask_open_file, :ask_save_file,
60
- :ask_open_folder, :ask_save_folder, :confirm, :color,
61
- :debug, :error, :font, :gradient, :gray, :rgb, :info,
62
- :pattern, :warn]
63
-
64
- builtin_methods.each do |method|
65
- it "responds to #{method}" do
66
- expect(Shoes).to respond_to method
67
- end
68
- end
69
-
70
- describe 'does not get to the nitty gritty helper_methods' do
71
- helper_methods = [:image_file?, :image_pattern]
72
-
73
- helper_methods.each do |method|
74
- it "does not respond to #{method}" do
75
- expect(Shoes).not_to respond_to method
76
- end
77
- end
78
- end
79
- end
80
-
81
- %w(alert confirm).each do |type|
82
- describe '##{alert}' do
83
- let(:message) { double('message') }
84
-
85
- before do
86
- allow(Shoes::Dialog).to receive(:new).and_return(dialog)
87
- expect(dialog).to receive(type).with(message).and_return(dialog)
88
- end
89
-
90
- it 'creates a new dialog' do
91
- expect(app.public_send(type, message)).to eq(dialog)
92
- end
93
- end
94
- end
95
-
96
- describe '#ask' do
97
- let(:message) { double('message') }
98
- let(:args) { double('args') }
99
-
100
- before do
101
- allow(Shoes::Dialog).to receive(:new).and_return(dialog)
102
- expect(dialog).to receive(:ask).with(message, args).and_return(dialog)
103
- end
104
-
105
- it 'creates a new dialog' do
106
- expect(app.ask(message, args)).to eq(dialog)
107
- end
108
- end
109
-
110
- describe '#ask_color' do
111
- let(:title) { double('title') }
112
-
113
- before do
114
- allow(Shoes::Dialog).to receive(:new).and_return(dialog)
115
- expect(dialog).to receive(:ask_color).with(title).and_return(dialog)
116
- end
117
-
118
- it 'creates a new dialog' do
119
- expect(app.ask_color(title)).to eq(dialog)
120
- end
121
- end
122
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Button do
4
- include_context "dsl app"
5
-
6
- let(:input_opts) do
7
- { left: left, top: top, width: width, height: height, margin: margin, state: "disabled" }
8
- end
9
-
10
- let(:left) { 13 }
11
- let(:top) { 44 }
12
- let(:width) { 131 }
13
- let(:height) { 137 }
14
- let(:margin) { 14 }
15
-
16
- subject(:button) { Shoes::Button.new(app, parent, "text", input_opts, input_block) }
17
-
18
- it_behaves_like "movable object"
19
- it_behaves_like "object with state"
20
- it_behaves_like "object with style" do
21
- let(:subject_without_style) { Shoes::Button.new(app, parent, "text") }
22
- let(:subject_with_style) { Shoes::Button.new(app, parent, "text", arg_styles) }
23
- end
24
- it_behaves_like "object with dimensions"
25
-
26
- it { is_expected.to respond_to :click }
27
- it { is_expected.to respond_to :focus }
28
- it { is_expected.to respond_to :text= }
29
-
30
- describe "initialize" do
31
- its(:parent) { should eq(parent) }
32
- its(:text) { should eq("text") }
33
- its(:width) { should eq(131) }
34
- its(:height) { should eq(137) }
35
- its(:state) { should eq("disabled") }
36
- end
37
-
38
- describe ".text=" do
39
- it "changes the text" do
40
- expect(subject.gui).to receive(:text=).with("something else")
41
- subject.text = "something else"
42
- expect(subject.text).to eq "something else"
43
- end
44
- end
45
-
46
- describe "relative dimensions" do
47
- subject { Shoes::Button.new(app, parent, "text", relative_opts, input_block) }
48
- it_behaves_like "object with relative dimensions"
49
- end
50
-
51
- describe "negative dimensions" do
52
- subject { Shoes::Button.new(app, parent, "text", negative_opts, input_block) }
53
- it_behaves_like "object with negative dimensions"
54
- end
55
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Check do
4
- include_context "dsl app"
5
-
6
- let(:input_opts) { { width: 22, height: 22 } }
7
- subject { Shoes::Check.new(app, parent, input_opts, input_block) }
8
-
9
- it_behaves_like "checkable"
10
- it_behaves_like "object with state"
11
- it_behaves_like "object with style" do
12
- let(:subject_without_style) { Shoes::Check.new(app, parent) }
13
- let(:subject_with_style) { Shoes::Check.new(app, parent, arg_styles) }
14
- end
15
-
16
- describe "dimensions" do
17
- let(:left) { 10 }
18
- let(:top) { 20 }
19
- let(:width) { 100 }
20
- let(:height) { 200 }
21
- let(:input_opts) { {left: left, top: top, width: width, height: height} }
22
- subject { Shoes::Check.new(app, parent, input_opts) }
23
-
24
- it_behaves_like "object with dimensions"
25
-
26
- describe "takes relative dimensions from parent" do
27
- subject { Shoes::Check.new(app, parent, relative_opts) }
28
- it_behaves_like "object with relative dimensions"
29
- end
30
-
31
- describe "negative dimensions" do
32
- subject { Shoes::Check.new(app, parent, negative_opts) }
33
- it_behaves_like "object with negative dimensions"
34
- end
35
- end
36
- end
@@ -1,429 +0,0 @@
1
- require '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 { -> { 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 { -> { 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 { -> { Shoes::Color.new("a1") } }
44
- it_behaves_like "color with bad arguments"
45
- end
46
-
47
- context "with invalid hex chars" do
48
- subject { -> { 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(:color1) { 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
- color2 = Shoes::Color.new(255, 69, 0)
220
- expect(color1).to eq(color2)
221
- end
222
-
223
- it "is less than when darker" do
224
- color2 = Shoes::Color.new(255, 70, 0)
225
- expect(color1).to be < color2
226
- end
227
-
228
- it "is greater than when lighter" do
229
- color2 = Shoes::Color.new(255, 68, 0)
230
- expect(color1).to be > color2
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
- # shoes 3 compatibility behavior
242
- describe 'different colors' do
243
- it 'takes the total of rgb values to compare, less is less' do
244
- expect(create_rgb(100, 200, 0)).to be < create_rgb(50, 100, 151)
245
- end
246
-
247
- it 'takes the total of rgb values to compare, more is more' do
248
- expect(create_rgb(0, 200, 200)).to be > create_rgb(150, 150, 99)
249
- end
250
- end
251
-
252
- context "same rgb values" do
253
- let(:color2) { Shoes::Color.new(255, 69, 0, 254) }
254
- it "is less than when less opaque" do
255
- expect(color2).to be < color1
256
- end
257
-
258
- it "is greater than when more opaque" do
259
- expect(color1).to be > color2
260
- end
261
- end
262
- end
263
- end
264
-
265
- def create_rgb(r, g, b)
266
- Shoes::Color.new r, g, b
267
- end
268
- end
269
-
270
- describe "Shoes built-in colors" do
271
- class MockApp
272
- include Shoes::DSL
273
- end
274
-
275
- subject { MockApp.new }
276
-
277
- its(:papayawhip) { should eq(Shoes::Color.new(255, 239, 213)) }
278
- its(:aquamarine) { should eq(Shoes::Color.new(127, 255, 212)) }
279
- its(:tomato) { should eq(Shoes::Color.new(255, 99, 71)) }
280
-
281
- # define colors spec here since this has the other custom colors?
282
- it 'can use define_shoes_color to create built-in colors' do
283
- Shoes::DSL.define_shoes_color(:test_color, 0, 1, 2)
284
- expect(subject.test_color).to eq Shoes::Color.new(0, 1, 2)
285
- end
286
- end
287
-
288
- describe "Shoes built in gray" do
289
- let(:app) { Shoes::App.new }
290
-
291
- it "creates a dsl method for gray" do
292
- expect(app).to respond_to(:gray)
293
- end
294
-
295
- specify "gray with no parameters is [128, 128, 128, OPAQUE]" do
296
- expect(app.gray).to eq(Shoes::Color.new(128, 128, 128))
297
- end
298
-
299
- specify "single parameter specifies the gray level" do
300
- expect(app.gray(64)).to eq(Shoes::Color.new(64, 64, 64))
301
- end
302
-
303
- specify "two parameters specifies the gray level and opacity" do
304
- expect(app.gray(13, 57)).to eq(Shoes::Color.new(13, 13, 13, 57))
305
- end
306
-
307
- specify "float parameters should be normalised" do
308
- expect(app.gray(1.0, 0.5)).to eq(Shoes::Color.new(255, 255, 255, 128))
309
- end
310
-
311
- it 'hangles 0.93 right as well' do
312
- result93 = (0.93 * 255).to_i
313
- expect(app.gray(0.93)).to eq(Shoes::Color.new(result93, result93, result93))
314
- end
315
-
316
- it 'also has a grey alias for our BE friends' do
317
- expect(app).to respond_to :grey
318
- end
319
- end
320
-
321
- # Differences between this implementation and Red Shoes
322
- describe "differences from Red Shoes" do
323
- let(:white) { Shoes::Color.new(255, 255, 255) }
324
- let(:transparent_black) { Shoes::Color.new(0, 0, 0, 0) }
325
-
326
- context "integers" do
327
- specify "too-large values become 255" do
328
- expect(Shoes::Color.new(256, 256, 256, 256)).to eq(white)
329
- end
330
-
331
- specify "too-small values become 0" do
332
- expect(Shoes::Color.new(-1, -1, -1, -1)).to eq(transparent_black)
333
- end
334
- end
335
-
336
- context "floats" do
337
- specify "too-large values become 255" do
338
- expect(Shoes::Color.new(1.1, 1.1, 1.1, 1.1)).to eq(white)
339
- end
340
-
341
- specify "too-small values become 0" do
342
- expect(Shoes::Color.new(-0.1, -0.1, -0.1, -0.1)).to eq(transparent_black)
343
- end
344
- end
345
-
346
- # These specifications describe how this implementation differs from Red Shoes.
347
- # These are examples of what Red Shoes _does_ do, and what this implementation
348
- # _does not_ do.
349
- describe "unusual input" do
350
- let(:baseline) { Shoes::Color.new(50, 0, 200) }
351
-
352
- describe "too-large values" do
353
- specify "red does not get modulo-256'd into bounds" do
354
- expect(Shoes::Color.new(306, 0, 200)).not_to eq(baseline)
355
- expect(Shoes::Color.new(1.197, 0, 200)).not_to eq(baseline)
356
- end
357
-
358
- specify "green does not get modulo-256'd into bounds" do
359
- expect(Shoes::Color.new(50, 256, 200)).not_to eq(baseline)
360
- expect(Shoes::Color.new(50, 2.005, 200)).not_to eq(baseline)
361
- end
362
-
363
- specify "blue does not get modulo-256'd into bounds" do
364
- expect(Shoes::Color.new(50, 0, 456)).not_to eq(baseline)
365
- expect(Shoes::Color.new(50, 0, 2.7913137254902)).not_to eq(baseline)
366
- end
367
- end
368
-
369
- describe "negative values" do
370
- specify "-1 does not become 255" do
371
- expect(Shoes::Color.new(-1, -1, -1, -1)).not_to eq(Shoes::Color.new(255, 255, 255))
372
- end
373
-
374
- specify "256 and neighbors" do
375
- expect(Shoes::Color.new(-256, -255, -257)).not_to eq(Shoes::Color.new(0, 1, 255))
376
- end
377
-
378
- specify "float behaviour" do
379
- expect(Shoes::Color.new(-1.0, -0.5, -0.0)).not_to eq(Shoes::Color.new(0, 128, 1))
380
- end
381
- end
382
-
383
- describe "edge cases" do
384
- specify "0.0 does not become 1" do
385
- expect(Shoes::Color.new(0.0, 0.0, 0.0)).not_to eq(Shoes::Color.new(1, 1, 1))
386
- end
387
-
388
- specify "1.0 does not become 0" do
389
- expect(Shoes::Color.new(1.0, 1.0, 1.0)).not_to eq(Shoes::Color.new(0, 0, 0))
390
- end
391
- end
392
- end
393
- end
394
-
395
- describe Shoes::Color::DSLHelpers do
396
- class ColorDSLHelperTest
397
- include Shoes::Color::DSLHelpers
398
- end
399
-
400
- subject { ColorDSLHelperTest.new }
401
-
402
- describe '#pattern' do
403
- it 'creates an image pattern when fed a string for which a file exists' do
404
- allow(File).to receive_messages(exist?: true)
405
- my_path = '/some/path/to/image.png'
406
- image_pattern = subject.pattern(my_path)
407
- expect(image_pattern.path).to eq my_path
408
- end
409
-
410
- it 'raises an argument error for bad input like a single number' do
411
- expect { subject.pattern(1) }.to raise_error(ArgumentError)
412
- end
413
-
414
- it 'creates a gradient given 2 arguments' do
415
- expect(subject).to receive(:gradient)
416
- subject.pattern([10, 10, 10], [30, 30, 30])
417
- end
418
- end
419
-
420
- describe '#gradient' do
421
- it 'raises an argument error for no arguments supplied' do
422
- expect { subject.gradient }.to raise_error ArgumentError
423
- end
424
-
425
- it 'raises an argument error for too many (> 2) args supplied' do
426
- expect { subject.gradient 1, 2, 3 }.to raise_error ArgumentError
427
- end
428
- end
429
- end