shoes-swt 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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shoes/swt/app.rb +38 -2
  3. data/lib/shoes/swt/arc_painter.rb +36 -8
  4. data/lib/shoes/swt/common/painter.rb +9 -2
  5. data/lib/shoes/swt/common/update_position.rb +4 -0
  6. data/lib/shoes/swt/download.rb +7 -2
  7. data/lib/shoes/swt/font.rb +13 -5
  8. data/lib/shoes/swt/generate_backend.rb +34 -3
  9. data/lib/shoes/swt/line.rb +1 -0
  10. data/lib/shoes/swt/list_box.rb +1 -1
  11. data/lib/shoes/swt/redrawing_aspect.rb +4 -7
  12. data/lib/shoes/swt/text_block/text_segment.rb +10 -1
  13. data/lib/shoes/swt/version.rb +1 -1
  14. data/lib/shoes/swt.rb +2 -5
  15. metadata +11 -148
  16. data/Guardfile +0 -4
  17. data/Rakefile +0 -1
  18. data/shoes-swt.gemspec +0 -25
  19. data/spec/shoes/cli_spec.rb +0 -15
  20. data/spec/shoes/swt/animation_spec.rb +0 -86
  21. data/spec/shoes/swt/app_spec.rb +0 -166
  22. data/spec/shoes/swt/arc_painter_spec.rb +0 -80
  23. data/spec/shoes/swt/arc_spec.rb +0 -42
  24. data/spec/shoes/swt/arrow_painter_spec.rb +0 -37
  25. data/spec/shoes/swt/arrow_spec.rb +0 -27
  26. data/spec/shoes/swt/background_spec.rb +0 -69
  27. data/spec/shoes/swt/border_spec.rb +0 -55
  28. data/spec/shoes/swt/button_spec.rb +0 -104
  29. data/spec/shoes/swt/check_spec.rb +0 -39
  30. data/spec/shoes/swt/click_listener_spec.rb +0 -162
  31. data/spec/shoes/swt/color_factory_spec.rb +0 -49
  32. data/spec/shoes/swt/color_spec.rb +0 -68
  33. data/spec/shoes/swt/common/painter_spec.rb +0 -99
  34. data/spec/shoes/swt/common/remove_spec.rb +0 -46
  35. data/spec/shoes/swt/configuration_spec.rb +0 -11
  36. data/spec/shoes/swt/dialog_spec.rb +0 -97
  37. data/spec/shoes/swt/disposed_protection_spec.rb +0 -48
  38. data/spec/shoes/swt/flow_spec.rb +0 -38
  39. data/spec/shoes/swt/font_spec.rb +0 -31
  40. data/spec/shoes/swt/gradient_spec.rb +0 -37
  41. data/spec/shoes/swt/image_pattern_spec.rb +0 -45
  42. data/spec/shoes/swt/image_spec.rb +0 -100
  43. data/spec/shoes/swt/input_box_spec.rb +0 -119
  44. data/spec/shoes/swt/integration_spec.rb +0 -27
  45. data/spec/shoes/swt/key_listener_spec.rb +0 -353
  46. data/spec/shoes/swt/line_painter_spec.rb +0 -26
  47. data/spec/shoes/swt/line_spec.rb +0 -22
  48. data/spec/shoes/swt/link_segment_spec.rb +0 -121
  49. data/spec/shoes/swt/link_spec.rb +0 -49
  50. data/spec/shoes/swt/list_box_spec.rb +0 -81
  51. data/spec/shoes/swt/minimal.png +0 -0
  52. data/spec/shoes/swt/mouse_move_listener_spec.rb +0 -139
  53. data/spec/shoes/swt/oval_painter_spec.rb +0 -40
  54. data/spec/shoes/swt/oval_spec.rb +0 -19
  55. data/spec/shoes/swt/progress_spec.rb +0 -43
  56. data/spec/shoes/swt/radio_group_spec.rb +0 -72
  57. data/spec/shoes/swt/radio_spec.rb +0 -59
  58. data/spec/shoes/swt/rect_painter_spec.rb +0 -50
  59. data/spec/shoes/swt/rect_spec.rb +0 -17
  60. data/spec/shoes/swt/shape_painter_spec.rb +0 -27
  61. data/spec/shoes/swt/shape_spec.rb +0 -73
  62. data/spec/shoes/swt/shared_examples/button.rb +0 -19
  63. data/spec/shoes/swt/shared_examples/clickable.rb +0 -13
  64. data/spec/shoes/swt/shared_examples/movable.rb +0 -35
  65. data/spec/shoes/swt/shared_examples/paintable.rb +0 -6
  66. data/spec/shoes/swt/shared_examples/painter.rb +0 -82
  67. data/spec/shoes/swt/shared_examples/pattern.rb +0 -28
  68. data/spec/shoes/swt/shared_examples/removable.rb +0 -39
  69. data/spec/shoes/swt/shared_examples/swt_app_context.rb +0 -41
  70. data/spec/shoes/swt/shared_examples/visibility.rb +0 -15
  71. data/spec/shoes/swt/shell_control_listener_spec.rb +0 -23
  72. data/spec/shoes/swt/shoes_layout_spec.rb +0 -88
  73. data/spec/shoes/swt/slot_spec.rb +0 -41
  74. data/spec/shoes/swt/spec_helper.rb +0 -43
  75. data/spec/shoes/swt/star_painter_spec.rb +0 -36
  76. data/spec/shoes/swt/star_spec.rb +0 -22
  77. data/spec/shoes/swt/text_block/centered_text_segment_spec.rb +0 -16
  78. data/spec/shoes/swt/text_block/cursor_painter_spec.rb +0 -128
  79. data/spec/shoes/swt/text_block/fitter_spec.rb +0 -234
  80. data/spec/shoes/swt/text_block/painter_spec.rb +0 -52
  81. data/spec/shoes/swt/text_block/text_font_factory_spec.rb +0 -40
  82. data/spec/shoes/swt/text_block/text_segment_collection_spec.rb +0 -272
  83. data/spec/shoes/swt/text_block/text_segment_spec.rb +0 -138
  84. data/spec/shoes/swt/text_block_spec.rb +0 -213
  85. data/spec/spec_helper.rb +0 -25
@@ -1,82 +0,0 @@
1
- # Provide `shape` (a double) and `subject` (a Painter)
2
-
3
- shared_context "painter context" do
4
- let(:event) { double("event", gc: gc) }
5
- let(:gc) { double("gc", get_line_width: sw).as_null_object }
6
- let(:fill) { Shoes::Swt::Color.new(Shoes::Color.new(11, 12, 13, fill_alpha)) }
7
- let(:stroke) { Shoes::Swt::Color.new(Shoes::Color.new(111, 112, 113, stroke_alpha)) }
8
- let(:fill_alpha) { 70 }
9
- let(:stroke_alpha) { 110 }
10
- let(:sw) { 10 }
11
-
12
- before :each do
13
- allow(shape).to receive(:fill) { fill }
14
- allow(shape).to receive(:fill_alpha) { fill_alpha }
15
- allow(shape).to receive(:stroke) { stroke }
16
- allow(shape).to receive(:stroke_alpha) { stroke_alpha }
17
- allow(subject).to receive(:reset_rotate) { double("reset_rotate").as_null_object }
18
- end
19
- end
20
-
21
- shared_examples_for "movable painter" do
22
- describe "when moved" do
23
- let(:transform) { double("transform").as_null_object }
24
-
25
- before :each do
26
- allow(::Swt::Transform).to receive(:new) { transform }
27
- shape.update_position
28
- end
29
-
30
- it "applies transform" do
31
- expect(gc).to receive(:set_transform).with(transform)
32
- subject.paint_control(event)
33
- end
34
- end
35
- end
36
-
37
- shared_examples_for "stroke painter" do
38
- describe "sets stroke" do
39
- specify "color" do
40
- expect(gc).to receive(:set_foreground).with(stroke.real)
41
- subject.paint_control(event)
42
- end
43
-
44
- specify "alpha" do
45
- allow(gc).to receive(:set_alpha)
46
- expect(gc).to receive(:set_alpha).with(stroke_alpha)
47
- subject.paint_control(event)
48
- end
49
- end
50
-
51
- it "sets strokewidth" do
52
- allow(shape).to receive(:strokewidth) { 4 }
53
- expect(gc).to receive(:set_line_width).with(4)
54
- subject.paint_control(event)
55
- end
56
-
57
- it "sets antialias" do
58
- expect(gc).to receive(:set_antialias).with(Swt::SWT::ON)
59
- subject.paint_control(event)
60
- end
61
-
62
- it "sets line cap" do
63
- expect(gc).to receive(:set_line_cap).with(anything)
64
- subject.paint_control(event)
65
- end
66
- end
67
-
68
- shared_examples_for "fill painter" do
69
- describe "sets fill" do
70
- specify "color" do
71
- expect(gc).to receive(:set_background).with(fill.real)
72
- subject.paint_control(event)
73
- end
74
-
75
- specify "alpha" do
76
- # Once for stroke, once for fill
77
- allow(gc).to receive(:set_alpha)
78
- expect(gc).to receive(:set_alpha).with(fill_alpha)
79
- subject.paint_control(event)
80
- end
81
- end
82
- end
@@ -1,28 +0,0 @@
1
- shared_examples_for "an swt pattern" do
2
- it { is_expected.to respond_to(:apply_as_stroke) }
3
- it { is_expected.to respond_to(:apply_as_fill) }
4
-
5
- describe "#apply_as_stroke" do
6
- let(:gc) { double("graphics context") }
7
-
8
- it "sets foreground" do
9
- if subject.is_a? Shoes::Swt::Color
10
- allow(gc).to receive(:set_alpha)
11
- expect(gc).to receive(:set_foreground)
12
- else
13
- expect(gc).to receive(:set_foreground_pattern)
14
- end
15
- subject.apply_as_stroke(gc, applied_to)
16
- end
17
-
18
- it "sets alpha" do
19
- if subject.is_a? Shoes::Swt::Color
20
- allow(gc).to receive(:set_foreground)
21
- expect(gc).to receive(:set_alpha)
22
- else
23
- expect(gc).to receive(:set_foreground_pattern)
24
- end
25
- subject.apply_as_stroke(gc, applied_to)
26
- end
27
- end
28
- end
@@ -1,39 +0,0 @@
1
- shared_examples_for "removable" do
2
- it "should respond to remove" do
3
- expect(subject).to respond_to :remove
4
- end
5
-
6
- it "should remove paint listener" do
7
- expect(swt_app).to receive(:remove_paint_listener)
8
- expect(click_listener).to receive(:remove_listeners_for)
9
- subject.remove
10
- end
11
-
12
- it "disposes color factory if present" do
13
- swt_app.as_null_object
14
-
15
- color_factory = double("color factory")
16
- expect(color_factory).to receive(:dispose)
17
- subject.instance_variable_set(:@color_factory, color_factory)
18
-
19
- subject.remove
20
- end
21
- end
22
-
23
- shared_examples_for "removable native element" do
24
- it "should respond to remove" do
25
- expect(subject).to respond_to :remove
26
- end
27
-
28
- it "should dispose real when real is not disposed" do
29
- allow(real).to receive(:disposed?) { false }
30
- expect(real).to receive(:dispose)
31
- subject.remove
32
- end
33
-
34
- it "should not dispose real when real is already disposed" do
35
- allow(real).to receive(:disposed?) { true }
36
- expect(real).not_to receive(:dispose)
37
- subject.remove
38
- end
39
- end
@@ -1,41 +0,0 @@
1
- # This is a common context for running Shoes::Swt specs.
2
- # - parent: use for instantiating a Shoes::Swt object
3
- # - swt_app: use for instantiating a Shoes::Swt object
4
- # - shoes_app: use for instantiating a Shoes DSL object
5
- shared_context "swt app" do
6
- let(:swt_app_real) do
7
- double('swt app real', disposed?: false, set_visible: true)
8
- end
9
-
10
- let(:clickable_element) { double("clickable_element", delete: nil) }
11
-
12
- let(:click_listener) do
13
- double("click listener", add_click_listener: nil, add_release_listener: nil,
14
- remove_listeners_for: nil)
15
- end
16
-
17
- let(:swt_app) do
18
- swt_double = double('swt app', real: swt_app_real, disposed?: false,
19
- add_paint_listener: true, remove_paint_listener: true,
20
- add_clickable_element: true, add_listener: true,
21
- remove_listener: true, flush: true, redraw: true,
22
- click_listener: click_listener,
23
- clickable_elements: clickable_element)
24
- allow(swt_double).to receive(:app).and_return(swt_double)
25
- swt_double
26
- end
27
-
28
- let(:shoes_app) { double('shoes app', gui: swt_app, rotate: 0, style: {}, element_styles: {}) }
29
-
30
- let(:parent) do
31
- double('parent', app: swt_app, add_child: true, real: true,
32
- absolute_left: 0, absolute_top: 0,
33
- width: 200, height: 100, fixed_height?: true)
34
- end
35
-
36
- let(:parent_dsl) do
37
- double("parent dsl", add_child: true, contents: [], gui: parent,
38
- x_dimension: double.as_null_object,
39
- y_dimension: double.as_null_object)
40
- end
41
- end
@@ -1,15 +0,0 @@
1
- shared_examples_for "updating visibility" do
2
- it "triggers redrawing on the app" do
3
- with_redraws do
4
- expect(swt_app).to receive(:redraw)
5
- subject.update_visibility
6
- end
7
- end
8
-
9
- it "passes visibility to real object" do
10
- if subject.respond_to?(:gui) && subject.gui.respond_to?(:real)
11
- expect(subject.gui.real).to receive(:set_visible)
12
- subject.update_visibility
13
- end
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::ShellControlListener do
4
- let(:app) { double 'SWT App', dsl: dsl_app, shell: shell, real: real }
5
- let(:shell) { double('Shell').as_null_object }
6
- let(:resize_callbacks) { [] }
7
- let(:dsl_app) { double('DSL App', resize_callbacks: resize_callbacks).as_null_object }
8
- let(:block) { double 'Block', call: nil }
9
- let(:resize_event) { double 'resize_event', widget: shell }
10
- let(:real) { double('Swt Real').as_null_object }
11
-
12
- subject { Shoes::Swt::ShellControlListener.new(app) }
13
- before :each do
14
- subject.controlResized(resize_event)
15
- end
16
-
17
- describe 'resize' do
18
- let(:resize_callbacks) { [block] }
19
- it 'calls the resize block' do
20
- expect(block).to have_received(:call)
21
- end
22
- end
23
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::ShoesLayout do
4
- subject do
5
- result = Shoes::Swt::ShoesLayout.new
6
- result.gui_app = gui_app
7
- result
8
- end
9
-
10
- let(:gui_app) { double('gui_app', dsl: dsl, real: real, shell: shell) }
11
- let(:size) { double('size', height: 0, width: 0) }
12
- let(:location) { double('location', :y= => nil) }
13
- let(:dsl) { double('dsl', top_slot: top_slot, height: 100, width: 100) }
14
- let(:shell) { double('shell', vertical_bar: vertical_bar) }
15
-
16
- let(:scroll_height) { dsl.height * 2 }
17
-
18
- let(:real) do
19
- double('real', set_size: nil, location: location, :location= => nil)
20
- end
21
-
22
- let(:top_slot) do
23
- double('top_slot', contents_alignment: 0, :width= => nil, :height= => nil)
24
- end
25
-
26
- let(:vertical_bar) do
27
- double('vertical_bar', :increment= => nil, :visible= => nil,
28
- :maximum= => nil, :thumb= => nil, thumb: 0)
29
- end
30
-
31
- before do
32
- allow(real).to receive(:compute_trim) do |_, _, width, height|
33
- double('size', width: width, height: height)
34
- end
35
- end
36
-
37
- it "sets size on real element" do
38
- expect(real).to receive(:set_size).with(dsl.width, dsl.height)
39
- subject.layout
40
- end
41
-
42
- it "sets height on real element to scrollable height when that's bigger" do
43
- when_contents_scroll
44
- expect(real).to receive(:set_size).with(dsl.width, scroll_height)
45
- subject.layout
46
- end
47
-
48
- it "sets size on top slot" do
49
- expect(top_slot).to receive(:width=).with(dsl.width)
50
- expect(top_slot).to receive(:height=).with(dsl.height)
51
- subject.layout
52
- end
53
-
54
- it "sets height on top slot to scrollable height when that's bigger" do
55
- when_contents_scroll
56
- expect(top_slot).to receive(:width=).with(dsl.width)
57
- expect(top_slot).to receive(:height=).with(scroll_height)
58
- subject.layout
59
- end
60
-
61
- it "shows scrollbar" do
62
- when_contents_scroll
63
- expect(vertical_bar).to receive(:visible=).with(true)
64
- subject.layout
65
- end
66
-
67
- it "updates settings on scrollbar when visible" do
68
- when_contents_scroll
69
- [:thumb=, :maximum=, :increment=].each do |m|
70
- expect(vertical_bar).to receive(m)
71
- end
72
- subject.layout
73
- end
74
-
75
- it "hides scrollbar" do
76
- expect(vertical_bar).to receive(:visible=).with(false)
77
- subject.layout
78
- end
79
-
80
- it "sets gui location when scrollbar hidden" do
81
- expect(real).to receive(:location=).with(location)
82
- subject.layout
83
- end
84
-
85
- def when_contents_scroll
86
- allow(top_slot).to receive(:contents_alignment) { scroll_height }
87
- end
88
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::Slot do
4
- include_context "swt app"
5
-
6
- let(:dsl) do
7
- instance_double Shoes::Slot, hidden?: true, visible?: false,
8
- contents: [content]
9
- end
10
-
11
- let(:content) { double 'content', show: true, hide: true }
12
-
13
- subject { Shoes::Swt::Slot.new dsl, swt_app }
14
-
15
- describe '#update_visibility' do
16
- it 'does not set visibility on the parent #904' do
17
- subject.update_visibility
18
- expect(swt_app.real).not_to have_received(:set_visible)
19
- end
20
-
21
- # spec may be deleted if we can hide entire rather than their contents
22
- it 'tries to hide the content' do
23
- subject.update_visibility
24
- expect(content).to have_received :hide
25
- end
26
-
27
- # spec may be deleted if we can hide entire rather than their contents
28
- it 'only hides on visibility changes' do
29
- subject.update_visibility
30
- subject.update_visibility
31
- expect(content).to have_received(:hide).once
32
- end
33
- end
34
-
35
- describe '#remove' do
36
- it 'cleans up click listeners' do
37
- expect(swt_app.click_listener).to receive(:remove_listeners_for).with(dsl)
38
- subject.remove
39
- end
40
- end
41
- end
@@ -1,43 +0,0 @@
1
- require "shoes/swt"
2
- require "spec_helper"
3
-
4
- Shoes.load_backend("swt").initialize_backend
5
-
6
- RSpec.configure do |config|
7
- config.before(:each) do
8
- allow(Swt).to receive(:event_loop)
9
- allow_any_instance_of(Shoes::Swt::App).to receive_messages(flush: true)
10
- allow_any_instance_of(Swt::Widgets::Shell).to receive(:open)
11
- allow_any_instance_of(Swt::Widgets::MessageBox).to receive(:open)
12
- # stubbed as otherwise all sorts of callbacks are added during certain specs,
13
- # which then fail because some doubles are not made for the methods called
14
- allow(Shoes::Swt::RedrawingAspect).to receive_messages new: true
15
- end
16
-
17
- # https://github.com/jruby/jruby/wiki/Persistence
18
- # mostly to allow stubbing/mocking of said java classes
19
- config.before(:all) do
20
- Swt::Widgets::Shell.__persistent__ = true
21
- Swt::Widgets::MessageBox.__persistent__ = true
22
- Swt::Path.__persistent__ = true
23
- Swt::Transform.__persistent__ = true
24
- Swt::Font.__persistent__ = true
25
- Swt::Widgets::Display.__persistent__ = true
26
- end
27
- end
28
-
29
- # as we do not create real apps most of the time there are no redraws and we
30
- # we don't really want that during test execution either way as it adds stuff to
31
- # methods that might break
32
- def with_redraws
33
- allow(Shoes::Swt::RedrawingAspect).to receive(:new).and_call_original
34
- aspect = Shoes::Swt::RedrawingAspect.new swt_app, double
35
- begin
36
- yield
37
- ensure
38
- aspect.remove_redraws
39
- end
40
- end
41
-
42
- shared_examples = File.expand_path('../shared_examples/**/*.rb', __FILE__)
43
- Dir[shared_examples].each { |f| require f }
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::StarPainter do
4
- include_context "swt app"
5
- include_context "painter context"
6
-
7
- let(:left) { 55 }
8
- let(:top) { 77 }
9
- let(:points) { 7 }
10
- let(:outer) { 100 }
11
- let(:inner) { 20 }
12
- let(:corners) { 0 }
13
-
14
- let(:dsl) do
15
- double("dsl object", hidden: false, points: points, outer: outer,
16
- inner: inner, element_width: outer * 2.0,
17
- element_height: outer * 2.0, element_left: left,
18
- element_top: top).as_null_object
19
- end
20
-
21
- let(:shape) { Shoes::Swt::Star.new dsl, swt_app }
22
- subject { Shoes::Swt::StarPainter.new shape }
23
-
24
- it_behaves_like "fill painter"
25
- it_behaves_like "stroke painter"
26
-
27
- it "fills star" do
28
- expect(gc).to receive(:fillPolygon)
29
- subject.paint_control(event)
30
- end
31
-
32
- it "draws star" do
33
- expect(gc).to receive(:drawPolygon)
34
- subject.paint_control(event)
35
- end
36
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::Star do
4
- include_context "swt app"
5
-
6
- let(:left) { 55 }
7
- let(:top) { 77 }
8
- let(:points) { 7 }
9
- let(:outer) { 100 }
10
- let(:inner) { 20 }
11
- let(:dsl) { Shoes::Star.new shoes_app, parent, left, top, points, outer, inner }
12
-
13
- subject { Shoes::Swt::Star.new dsl, swt_app }
14
-
15
- context "#initialize" do
16
- its(:dsl) { is_expected.to be(dsl) }
17
- end
18
-
19
- it_behaves_like "paintable"
20
- it_behaves_like "updating visibility"
21
- it_behaves_like 'clickable backend'
22
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::TextBlock::CenteredTextSegment do
4
- let(:width) { 200 }
5
- let(:dsl) { double("dsl", text: "boo", font: "", size: 16, style: {}) }
6
-
7
- subject { Shoes::Swt::TextBlock::CenteredTextSegment.new(dsl, width) }
8
-
9
- it "takes all the width it can get" do
10
- expect(subject.width).to eq(width)
11
- end
12
-
13
- it "calls last line width the full width" do
14
- expect(subject.last_line_width).to eq(width)
15
- end
16
- end
@@ -1,128 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoes::Swt::TextBlock::CursorPainter do
4
- include_context "swt app"
5
-
6
- let(:dsl) { double("dsl", app: shoes_app, textcursor: textcursor, textcursor?: true) }
7
- let(:textcursor) { double("textcursor", left: 0, top: 0, height: 10) }
8
-
9
- let(:segment_collection) do
10
- double('segment collection', cursor_height: 12, relative_text_position: 0)
11
- end
12
-
13
- subject { Shoes::Swt::TextBlock::CursorPainter.new(dsl, segment_collection) }
14
-
15
- describe "missing cursor" do
16
- before(:each) do
17
- allow(dsl).to receive(:cursor) { nil }
18
- allow(dsl).to receive(:textcursor=)
19
- allow(textcursor).to receive(:remove)
20
- allow(textcursor).to receive(:textcursor=)
21
- end
22
-
23
- it "shouldn't do anything without text cursor" do
24
- allow(dsl).to receive(:textcursor?) { nil }
25
- subject.draw
26
- expect(dsl).to_not have_received(:textcursor=)
27
- end
28
-
29
- it "should remove leftover text cursor" do
30
- subject.draw
31
- expect(dsl).to have_received(:textcursor=)
32
- expect(textcursor).to have_received(:remove)
33
- end
34
- end
35
-
36
- describe "cursor positioning" do
37
- let(:left) { 10 }
38
- let(:top) { 20 }
39
- let(:position) { double(x: 5, y: 5) }
40
-
41
- let(:first_segment) do
42
- double("first segment", text: "first", get_location: position, height: 10,
43
- element_left: left, element_top: top)
44
- end
45
-
46
- before(:each) do
47
- allow(textcursor).to receive(:move)
48
- allow(textcursor).to receive(:show)
49
- end
50
-
51
- context "with two segments" do
52
- let(:second_segment) do
53
- double("second segment", text: "second", get_location: position,
54
- element_left: left, element_top: top + 100)
55
- end
56
-
57
- before(:each) do
58
- allow(dsl).to receive(:text).and_return(first_segment.text + second_segment.text)
59
- end
60
-
61
- context "when moving" do
62
- context "in the first segment" do
63
- before :each do
64
- allow(dsl).to receive(:cursor) { 1 }
65
- allow(segment_collection).to receive(:segment_at_text_position) { first_segment }
66
- end
67
-
68
- it "moves" do
69
- subject.draw
70
- expect(textcursor).to have_received(:move).with(left + position.x,
71
- top + position.y,
72
- left + position.x,
73
- top + position.y + textcursor.height)
74
- expect(textcursor).to have_received(:show)
75
- end
76
-
77
- it "does not move when already in position" do
78
- allow(textcursor).to receive(:left) { left + position.x }
79
- allow(textcursor).to receive(:top) { top + position.y }
80
- allow(subject).to receive(:move_textcursor)
81
-
82
- subject.draw
83
-
84
- expect(subject).to_not have_received(:move_textcursor)
85
- end
86
- end
87
-
88
- context "in the second segment" do
89
- before :each do
90
- allow(dsl).to receive(:cursor) { -1 }
91
- allow(segment_collection).to receive(:segment_at_text_position) { second_segment }
92
- end
93
-
94
- it "moves" do
95
- subject.draw
96
- expect(textcursor).to have_received(:move).with(left + position.x,
97
- top + 100 + position.y,
98
- left + position.x,
99
- top + 100 + position.y + textcursor.height)
100
- expect(textcursor).to have_received(:show)
101
- end
102
-
103
- it "does not move when already in position" do
104
- allow(textcursor).to receive(:left) { left + position.x }
105
- allow(textcursor).to receive(:top) { top + 100 + position.y }
106
- allow(subject).to receive(:move_textcursor)
107
-
108
- subject.draw
109
-
110
- expect(subject).to_not have_received(:move_textcursor)
111
- end
112
- end
113
- end
114
- end
115
- end
116
-
117
- describe "textcursor management" do
118
- before(:each) do
119
- allow(shoes_app).to receive(:textcursor)
120
- end
121
-
122
- it "delegates to dsl" do
123
- allow(dsl).to receive(:textcursor) { textcursor }
124
- result = subject.textcursor
125
- expect(result).to eq(textcursor)
126
- end
127
- end
128
- end