4 changed files with 101 additions and 7 deletions
@ -0,0 +1,79 @@
|
||||
require 'spec_helper' |
||||
require 'squib' |
||||
|
||||
describe Squib::Card do |
||||
|
||||
before(:each) do |
||||
@deck = double(Squib::Deck) |
||||
@context = double(Cairo::Context) |
||||
@svg = double(RSVG::Handle) |
||||
allow(Cairo::Context).to receive(:new).and_return(@context) |
||||
allow(Cairo::ImageSurface).to receive(:from_png).and_return(nil) |
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(nil) |
||||
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg) |
||||
end |
||||
|
||||
context '#png' do |
||||
it 'makes all the expected calls on a smoke test' do |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:translate).with(-37, -38).once |
||||
expect(@context).to receive(:rotate).with(0.0).once |
||||
expect(@context).to receive(:translate).with(37, 38).once |
||||
expect(@context).to receive(:set_source).with(nil, 37, 38).once |
||||
expect(@context).to receive(:paint).with(0.9).once |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
# png(file, x, y, alpha, blend, angle) |
||||
card.png('foo.png', 37, 38, 0.9, :none, 0.0) |
||||
end |
||||
|
||||
it 'sets blend when needed' do |
||||
@context.as_null_object |
||||
expect(@context).to receive(:operator=).with(:overlay).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
card.png('foo.png', 37, 38, 0.9, :overlay, 0.0) |
||||
end |
||||
end |
||||
|
||||
context '#svg' 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(:height).and_return(100).twice |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:translate).with(-37, -38).once |
||||
expect(@context).to receive(:rotate).with(0.0).once |
||||
expect(@context).to receive(:translate).with(37, 38).once |
||||
expect(@context).to receive(:scale).with(1.0, 1.0).once |
||||
expect(@context).to receive(:render_rsvg_handle).with(@svg, 'id').once |
||||
expect(@context).to receive(:set_source).with(nil, 37, 38).once |
||||
expect(@context).to receive(:paint).with(0.9).once |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
# svg(file, id, x, y, width, height, alpha, blend, angle) |
||||
card.svg('foo.png', 'id', 37, 38, :native, :native, 0.9, :none, 0.0) |
||||
end |
||||
|
||||
it 'sets blend when needed' do |
||||
@context.as_null_object |
||||
@svg.as_null_object |
||||
expect(@context).to receive(:operator=).with(:overlay).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
card.svg('foo.png', nil, 37, 38, :native, :native, 0.9, :overlay, 0.0) |
||||
end |
||||
|
||||
it 'sets width & height when needed' do |
||||
@context.as_null_object |
||||
expect(@svg).to receive(:width).and_return(100).once |
||||
expect(@svg).to receive(:height).and_return(100).once |
||||
expect(@context).to receive(:scale).with(2.0, 3.0).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
card.svg('foo.png', nil, 37, 38, 200, 300, 0.9, :none, 0.0) |
||||
end |
||||
end |
||||
|
||||
end |
||||
Loading…
Reference in new issue