|
|
|
|
@ -11,6 +11,9 @@ describe Squib::Card, '#text' do
|
|
|
|
|
|
|
|
|
|
before(:each) do |
|
|
|
|
allow(Cairo::Context).to receive(:new).and_return(context) |
|
|
|
|
allow(deck).to receive(:dir).and_return('_output') |
|
|
|
|
allow(deck).to receive(:count_format).and_return('%02d') |
|
|
|
|
allow(deck).to receive(:prefix).and_return('card_') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'make all the expected calls on a smoke test' do |
|
|
|
|
@ -39,7 +42,7 @@ describe Squib::Card, '#text' do
|
|
|
|
|
expect(context).to receive(:show_pango_layout).once |
|
|
|
|
expect(context).to receive(:restore).once |
|
|
|
|
|
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
# text(str, font, font_size, color, |
|
|
|
|
# x, y, width, height, |
|
|
|
|
# markup, justify, wrap, ellipsize, |
|
|
|
|
@ -53,18 +56,22 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'convenience lookups' do |
|
|
|
|
let(:deck) { double(Squib::Deck) } |
|
|
|
|
let(:context) { double(Cairo::Context).as_null_object } |
|
|
|
|
let(:layout) { double(Pango::Layout).as_null_object } |
|
|
|
|
let(:extents) { double("extents") } |
|
|
|
|
|
|
|
|
|
before(:each) do |
|
|
|
|
@deck = double(Squib::Deck) |
|
|
|
|
@context = double(Cairo::Context).as_null_object |
|
|
|
|
@layout = double(Pango::Layout).as_null_object |
|
|
|
|
@extents = double("extents") |
|
|
|
|
allow(Cairo::Context).to receive(:new).and_return(@context) |
|
|
|
|
expect(@context).to receive(:create_pango_layout).once.and_return(@layout) |
|
|
|
|
allow(Cairo::Context).to receive(:new).and_return(context) |
|
|
|
|
expect(context).to receive(:create_pango_layout).once.and_return(layout) |
|
|
|
|
allow(deck).to receive(:dir).and_return('_output') |
|
|
|
|
allow(deck).to receive(:count_format).and_return('%02d') |
|
|
|
|
allow(deck).to receive(:prefix).and_return('card_') |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'aligns right with strings' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, false, false, |
|
|
|
|
@ -72,8 +79,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'aligns center with strings' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, false, false, |
|
|
|
|
@ -81,8 +88,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets wrap to char with string char' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, 'char', false, |
|
|
|
|
@ -90,8 +97,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets wrap to word with word string' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, 'word', false, |
|
|
|
|
@ -99,8 +106,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets wrap to word_char with symbol word_char' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, :word_char, false, |
|
|
|
|
@ -108,8 +115,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets wrap to word_char with true' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, true, false, |
|
|
|
|
@ -117,8 +124,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets ellipsize to start properly' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, true, :start, |
|
|
|
|
@ -126,8 +133,8 @@ describe Squib::Card, '#text' do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'sets ellipsize to middle properly' do |
|
|
|
|
card = Squib::Card.new(@deck, 100, 150) |
|
|
|
|
expect(@layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once |
|
|
|
|
card = Squib::Card.new(deck, 100, 150) |
|
|
|
|
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once |
|
|
|
|
card.text('foo', 'Sans 12', nil, '#abc', |
|
|
|
|
10, 15, 20, 50, |
|
|
|
|
nil, false, true, 'middle', |
|
|
|
|
|