squib 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +11 -1
- data/README.md +24 -4
- data/Rakefile +2 -0
- data/benchmarks/antialias_best.rb +13 -0
- data/benchmarks/antialias_best.yml +1 -0
- data/benchmarks/antialias_fast.rb +13 -0
- data/benchmarks/antialias_fast.yml +1 -0
- data/benchmarks/backend-memory.rb +14 -0
- data/benchmarks/backend-svg.rb +14 -0
- data/benchmarks/backend-svg.yml +4 -0
- data/lib/squib/api/image.rb +2 -2
- data/lib/squib/api/save.rb +3 -3
- data/lib/squib/card.rb +23 -4
- data/lib/squib/constants.rb +14 -4
- data/lib/squib/deck.rb +24 -11
- data/lib/squib/graphics/cairo_context_wrapper.rb +2 -1
- data/lib/squib/graphics/image.rb +13 -12
- data/lib/squib/graphics/save_doc.rb +37 -18
- data/lib/squib/graphics/shapes.rb +1 -0
- data/lib/squib/project_template/config.yml +8 -1
- data/lib/squib/version.rb +1 -1
- data/samples/backend-config.yml +5 -0
- data/samples/backend.rb +33 -0
- data/samples/glass-heart.svg +52 -52
- data/samples/load_images.rb +3 -3
- data/spec/data/samples/autoscale_font.rb.txt +9 -3
- data/spec/data/samples/basic.rb.txt +12 -15
- data/spec/data/samples/cairo_access.rb.txt +2 -0
- data/spec/data/samples/csv_import.rb.txt +8 -6
- data/spec/data/samples/custom_config.rb.txt +10 -7
- data/spec/data/samples/draw_shapes.rb.txt +2 -0
- data/spec/data/samples/excel.rb.txt +12 -9
- data/spec/data/samples/gradients.rb.txt +3 -1
- data/spec/data/samples/hello_world.rb.txt +4 -2
- data/spec/data/samples/load_images.rb.txt +19 -38
- data/spec/data/samples/portrait-landscape.rb.txt +4 -2
- data/spec/data/samples/ranges.rb.txt +27 -24
- data/spec/data/samples/saves.rb.txt +161 -84
- data/spec/data/samples/showcase.rb.txt +13 -21
- data/spec/data/samples/text_options.rb.txt +48 -39
- data/spec/data/samples/tgc_proofs.rb.txt +5 -7
- data/spec/data/samples/units.rb.txt +1 -0
- data/spec/deck_spec.rb +1 -1
- data/spec/graphics/graphics_images_spec.rb +7 -3
- data/spec/graphics/graphics_save_doc_spec.rb +36 -39
- data/spec/graphics/graphics_shapes_spec.rb +9 -0
- data/spec/graphics/graphics_text_spec.rb +73 -62
- data/spec/input_helpers_spec.rb +27 -10
- data/spec/spec_helper.rb +12 -9
- data/squib.gemspec +2 -2
- metadata +27 -17
data/spec/deck_spec.rb
CHANGED
@@ -12,10 +12,16 @@ describe Squib::Card do
|
|
12
12
|
allow(Cairo::ImageSurface).to receive(:from_png).and_return(@png)
|
13
13
|
allow(Cairo::ImageSurface).to receive(:new).and_return(@png)
|
14
14
|
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
|
15
|
+
allow(@deck).to receive(:dir).and_return('_output')
|
16
|
+
allow(@deck).to receive(:count_format).and_return('%02d')
|
17
|
+
allow(@deck).to receive(:prefix).and_return('card_')
|
18
|
+
allow(@deck).to receive(:antialias).and_return('best')
|
19
|
+
|
15
20
|
end
|
16
21
|
|
17
22
|
context '#png' do
|
18
23
|
it 'makes all the expected calls on a smoke test' do
|
24
|
+
expect(@context).to receive(:antialias=).with('subpixel')
|
19
25
|
expect(@context).to receive(:save).once
|
20
26
|
expect(@context).to receive(:translate).with(-37, -38).once
|
21
27
|
expect(@context).to receive(:rotate).with(0.0).once
|
@@ -42,14 +48,12 @@ describe Squib::Card do
|
|
42
48
|
it 'makes all the expected calls on a smoke test' do
|
43
49
|
expect(@svg).to receive(:width).and_return(100).twice
|
44
50
|
expect(@svg).to receive(:height).and_return(100).twice
|
51
|
+
expect(@context).to receive(:antialias=).with('subpixel').once
|
45
52
|
expect(@context).to receive(:save).once
|
46
|
-
expect(@context).to receive(:translate).with(-37, -38).once
|
47
53
|
expect(@context).to receive(:rotate).with(0.0).once
|
48
54
|
expect(@context).to receive(:translate).with(37, 38).once
|
49
55
|
expect(@context).to receive(:scale).with(1.0, 1.0).once
|
50
56
|
expect(@context).to receive(:render_rsvg_handle).with(@svg, 'id').once
|
51
|
-
expect(@context).to receive(:set_source).with(@png, 37, 38).once
|
52
|
-
expect(@context).to receive(:paint).with(0.9).once
|
53
57
|
expect(@context).to receive(:restore).once
|
54
58
|
|
55
59
|
card = Squib::Card.new(@deck, 100, 150)
|
@@ -3,62 +3,59 @@ require 'squib'
|
|
3
3
|
|
4
4
|
describe Squib::Deck, '#save_pdf' do
|
5
5
|
|
6
|
-
def expect_card_place(x, y)
|
7
|
-
expect(@context).to receive(:set_source)
|
8
|
-
.with(instance_of(Cairo::ImageSurface), -37, -37)
|
9
|
-
.once # trim the card
|
10
|
-
expect(@context).to receive(:paint).once # paint trimmed card
|
11
|
-
expect(@context).to receive(:set_source) # place the card
|
12
|
-
.with(instance_of(Cairo::ImageSurface), x, y).once
|
13
|
-
expect(@context).to receive(:paint).once # paint placed card
|
14
|
-
end
|
15
|
-
|
16
6
|
context 'typical inputs' do
|
7
|
+
let(:cxt) { double(Cairo::Context) }
|
8
|
+
|
9
|
+
def expect_card_place(x, y)
|
10
|
+
expect(cxt).to receive(:translate).with(x, y).once
|
11
|
+
expect(cxt).to receive(:rectangle).once
|
12
|
+
expect(cxt).to receive(:clip).once
|
13
|
+
expect(cxt).to receive(:set_source) # place the card
|
14
|
+
.with(instance_of(Cairo::ImageSurface), 0, 0).once
|
15
|
+
expect(cxt).to receive(:paint).once # paint placed card
|
16
|
+
expect(cxt).to receive(:translate).with(-x,-y).once
|
17
|
+
expect(cxt).to receive(:reset_clip).once
|
18
|
+
end
|
17
19
|
|
18
20
|
before(:each) do
|
19
|
-
@context = double(Cairo::Context)
|
20
21
|
allow(Cairo::PDFSurface).to receive(:new).and_return(nil) #don't create the file
|
22
|
+
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
23
|
+
allow(cxt).to receive(:antialias=)
|
21
24
|
end
|
22
25
|
|
23
26
|
it 'make all the expected calls on a smoke test' do
|
24
27
|
num_cards = 9
|
25
|
-
|
26
|
-
deck
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
expect_card_place(2343, 1131)
|
40
|
-
expect(@context).to receive(:show_page).once
|
41
|
-
expect_card_place(75, 75)
|
28
|
+
deck = Squib::Deck.new(cards: 9, width: 825, height: 1125)
|
29
|
+
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
30
|
+
expect(Squib.logger).to receive(:debug).at_least(:once)
|
31
|
+
|
32
|
+
expect_card_place(75, 75)
|
33
|
+
expect_card_place(831, 75)
|
34
|
+
expect_card_place(1587, 75)
|
35
|
+
expect_card_place(2343, 75)
|
36
|
+
expect_card_place(75, 1131)
|
37
|
+
expect_card_place(831, 1131)
|
38
|
+
expect_card_place(1587, 1131)
|
39
|
+
expect_card_place(2343, 1131)
|
40
|
+
expect(cxt).to receive(:show_page).once
|
41
|
+
expect_card_place(75, 75)
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
44
|
+
deck.save_pdf(args)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'only does the three cards on a limited range' do
|
48
48
|
num_cards = 9
|
49
49
|
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
50
50
|
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
51
|
-
|
52
|
-
|
53
|
-
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times
|
54
|
-
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
51
|
+
expect(Squib.logger).to receive(:debug).at_least(:once)
|
52
|
+
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
expect_card_place(75, 75)
|
55
|
+
expect_card_place(831, 75)
|
56
|
+
expect_card_place(1587, 75)
|
59
57
|
|
60
|
-
|
61
|
-
end
|
58
|
+
deck.save_pdf(args)
|
62
59
|
end
|
63
60
|
|
64
61
|
end
|
@@ -15,10 +15,15 @@ describe Squib::Card do
|
|
15
15
|
@deck = double(Squib::Deck)
|
16
16
|
@context = double(Cairo::Context)
|
17
17
|
allow(Cairo::Context).to receive(:new).and_return(@context)
|
18
|
+
allow(@deck).to receive(:dir).and_return('_output')
|
19
|
+
allow(@deck).to receive(:count_format).and_return('%02d')
|
20
|
+
allow(@deck).to receive(:prefix).and_return('card_')
|
21
|
+
allow(@deck).to receive(:antialias).and_return('best')
|
18
22
|
end
|
19
23
|
|
20
24
|
context 'rect' do
|
21
25
|
it 'make all the expected calls on a smoke test' do
|
26
|
+
expect(@context).to receive(:antialias=).with('subpixel')
|
22
27
|
expect(@context).to receive(:save).once
|
23
28
|
expect(@context).to receive(:rounded_rectangle).with(37, 38, 50, 100, 10, 15).twice
|
24
29
|
expect_stroke('#fff', '#f00', 2.0)
|
@@ -33,7 +38,9 @@ describe Squib::Card do
|
|
33
38
|
|
34
39
|
context 'circle' do
|
35
40
|
it 'make all the expected calls on a smoke test' do
|
41
|
+
expect(@context).to receive(:antialias=).with('subpixel')
|
36
42
|
expect(@context).to receive(:save).once
|
43
|
+
expect(@context).to receive(:move_to).with(137, 38)
|
37
44
|
expect(@context).to receive(:circle).with(37, 38, 100).twice
|
38
45
|
expect_stroke('#fff', '#f00', 2.0)
|
39
46
|
expect(@context).to receive(:restore).once
|
@@ -47,6 +54,7 @@ describe Squib::Card do
|
|
47
54
|
|
48
55
|
context 'triangle' do
|
49
56
|
it 'make all the expected calls on a smoke test' do
|
57
|
+
expect(@context).to receive(:antialias=).with('subpixel')
|
50
58
|
expect(@context).to receive(:save).once
|
51
59
|
expect(@context).to receive(:triangle).with(1, 2, 3, 4, 5, 6).twice
|
52
60
|
expect_stroke('#fff', '#f00', 2.0)
|
@@ -59,6 +67,7 @@ describe Squib::Card do
|
|
59
67
|
|
60
68
|
context 'line' do
|
61
69
|
it 'make all the expected calls on a smoke test' do
|
70
|
+
expect(@context).to receive(:antialias=).with('subpixel')
|
62
71
|
expect(@context).to receive(:save).once
|
63
72
|
expect(@context).to receive(:move_to).with(1, 2).once
|
64
73
|
expect(@context).to receive(:line_to).with(3, 4).once
|
@@ -4,66 +4,77 @@ require 'squib'
|
|
4
4
|
describe Squib::Card, '#text' do
|
5
5
|
|
6
6
|
context 'typical inputs' do
|
7
|
+
let(:deck) { double(Squib::Deck) }
|
8
|
+
let(:context) { double(Cairo::Context) }
|
9
|
+
let(:layout) { double(Pango::Layout) }
|
10
|
+
let(:font_desc) { double(Pango::FontDescription) }
|
11
|
+
|
7
12
|
before(:each) do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
allow(
|
13
|
+
allow(Cairo::Context).to receive(:new).and_return(context)
|
14
|
+
allow(deck).to receive(:dir).and_return('_output')
|
15
|
+
allow(deck).to receive(:count_format).and_return('%02d')
|
16
|
+
allow(deck).to receive(:prefix).and_return('card_')
|
17
|
+
allow(deck).to receive(:antialias).and_return('best')
|
12
18
|
end
|
13
19
|
|
14
20
|
it 'make all the expected calls on a smoke test' do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
21
|
+
extent = Pango::Rectangle.new(50,60,100,200)
|
22
|
+
expect(Squib.logger).to receive(:debug).once
|
23
|
+
expect(context).to receive(:antialias=).with('subpixel').once
|
24
|
+
expect(context).to receive(:save).once
|
25
|
+
expect(context).to receive(:set_source_color).once
|
26
|
+
expect(context).to receive(:move_to).with(10, 15).once
|
27
|
+
expect(context).to receive(:translate).with(-10, -15).once
|
28
|
+
expect(context).to receive(:rotate).with(0.0).once
|
29
|
+
expect(context).to receive(:translate).with(10, 15).once
|
30
|
+
expect(context).to receive(:create_pango_layout).once.and_return(layout)
|
31
|
+
expect(Pango::FontDescription).to receive(:new).with('Sans 12').and_return(font_desc)
|
32
|
+
expect(layout ).to receive(:font_description=).with(font_desc).once
|
33
|
+
expect(layout ).to receive(:text=).with('foo').once
|
34
|
+
expect(layout ).to receive(:width=).with(20 * Pango::SCALE).once
|
35
|
+
expect(layout ).to receive(:height=).with(25 * Pango::SCALE).once
|
36
|
+
expect(layout ).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_NONE).once
|
37
|
+
expect(layout ).to receive(:alignment=).with(Pango::Layout::ALIGN_LEFT).once
|
38
|
+
expect(layout ).to receive(:justify=).with(false).once
|
39
|
+
expect(layout ).to receive(:spacing=).with(1.0 * Pango::SCALE).once
|
40
|
+
expect(context).to receive(:update_pango_layout).once
|
41
|
+
expect(layout ).to receive(:height).once.and_return(25)
|
42
|
+
expect(layout ).to receive(:extents).thrice.and_return([nil,extent])
|
43
|
+
expect(context).to receive(:update_pango_layout).once
|
44
|
+
expect(context).to receive(:show_pango_layout).once
|
45
|
+
expect(context).to receive(:restore).once
|
46
|
+
|
47
|
+
card = Squib::Card.new(deck, 100, 150)
|
48
|
+
# text(str, font, font_size, color,
|
49
|
+
# x, y, width, height,
|
50
|
+
# markup, justify, wrap, ellipsize,
|
51
|
+
# spacing, align, valign, hint, angle)
|
52
|
+
ret = card.text('foo', 'Sans 12', nil, '#abc',
|
53
|
+
10, 15, 20, 25,
|
54
|
+
nil, false, false, false,
|
55
|
+
1.0, :left, :top, nil, 0.0)
|
56
|
+
expect(ret).to eq({width: 0, height: 0})
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
60
|
context 'convenience lookups' do
|
61
|
+
let(:deck) { double(Squib::Deck) }
|
62
|
+
let(:context) { double(Cairo::Context).as_null_object }
|
63
|
+
let(:layout) { double(Pango::Layout).as_null_object }
|
64
|
+
let(:extents) { double("extents") }
|
65
|
+
|
55
66
|
before(:each) do
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
allow(
|
61
|
-
|
67
|
+
allow(Cairo::Context).to receive(:new).and_return(context)
|
68
|
+
expect(context).to receive(:create_pango_layout).once.and_return(layout)
|
69
|
+
allow(deck).to receive(:dir).and_return('_output')
|
70
|
+
allow(deck).to receive(:count_format).and_return('%02d')
|
71
|
+
allow(deck).to receive(:prefix).and_return('card_')
|
72
|
+
allow(deck).to receive(:antialias).and_return('best')
|
62
73
|
end
|
63
74
|
|
64
75
|
it 'aligns right with strings' do
|
65
|
-
card = Squib::Card.new(
|
66
|
-
expect(
|
76
|
+
card = Squib::Card.new(deck, 100, 150)
|
77
|
+
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
|
67
78
|
card.text('foo', 'Sans 12', nil, '#abc',
|
68
79
|
10, 15, 20, 50,
|
69
80
|
nil, false, false, false,
|
@@ -71,8 +82,8 @@ describe Squib::Card, '#text' do
|
|
71
82
|
end
|
72
83
|
|
73
84
|
it 'aligns center with strings' do
|
74
|
-
card = Squib::Card.new(
|
75
|
-
expect(
|
85
|
+
card = Squib::Card.new(deck, 100, 150)
|
86
|
+
expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
|
76
87
|
card.text('foo', 'Sans 12', nil, '#abc',
|
77
88
|
10, 15, 20, 50,
|
78
89
|
nil, false, false, false,
|
@@ -80,8 +91,8 @@ describe Squib::Card, '#text' do
|
|
80
91
|
end
|
81
92
|
|
82
93
|
it 'sets wrap to char with string char' do
|
83
|
-
card = Squib::Card.new(
|
84
|
-
expect(
|
94
|
+
card = Squib::Card.new(deck, 100, 150)
|
95
|
+
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
|
85
96
|
card.text('foo', 'Sans 12', nil, '#abc',
|
86
97
|
10, 15, 20, 50,
|
87
98
|
nil, false, 'char', false,
|
@@ -89,8 +100,8 @@ describe Squib::Card, '#text' do
|
|
89
100
|
end
|
90
101
|
|
91
102
|
it 'sets wrap to word with word string' do
|
92
|
-
card = Squib::Card.new(
|
93
|
-
expect(
|
103
|
+
card = Squib::Card.new(deck, 100, 150)
|
104
|
+
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
|
94
105
|
card.text('foo', 'Sans 12', nil, '#abc',
|
95
106
|
10, 15, 20, 50,
|
96
107
|
nil, false, 'word', false,
|
@@ -98,8 +109,8 @@ describe Squib::Card, '#text' do
|
|
98
109
|
end
|
99
110
|
|
100
111
|
it 'sets wrap to word_char with symbol word_char' do
|
101
|
-
card = Squib::Card.new(
|
102
|
-
expect(
|
112
|
+
card = Squib::Card.new(deck, 100, 150)
|
113
|
+
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
103
114
|
card.text('foo', 'Sans 12', nil, '#abc',
|
104
115
|
10, 15, 20, 50,
|
105
116
|
nil, false, :word_char, false,
|
@@ -107,8 +118,8 @@ describe Squib::Card, '#text' do
|
|
107
118
|
end
|
108
119
|
|
109
120
|
it 'sets wrap to word_char with true' do
|
110
|
-
card = Squib::Card.new(
|
111
|
-
expect(
|
121
|
+
card = Squib::Card.new(deck, 100, 150)
|
122
|
+
expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
|
112
123
|
card.text('foo', 'Sans 12', nil, '#abc',
|
113
124
|
10, 15, 20, 50,
|
114
125
|
nil, false, true, false,
|
@@ -116,8 +127,8 @@ describe Squib::Card, '#text' do
|
|
116
127
|
end
|
117
128
|
|
118
129
|
it 'sets ellipsize to start properly' do
|
119
|
-
card = Squib::Card.new(
|
120
|
-
expect(
|
130
|
+
card = Squib::Card.new(deck, 100, 150)
|
131
|
+
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
|
121
132
|
card.text('foo', 'Sans 12', nil, '#abc',
|
122
133
|
10, 15, 20, 50,
|
123
134
|
nil, false, true, :start,
|
@@ -125,8 +136,8 @@ describe Squib::Card, '#text' do
|
|
125
136
|
end
|
126
137
|
|
127
138
|
it 'sets ellipsize to middle properly' do
|
128
|
-
card = Squib::Card.new(
|
129
|
-
expect(
|
139
|
+
card = Squib::Card.new(deck, 100, 150)
|
140
|
+
expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
|
130
141
|
card.text('foo', 'Sans 12', nil, '#abc',
|
131
142
|
10, 15, 20, 50,
|
132
143
|
nil, false, true, 'middle',
|
data/spec/input_helpers_spec.rb
CHANGED
@@ -25,11 +25,9 @@ describe Squib::InputHelpers do
|
|
25
25
|
|
26
26
|
context '#layoutify' do
|
27
27
|
it 'warns on the logger when the layout does not exist' do
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
32
|
-
end
|
28
|
+
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
29
|
+
expect(Squib.logger).to receive(:debug)
|
30
|
+
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
33
31
|
end
|
34
32
|
|
35
33
|
it 'applies the layout in a normal situation' do
|
@@ -88,11 +86,9 @@ describe Squib::InputHelpers do
|
|
88
86
|
opts = {dir: 'tocreate'}
|
89
87
|
Dir.chdir(output_dir) do
|
90
88
|
FileUtils.rm_rf('tocreate', secure: true)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
expect(Dir.exists? 'tocreate').to be true
|
95
|
-
end
|
89
|
+
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
90
|
+
expect(@deck.send(:dirify, opts, :dir, true)).to eq(opts)
|
91
|
+
expect(Dir.exists? 'tocreate').to be true
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
@@ -218,4 +214,25 @@ describe Squib::InputHelpers do
|
|
218
214
|
end
|
219
215
|
end
|
220
216
|
|
217
|
+
context '#formatify' do
|
218
|
+
it 'sets format to nil when format is not set' do
|
219
|
+
opts = @deck.send(:formatify, {foo: true})
|
220
|
+
expect(opts).to eq({
|
221
|
+
foo: true,
|
222
|
+
format: [nil]
|
223
|
+
})
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'updates the format to array' do
|
227
|
+
opts = @deck.send(:formatify, {format: :png})
|
228
|
+
expect(opts).to eq({format: [:png]})
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'updates the format to flattened array' do
|
232
|
+
opts = @deck.send(:formatify, {format: [[:png]]})
|
233
|
+
expect(opts).to eq({format: [:png]})
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
221
238
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'coveralls'
|
3
|
+
require 'byebug'
|
3
4
|
|
4
5
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
6
|
SimpleCov::Formatter::HTMLFormatter,
|
@@ -57,6 +58,7 @@ def mock_cairo(strio)
|
|
57
58
|
cxt = double(Cairo::Context)
|
58
59
|
surface = double(Cairo::ImageSurface)
|
59
60
|
pango = double(Pango::Layout)
|
61
|
+
font = double(Pango::FontDescription)
|
60
62
|
allow(Squib.logger).to receive(:warn) {}
|
61
63
|
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
62
64
|
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
@@ -68,11 +70,14 @@ def mock_cairo(strio)
|
|
68
70
|
allow(pango).to receive(:height).and_return(25)
|
69
71
|
allow(pango).to receive(:width).and_return(25)
|
70
72
|
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0,0,0,0)]*2)
|
73
|
+
allow(Pango::FontDescription).to receive(:new).and_return(font)
|
74
|
+
allow(Cairo::PDFSurface).to receive(:new).and_return(nil)
|
71
75
|
|
72
76
|
%w(save set_source_color paint restore translate rotate move_to
|
73
77
|
update_pango_layout width height show_pango_layout rounded_rectangle
|
74
78
|
set_line_width stroke fill set_source scale render_rsvg_handle circle
|
75
|
-
triangle line_to operator= show_page clip transform mask
|
79
|
+
triangle line_to operator= show_page clip transform mask rectangle
|
80
|
+
reset_clip antialias=).each do |m|
|
76
81
|
allow(cxt).to receive(m) { |*args| strio << scrub_hex("cairo: #{m}(#{args})\n") }
|
77
82
|
end
|
78
83
|
|
@@ -81,9 +86,14 @@ def mock_cairo(strio)
|
|
81
86
|
allow(pango).to receive(m) {|*args| strio << scrub_hex("pango: #{m}(#{args})\n") }
|
82
87
|
end
|
83
88
|
|
89
|
+
%w(size=).each do |m|
|
90
|
+
allow(font).to receive(m) { |*args| strio << scrub_hex("pango font: #{m}(#{args})\n") }
|
91
|
+
end
|
92
|
+
|
84
93
|
%w(write_to_png).each do |m|
|
85
94
|
allow(surface).to receive(m) { |*args| strio << scrub_hex("surface: #{m}(#{args})\n") }
|
86
95
|
end
|
96
|
+
|
87
97
|
end
|
88
98
|
|
89
99
|
# Refine Squib to allow setting the logger and progress bar
|
@@ -91,20 +101,13 @@ module Squib
|
|
91
101
|
def logger=(l)
|
92
102
|
@logger = l
|
93
103
|
end
|
94
|
-
module_function
|
104
|
+
module_function :logger=
|
95
105
|
|
96
106
|
class Deck
|
97
107
|
attr_accessor :progress_bar
|
98
108
|
end
|
99
109
|
end
|
100
110
|
|
101
|
-
def mock_squib_logger(old_logger)
|
102
|
-
old_logger = Squib.logger
|
103
|
-
Squib.logger = instance_double(Logger)
|
104
|
-
yield
|
105
|
-
Squib.logger = old_logger
|
106
|
-
end
|
107
|
-
|
108
111
|
def output_dir
|
109
112
|
File.expand_path('../samples/_output', File.dirname(__FILE__))
|
110
113
|
end
|