Redesigning how config files are read, stored, and delegated
With the new design, we take the load off of deck.rb and simply delegate methods over to the new conf.rb. This means that things like `antialias` is now available as a method to the normal Squib scripts for easy checking (without being mutable). Squib::Conf also handles parsing and defaults, and any potential input validation we need to do in the future. Typographer is also set up now as a deck-wide configuration. This may change in the future if we want typography customization per-command, although that seems like a strange use case. Lots of tests for this one, and lots of cross-cutting concerns in this commit. This commit also includes some tweaks to rspec tests, including tagging of slow tests for a `rake spec_fastonly` Conflicts: spec/samples/samples_regression_spec.rb spec/spec_helper.rb squib.sublime-project
This commit is contained in:
@@ -3,80 +3,81 @@ require 'squib'
|
||||
|
||||
describe Squib::Card do
|
||||
|
||||
before(:example) do
|
||||
@deck = double(Squib::Deck)
|
||||
@context = double(Cairo::Context)
|
||||
@svg = double(RSVG::Handle)
|
||||
@png = double(Cairo::ImageSurface)
|
||||
allow(Cairo::Context).to receive(:new).and_return(@context)
|
||||
allow(Cairo::ImageSurface).to receive(:from_png).and_return(@png)
|
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(@png)
|
||||
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
|
||||
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_')
|
||||
allow(@deck).to receive(:antialias).and_return('best')
|
||||
let(:deck) { double(Squib::Deck) }
|
||||
let(:context) { double(Cairo::Context) }
|
||||
let(:svg) { double(RSVG::Handle) }
|
||||
let(:png) { double(Cairo::ImageSurface) }
|
||||
|
||||
before(:each) do
|
||||
allow(Cairo::Context).to receive(:new).and_return(context)
|
||||
allow(Cairo::ImageSurface).to receive(:from_png).and_return(png)
|
||||
allow(Cairo::ImageSurface).to receive(:new).and_return(png)
|
||||
allow(RSVG::Handle).to receive(:new_from_file).and_return(svg)
|
||||
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_')
|
||||
allow(deck).to receive(:antialias).and_return('subpixel')
|
||||
allow(deck).to receive(:backend).and_return('memory')
|
||||
end
|
||||
|
||||
context '#png' do
|
||||
it 'makes all the expected calls on a smoke test' do
|
||||
expect(@context).to receive(:antialias=).with('subpixel')
|
||||
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(@png, 37, 38).once
|
||||
expect(@context).to receive(:paint).with(0.9).once
|
||||
expect(@context).to receive(:restore).once
|
||||
expect(context).to receive(:antialias=).with('subpixel')
|
||||
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(png, 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)
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
# png(file, x, y, alpha, blend, angle)
|
||||
card.png('foo.png', 37, 38, :native, :native, 0.9, :none, 0.0, nil)
|
||||
end
|
||||
|
||||
it 'sets blend when needed' do
|
||||
@context.as_null_object
|
||||
expect(@context).to receive(:operator=).with(:overlay).once
|
||||
context.as_null_object
|
||||
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)
|
||||
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(:antialias=).with('subpixel').once
|
||||
expect(@context).to receive(:save).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(:restore).once
|
||||
expect(svg).to receive(:width).and_return(100).twice
|
||||
expect(svg).to receive(:height).and_return(100).twice
|
||||
expect(context).to receive(:antialias=).with('subpixel').once
|
||||
expect(context).to receive(:save).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(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
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, nil)
|
||||
end
|
||||
|
||||
it 'sets blend when needed' do
|
||||
@context.as_null_object
|
||||
@svg.as_null_object
|
||||
expect(@context).to receive(:operator=).with(:overlay).once
|
||||
context.as_null_object
|
||||
svg.as_null_object
|
||||
expect(context).to receive(:operator=).with(:overlay).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
card.svg('foo.png', nil, 37, 38, :native, :native, 0.9, :overlay, 0.0, nil)
|
||||
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
|
||||
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 = Squib::Card.new(deck, 100, 150)
|
||||
card.svg('foo.png', nil, 37, 38, 200, 300, 0.9, :none, 0.0, nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,33 +3,35 @@ 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
|
||||
let(:deck) { double(Squib::Deck) }
|
||||
let(:cxt) { double(Cairo::Context) }
|
||||
|
||||
def expect_stroke(cxt, fill_color, stroke_color, stroke_width)
|
||||
expect(cxt).to receive(:set_source_color).with(stroke_color).once
|
||||
expect(cxt).to receive(:set_line_width).with(stroke_width).once
|
||||
expect(cxt).to receive(:stroke).once
|
||||
expect(cxt).to receive(:set_source_color).with(fill_color).once
|
||||
expect(cxt).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)
|
||||
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_')
|
||||
allow(@deck).to receive(:antialias).and_return('best')
|
||||
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
||||
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_')
|
||||
allow(deck).to receive(:antialias).and_return('subpixel')
|
||||
allow(deck).to receive(:backend).and_return('memory')
|
||||
end
|
||||
|
||||
context 'rect' do
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
expect(@context).to receive(:antialias=).with('subpixel')
|
||||
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
|
||||
expect(cxt).to receive(:antialias=).with('subpixel')
|
||||
expect(cxt).to receive(:save).once
|
||||
expect(cxt).to receive(:rounded_rectangle).with(37, 38, 50, 100, 10, 15).twice
|
||||
expect_stroke(cxt, '#fff', '#f00', 2.0)
|
||||
expect(cxt).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
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)
|
||||
@@ -38,14 +40,14 @@ describe Squib::Card do
|
||||
|
||||
context 'circle' do
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
expect(@context).to receive(:antialias=).with('subpixel')
|
||||
expect(@context).to receive(:save).once
|
||||
expect(@context).to receive(:move_to).with(137, 38)
|
||||
expect(@context).to receive(:circle).with(37, 38, 100).twice
|
||||
expect_stroke('#fff', '#f00', 2.0)
|
||||
expect(@context).to receive(:restore).once
|
||||
expect(cxt).to receive(:antialias=).with('subpixel')
|
||||
expect(cxt).to receive(:save).once
|
||||
expect(cxt).to receive(:move_to).with(137, 38)
|
||||
expect(cxt).to receive(:circle).with(37, 38, 100).twice
|
||||
expect_stroke(cxt, '#fff', '#f00', 2.0)
|
||||
expect(cxt).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
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)
|
||||
@@ -54,29 +56,29 @@ describe Squib::Card do
|
||||
|
||||
context 'triangle' do
|
||||
it 'make all the expected calls on a smoke test' do
|
||||
expect(@context).to receive(:antialias=).with('subpixel')
|
||||
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
|
||||
expect(cxt).to receive(:antialias=).with('subpixel')
|
||||
expect(cxt).to receive(:save).once
|
||||
expect(cxt).to receive(:triangle).with(1, 2, 3, 4, 5, 6).twice
|
||||
expect_stroke(cxt, '#fff', '#f00', 2.0)
|
||||
expect(cxt).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
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(:antialias=).with('subpixel')
|
||||
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
|
||||
expect(cxt).to receive(:antialias=).with('subpixel')
|
||||
expect(cxt).to receive(:save).once
|
||||
expect(cxt).to receive(:move_to).with(1, 2).once
|
||||
expect(cxt).to receive(:line_to).with(3, 4).once
|
||||
expect(cxt).to receive(:set_source_color).with('#fff').once
|
||||
expect(cxt).to receive(:set_line_width).with(2.0).once
|
||||
expect(cxt).to receive(:stroke).once
|
||||
expect(cxt).to receive(:restore).once
|
||||
|
||||
card = Squib::Card.new(@deck, 100, 150)
|
||||
card = Squib::Card.new(deck, 100, 150)
|
||||
card.line(1, 2, 3, 4, '#fff', 2.0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,8 @@ describe Squib::Card, '#text' do
|
||||
allow(deck).to receive(:count_format).and_return('%02d')
|
||||
allow(deck).to receive(:prefix).and_return('card_')
|
||||
allow(deck).to receive(:antialias).and_return('best')
|
||||
allow(deck).to receive(:antialias).and_return('subpixel')
|
||||
allow(deck).to receive(:backend).and_return('memory')
|
||||
allow(layout).to receive(:context).and_return(pango_cxt)
|
||||
end
|
||||
|
||||
@@ -71,7 +73,8 @@ describe Squib::Card, '#text' do
|
||||
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_')
|
||||
allow(deck).to receive(:antialias).and_return('best')
|
||||
allow(deck).to receive(:antialias).and_return('subpixel')
|
||||
allow(deck).to receive(:backend).and_return('memory')
|
||||
end
|
||||
|
||||
it 'aligns right with strings' do
|
||||
|
||||
Reference in New Issue
Block a user