3 changed files with 145 additions and 2 deletions
@ -0,0 +1,66 @@
|
||||
require 'spec_helper' |
||||
require 'squib' |
||||
|
||||
describe Squib::Deck, '#save_pdf' do |
||||
|
||||
def expect_card_place(x, y) |
||||
expect(@context).to receive(:set_source) |
||||
.with(instance_of(Cairo::ImageSurface), -37, -37) |
||||
.once # trim the card |
||||
expect(@context).to receive(:paint).once # paint trimmed card |
||||
expect(@context).to receive(:set_source) # place the card |
||||
.with(instance_of(Cairo::ImageSurface), x, y).once |
||||
expect(@context).to receive(:paint).once # paint placed card |
||||
end |
||||
|
||||
context 'typical inputs' do |
||||
|
||||
before(:each) do |
||||
@context = double(Cairo::Context) |
||||
allow(Cairo::PDFSurface).to receive(:new).and_return(nil) #don't create the file |
||||
end |
||||
|
||||
it 'make all the expected calls on a smoke test' do |
||||
num_cards = 9 |
||||
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 } |
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125) |
||||
mock_squib_logger(@old_logger) do |
||||
expect(Squib.logger).to receive(:debug).thrice |
||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(num_cards + 1).times |
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir |
||||
|
||||
expect_card_place(75, 75) |
||||
expect_card_place(831, 75) |
||||
expect_card_place(1587, 75) |
||||
expect_card_place(2343, 75) |
||||
expect_card_place(75, 1131) |
||||
expect_card_place(831, 1131) |
||||
expect_card_place(1587, 1131) |
||||
expect_card_place(2343, 1131) |
||||
expect(@context).to receive(:show_page).once |
||||
expect_card_place(75, 75) |
||||
|
||||
deck.save_pdf(args) |
||||
end |
||||
end |
||||
|
||||
it 'only does the three cards on a limited range' do |
||||
num_cards = 9 |
||||
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 } |
||||
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125) |
||||
mock_squib_logger(@old_logger) do |
||||
expect(Squib.logger).to receive(:debug).thrice |
||||
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times |
||||
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir |
||||
|
||||
expect_card_place(75, 75) |
||||
expect_card_place(831, 75) |
||||
expect_card_place(1587, 75) |
||||
|
||||
deck.save_pdf(args) |
||||
end |
||||
end |
||||
|
||||
end |
||||
|
||||
end |
||||
@ -0,0 +1,74 @@
|
||||
require 'spec_helper' |
||||
require 'squib' |
||||
|
||||
describe Squib::Card do |
||||
|
||||
def expect_stroke(fill_color, stroke_color, stroke_width) |
||||
expect(@context).to receive(:set_source_color).with(stroke_color).once |
||||
expect(@context).to receive(:set_line_width).with(stroke_width).once |
||||
expect(@context).to receive(:stroke).once |
||||
expect(@context).to receive(:set_source_color).with(fill_color).once |
||||
expect(@context).to receive(:fill).once |
||||
end |
||||
|
||||
before(:each) do |
||||
@deck = double(Squib::Deck) |
||||
@context = double(Cairo::Context) |
||||
allow(Cairo::Context).to receive(:new).and_return(@context) |
||||
end |
||||
|
||||
context 'rect' do |
||||
it 'make all the expected calls on a smoke test' do |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:rounded_rectangle).with(37, 38, 50, 100, 10, 15).twice |
||||
expect_stroke('#fff', '#f00', 2.0) |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
# rect(x, y, width, height, x_radius, y_radius, |
||||
# fill_color, stroke_color, stroke_width) |
||||
card.rect(37, 38, 50, 100, 10, 15, '#fff', '#f00', 2.0) |
||||
end |
||||
end |
||||
|
||||
context 'circle' do |
||||
it 'make all the expected calls on a smoke test' do |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:circle).with(37, 38, 100).twice |
||||
expect_stroke('#fff', '#f00', 2.0) |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
# circle(x, y, radius, |
||||
# fill_color, stroke_color, stroke_width) |
||||
card.circle(37, 38, 100, '#fff', '#f00', 2.0) |
||||
end |
||||
end |
||||
|
||||
context 'triangle' do |
||||
it 'make all the expected calls on a smoke test' do |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:triangle).with(1, 2, 3, 4, 5, 6).twice |
||||
expect_stroke('#fff', '#f00', 2.0) |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
card.triangle(1, 2, 3, 4, 5, 6, '#fff', '#f00', 2.0) |
||||
end |
||||
end |
||||
|
||||
context 'line' do |
||||
it 'make all the expected calls on a smoke test' do |
||||
expect(@context).to receive(:save).once |
||||
expect(@context).to receive(:move_to).with(1, 2).once |
||||
expect(@context).to receive(:line_to).with(3, 4).once |
||||
expect(@context).to receive(:set_source_color).with('#fff').once |
||||
expect(@context).to receive(:set_line_width).with(2.0).once |
||||
expect(@context).to receive(:stroke).once |
||||
expect(@context).to receive(:restore).once |
||||
|
||||
card = Squib::Card.new(@deck, 100, 150) |
||||
card.line(1, 2, 3, 4, '#fff', 2.0) |
||||
end |
||||
end |
||||
end |
||||
Loading…
Reference in new issue