Skip to content

Commit

Permalink
Update Image, Shape specs for shared Swt backend
Browse files Browse the repository at this point in the history
Also, eliminate temporary test-double shims for allowing
differently-named doubles in shared specs
  • Loading branch information
wasnotrice committed Dec 11, 2013
1 parent 9c411b2 commit 21df1bc
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 63 deletions.
5 changes: 2 additions & 3 deletions lib/shoes/swt/common/clickable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ def add_listener_for(object = self, event, block)
end
listener = ClickListener.new(dsl_object, block)
object.click_listener = listener
app_gui = dsl_object.app.gui
app_gui.add_clickable_element dsl_object
app_gui.real.addListener event, listener
app.add_clickable_element dsl_object
app.add_listener event, listener
end


Expand Down
3 changes: 1 addition & 2 deletions lib/shoes/swt/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Image
def initialize(dsl, parent, blk)
@dsl = dsl
@parent = parent
@container = parent.real

load_image(@dsl.file_path)

Expand Down Expand Up @@ -128,7 +127,7 @@ def add_paint_listener
graphics_context = event.gc
graphics_context.drawImage @real, 0, 0, @full_width, @full_height, dsl.element_left, dsl.element_top, dsl.element_width, dsl.element_height unless @dsl.hidden
end
@container.add_paint_listener(@painter)
app.add_paint_listener(@painter)
end

end
Expand Down
15 changes: 4 additions & 11 deletions spec/swt_shoes/border_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'swt_shoes/spec_helper'

describe Shoes::Swt::Border do
let(:container) { double('container', :disposed? => false) }
let(:app) { double('app', :real => container, :add_paint_listener => true) }
include_context "swt app"

let(:left) { 55 }
let(:top) { 77 }
let(:width) { 222 }
Expand All @@ -11,19 +11,12 @@
let(:dsl) { double("dsl object", element_width: width, element_height: height,
element_left: left, element_top: top, parent: parent,
strokewidth: 1, corners: corners,hidden: false).as_null_object }
let(:parent) { double("parent", width: width, height: height,
absolute_left: left, absolute_top: top, contents: []) }

subject { Shoes::Swt::Border.new dsl, app }
subject { Shoes::Swt::Border.new dsl, swt_app }

context "#initialize" do
it { should be_an_instance_of(Shoes::Swt::Border) }
its(:dsl) { should be(dsl) }

specify "adds paint listener" do
app.should_receive(:add_paint_listener)
subject
end
end

it_behaves_like "paintable"
Expand All @@ -32,7 +25,7 @@
include_context "painter context"

let(:corners) { 0 }
let(:shape) { Shoes::Swt::Border.new dsl, app }
let(:shape) { Shoes::Swt::Border.new dsl, swt_app }
subject { Shoes::Swt::Border::Painter.new shape }

it_behaves_like "stroke painter"
Expand Down
12 changes: 3 additions & 9 deletions spec/swt_shoes/image_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
require 'swt_shoes/spec_helper'

describe Shoes::Swt::Image do
include_context "swt app"

IMAGE_WIDTH = 3
IMAGE_HEIGHT = 1

let(:container) { parent.real }
let(:paint_container) { parent.real }
let(:blk) { double("block") }
let(:parent_dsl) { double("parent dsl", add_child: nil, contents: [], gui: parent) }
let(:parent) { double("parent", real: real, app: swt_app) }
let(:dsl) { Shoes::Image.new app, parent_dsl, image, opts}
let(:dsl) { Shoes::Image.new shoes_app, parent_dsl, image, opts}
let(:opts) {{left: left, top: top, width: width, height: height}}
let(:left) { 100 }
let(:top) { 200 }
let(:height) { nil }
let(:width) {nil}
let(:real) { double 'real', addListener: true, add_paint_listener: true }
let(:swt_app) { double("swt_app", real: real, disposed?: false, clickable_elements: [], add_clickable_element: nil) }
let(:app) { double("app", gui: swt_app) }
let(:image) { "spec/swt_shoes/minimal.png" }

subject {
Expand All @@ -36,7 +31,7 @@
let(:gc) { double("gc", drawImage: true) }

before :each do
paint_container.should_receive(:add_paint_listener)
swt_app.should_receive(:add_paint_listener)
end

specify "draws image" do
Expand Down Expand Up @@ -102,6 +97,5 @@
subject.height.should == 2
end
end

end
end
7 changes: 4 additions & 3 deletions spec/swt_shoes/shape_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'swt_shoes/spec_helper'

describe Shoes::Swt::Shape do
let(:app) { double("app", add_paint_listener: true) }
include_context "swt app"

let(:dsl) { double('dsl', hidden: false).as_null_object }
subject { Shoes::Swt::Shape.new dsl, app }
subject { Shoes::Swt::Shape.new dsl, swt_app }

shared_examples_for "Swt::Shape" do
let(:ancestors) { subject.class.ancestors.map(&:name) }
Expand Down Expand Up @@ -60,7 +61,7 @@
describe "painter" do
include_context "painter context"

let(:shape) { Shoes::Swt::Shape.new(dsl, app) }
let(:shape) { Shoes::Swt::Shape.new(dsl, swt_app) }
subject { Shoes::Swt::Shape::Painter.new(shape) }

it_behaves_like "stroke painter"
Expand Down
21 changes: 8 additions & 13 deletions spec/swt_shoes/shared_examples/clickable.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
shared_examples 'clickable backend' do

before :each do
subject.stub dsl: click_dsl
swt_app.stub :add_clickable_element
dsl.stub(:in_bounds?) { true }
end

let(:click_dsl) {double 'dsl', app: click_dsl_app, in_bounds?: true}
let(:click_dsl_app) {double 'dsl_app', gui: click_swt_app}
let(:click_swt_app) {double 'swt_app', real: click_real,
add_clickable_element: true}
let(:click_real) {double 'real', addListener: true}

it {should respond_to :clickable}
let(:clickable_block) {double 'clickable_block'}
let(:clickable_subject) do
subject.clickable clickable_block
Expand All @@ -19,6 +13,8 @@

let(:mouse_event) {double 'mouse_event', button: 1, x: 2, y:3}

it {should respond_to :clickable}

it 'its click_handler should not be nil' do
clickable_subject.click_listener.should_not be_nil
end
Expand All @@ -28,14 +24,14 @@
clickable_subject.click_listener.handleEvent mouse_event
end

describe 'interaction with the app gui' do
describe 'interaction with the swt app object' do

def expect_adds_listener_for(event)
click_real.should_receive(:addListener).with(event, clickable_subject.click_listener)
swt_app.should_receive(:add_listener).with(event, clickable_subject.click_listener)
end

it 'receives the add_clickable_element message' do
click_swt_app.should_receive(:add_clickable_element)
swt_app.should_receive(:add_clickable_element)
clickable_subject
end

Expand All @@ -54,5 +50,4 @@ def expect_adds_listener_for(event)
subject.release do ; end
end
end

end
end
16 changes: 1 addition & 15 deletions spec/swt_shoes/shared_examples/paintable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
shared_examples_for "paintable" do
it "registers for painting" do
# Transitioning from gui_container_real to app_real
begin
container = paint_container
rescue
begin
container = gui_container_real
rescue
begin
container = swt_app
rescue
container = app
end
end
end
container.should_receive(:add_paint_listener)
swt_app.should_receive(:add_paint_listener)
subject
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/swt_shoes/shared_examples/swt_app_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
shared_context "swt app" do
let(:swt_app_real) { double('swt app real') }
let(:swt_app) { double('swt app', real: swt_app_real, disposed?: false,
add_paint_listener: true, remove_paint_listener: true) }
add_paint_listener: true, remove_paint_listener: true,
add_clickable_element: true, add_listener: true) }
let(:shoes_app) { double('shoes app', gui: swt_app, unslotted_elements: [], rotate: 0) }#.as_null_object }
let(:parent) { double('parent', app: swt_app, real: true) }
end
Expand Down
7 changes: 1 addition & 6 deletions spec/swt_shoes/shared_examples/togglable.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
shared_examples_for "togglable" do
it "triggers redrawing on the app" do
begin
container = swt_app
rescue
container = container
end
expect(container).to receive(:redraw)
expect(swt_app).to receive(:redraw)
subject.toggle
end

Expand Down

0 comments on commit 21df1bc

Please sign in to comment.