Browse Source

Fix mock object tests

dev
Andy Meneely 11 years ago
parent
commit
04ac3f730a
  1. 1
      lib/squib/graphics/image.rb
  2. 21
      spec/graphics/graphics_images_spec.rb

1
lib/squib/graphics/image.rb

@ -56,7 +56,6 @@ module Squib
cc.rotate(trans.angle) cc.rotate(trans.angle)
cc.scale(scale_width, scale_height) cc.scale(scale_width, scale_height)
cc.operator = paint.blend unless paint.blend == :none cc.operator = paint.blend unless paint.blend == :none
#FIXME Alpha is no longer used since we are not using cc.paint anymore
if paint.mask.to_s.empty? if paint.mask.to_s.empty?
cc.render_rsvg_handle(svg, svg_args.id) cc.render_rsvg_handle(svg, svg_args.id)
else else

21
spec/graphics/graphics_images_spec.rb

@ -1,5 +1,6 @@
require 'spec_helper' require 'spec_helper'
require 'squib' require 'squib'
require 'ostruct'
describe Squib::Card do describe Squib::Card do
@ -7,6 +8,9 @@ describe Squib::Card do
let(:context) { double(Cairo::Context) } let(:context) { double(Cairo::Context) }
let(:svg) { double(RSVG::Handle) } let(:svg) { double(RSVG::Handle) }
let(:png) { double(Cairo::ImageSurface) } let(:png) { double(Cairo::ImageSurface) }
let(:box) { OpenStruct.new({x: 37, y: 38, width: :native, height: :native})}
let(:paint) { OpenStruct.new({alpha: 0.9, blend: :none, mask: '' })}
let(:trans) { OpenStruct.new({angle: 0.0})}
before(:each) do before(:each) do
allow(Cairo::Context).to receive(:new).and_return(context) allow(Cairo::Context).to receive(:new).and_return(context)
@ -33,7 +37,7 @@ describe Squib::Card do
card = Squib::Card.new(deck, 100, 150) card = Squib::Card.new(deck, 100, 150)
# png(file, x, y, alpha, blend, angle) # png(file, x, y, alpha, blend, angle)
card.png('foo.png', 37, 38, :native, :native, 0.9, :none, 0.0, nil) card.png('foo.png', box, paint, trans)
end end
it 'sets blend when needed' do it 'sets blend when needed' do
@ -41,11 +45,14 @@ describe Squib::Card do
expect(context).to receive(:operator=).with(:overlay).once expect(context).to receive(:operator=).with(:overlay).once
card = Squib::Card.new(deck, 100, 150) card = Squib::Card.new(deck, 100, 150)
card.png('foo.png', 37, 38, :native, :native, 0.9, :overlay, 0.0, nil) paint.blend = :overlay
card.png('foo.png', box, paint, trans)
end end
end end
context '#svg' do context '#svg' do
let(:svg_args) { OpenStruct.new({data: '<svg></svg>', id: 'id'}) }
it 'makes all the expected calls on a smoke test' do it 'makes all the expected calls on a smoke test' do
expect(svg).to receive(:width).and_return(100).twice expect(svg).to receive(:width).and_return(100).twice
expect(svg).to receive(:height).and_return(100).twice expect(svg).to receive(:height).and_return(100).twice
@ -58,8 +65,7 @@ describe Squib::Card do
expect(context).to receive(:restore).once expect(context).to receive(:restore).once
card = Squib::Card.new(deck, 100, 150) card = Squib::Card.new(deck, 100, 150)
# svg(file, data, id, x, y, width, height, alpha, blend, angle) card.svg(nil, svg_args, box, paint, trans)
card.svg(nil, '<svg></svg>', 'id', 37, 38, :native, :native, 0.9, :none, 0.0, nil)
end end
it 'sets blend when needed' do it 'sets blend when needed' do
@ -68,7 +74,8 @@ describe Squib::Card do
expect(context).to receive(:operator=).with(:overlay).once expect(context).to receive(:operator=).with(:overlay).once
card = Squib::Card.new(deck, 100, 150) card = Squib::Card.new(deck, 100, 150)
card.svg(nil, '<svg></svg>', nil, 37, 38, :native, :native, 0.9, :overlay, 0.0, nil) paint.blend = :overlay
card.svg(nil, svg_args, box, paint, trans)
end end
it 'sets width & height when needed' do it 'sets width & height when needed' do
@ -78,7 +85,9 @@ describe Squib::Card do
expect(context).to receive(:scale).with(2.0, 3.0).once expect(context).to receive(:scale).with(2.0, 3.0).once
card = Squib::Card.new(deck, 100, 150) card = Squib::Card.new(deck, 100, 150)
card.svg(nil, '<svg></svg>', nil, 37, 38, 200, 300, 0.9, :none, 0.0, nil) box.width = 200
box.height = 300
card.svg(nil, svg_args, box, paint, trans)
end end
end end

Loading…
Cancel
Save