Upgrading rspec, fixing mock objects bug

This commit is contained in:
Andy Meneely
2015-02-13 13:26:22 -05:00
parent d2543473c7
commit 578c3cb6a0
17 changed files with 173 additions and 157 deletions
+40 -39
View File
@@ -4,50 +4,51 @@ require 'squib'
describe Squib::Card, '#text' do
context 'typical inputs' do
let(:deck) { double(Squib::Deck) }
let(:context) { double(Cairo::Context) }
let(:layout) { double(Pango::Layout) }
let(:font_desc) { double(Pango::FontDescription) }
before(:each) do
@deck = double(Squib::Deck)
@context = double(Cairo::Context)
@layout = double(Pango::Layout)
allow(Cairo::Context).to receive(:new).and_return(@context)
allow(Cairo::Context).to receive(:new).and_return(context)
end
it 'make all the expected calls on a smoke test' do
mock_squib_logger(@old_logger) do
extent = Pango::Rectangle.new(50,60,100,200)
expect(Squib.logger).to receive(:debug).once
expect(@context).to receive(:save).once
expect(@context).to receive(:set_source_color).once
expect(@context).to receive(:move_to).with(10, 15).once
expect(@context).to receive(:translate).with(-10, -15).once
expect(@context).to receive(:rotate).with(0.0).once
expect(@context).to receive(:translate).with(10, 15).once
expect(@context).to receive(:create_pango_layout).once.and_return(@layout)
expect(@layout).to receive(:font_description=).with(Pango::FontDescription.new('Sans 12')).once
expect(@layout).to receive(:text=).with('foo').once
expect(@layout).to receive(:width=).with(20 * Pango::SCALE).once
expect(@layout).to receive(:height=).with(25 * Pango::SCALE).once
expect(@layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_NONE).once
expect(@layout).to receive(:alignment=).with(Pango::Layout::ALIGN_LEFT).once
expect(@layout).to receive(:justify=).with(false).once
expect(@layout).to receive(:spacing=).with(1.0 * Pango::SCALE).once
expect(@context).to receive(:update_pango_layout).once
expect(@layout).to receive(:height).once.and_return(25)
expect(@layout).to receive(:extents).thrice.and_return([nil,extent])
expect(@context).to receive(:update_pango_layout).once
expect(@context).to receive(:show_pango_layout).once
expect(@context).to receive(:restore).once
extent = Pango::Rectangle.new(50,60,100,200)
expect(Squib.logger).to receive(:debug).once
expect(context).to receive(:save).once
expect(context).to receive(:set_source_color).once
expect(context).to receive(:move_to).with(10, 15).once
expect(context).to receive(:translate).with(-10, -15).once
expect(context).to receive(:rotate).with(0.0).once
expect(context).to receive(:translate).with(10, 15).once
expect(context).to receive(:create_pango_layout).once.and_return(layout)
expect(Pango::FontDescription).to receive(:new).with('Sans 12').and_return(font_desc)
expect(layout ).to receive(:font_description=).with(font_desc).once
expect(layout ).to receive(:text=).with('foo').once
expect(layout ).to receive(:width=).with(20 * Pango::SCALE).once
expect(layout ).to receive(:height=).with(25 * Pango::SCALE).once
expect(layout ).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_NONE).once
expect(layout ).to receive(:alignment=).with(Pango::Layout::ALIGN_LEFT).once
expect(layout ).to receive(:justify=).with(false).once
expect(layout ).to receive(:spacing=).with(1.0 * Pango::SCALE).once
expect(context).to receive(:update_pango_layout).once
expect(layout ).to receive(:height).once.and_return(25)
expect(layout ).to receive(:extents).thrice.and_return([nil,extent])
expect(context).to receive(:update_pango_layout).once
expect(context).to receive(:show_pango_layout).once
expect(context).to receive(:restore).once
card = Squib::Card.new(@deck, 100, 150)
# text(str, font, font_size, color,
# x, y, width, height,
# markup, justify, wrap, ellipsize,
# spacing, align, valign, hint, angle)
ret = card.text('foo', 'Sans 12', nil, '#abc',
10, 15, 20, 25,
nil, false, false, false,
1.0, :left, :top, nil, 0.0)
expect(ret).to eq({width: 0, height: 0})
end
card = Squib::Card.new(@deck, 100, 150)
# text(str, font, font_size, color,
# x, y, width, height,
# markup, justify, wrap, ellipsize,
# spacing, align, valign, hint, angle)
ret = card.text('foo', 'Sans 12', nil, '#abc',
10, 15, 20, 25,
nil, false, false, false,
1.0, :left, :top, nil, 0.0)
expect(ret).to eq({width: 0, height: 0})
end
end