Skip to content

Commit 01c4bda

Browse files
committed
Minor spec improvements
1 parent 8830c49 commit 01c4bda

12 files changed

Lines changed: 240 additions & 218 deletions

File tree

spec/units/blocks_spec.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

spec/units/misc_spec.rb

Lines changed: 0 additions & 164 deletions
This file was deleted.

spec/units/prawn_html/tags/b_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,34 @@
1414
expect(b.styles).to match(color: 'ffbb11', styles: [:bold])
1515
end
1616
end
17+
18+
describe 'tag rendering' do
19+
include_context 'with pdf wrapper'
20+
21+
before { append_html_to_pdf(html) }
22+
23+
context 'with a B tag' do
24+
let(:html) { '<b>Some sample content</b>' }
25+
26+
it 'sends the expected buffer elements to the pdf' do
27+
expect(pdf).to have_received(:puts).with(
28+
[{ size: TestUtils.default_font_size, styles: [:bold], text: "Some sample content" }],
29+
{ leading: TestUtils.adjust_leading },
30+
{ bounding_box: nil, left_indent: 0 }
31+
)
32+
end
33+
end
34+
35+
context 'with a Strong tag' do
36+
let(:html) { '<strong>Some sample content</strong>' }
37+
38+
it 'sends the expected buffer elements to the pdf' do
39+
expect(pdf).to have_received(:puts).with(
40+
[{ size: TestUtils.default_font_size, styles: [:bold], text: "Some sample content" }],
41+
{ leading: TestUtils.adjust_leading },
42+
{ bounding_box: nil, left_indent: 0 }
43+
)
44+
end
45+
end
46+
end
1747
end

spec/units/prawn_html/tags/del_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,34 @@
1616
expect(styles).to match(color: 'ffbb11', callback: ['StrikeThrough', nil])
1717
end
1818
end
19+
20+
describe 'tag rendering' do
21+
include_context 'with pdf wrapper'
22+
23+
before { append_html_to_pdf(html) }
24+
25+
context 'with a Del tag' do
26+
let(:html) { '<del>Some sample content</del>' }
27+
28+
it 'sends the expected buffer elements to the pdf' do
29+
expect(pdf).to have_received(:puts).with(
30+
[{ callback: anything, size: TestUtils.default_font_size, text: "Some sample content" }],
31+
{ leading: TestUtils.adjust_leading },
32+
{ bounding_box: nil, left_indent: 0 }
33+
)
34+
end
35+
end
36+
37+
context 'with a S tag' do
38+
let(:html) { '<s>Some sample content</s>' }
39+
40+
it 'sends the expected buffer elements to the pdf' do
41+
expect(pdf).to have_received(:puts).with(
42+
[{ callback: anything, size: TestUtils.default_font_size, text: "Some sample content" }],
43+
{ leading: TestUtils.adjust_leading },
44+
{ bounding_box: nil, left_indent: 0 }
45+
)
46+
end
47+
end
48+
end
1949
end

spec/units/prawn_html/tags/div_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,20 @@
1010

1111
it { is_expected.to be_truthy }
1212
end
13+
14+
describe 'tag rendering' do
15+
include_context 'with pdf wrapper'
16+
17+
let(:html) { '<div>Some sample content</div>' }
18+
19+
before { append_html_to_pdf(html) }
20+
21+
it 'sends the expected buffer elements to the pdf' do
22+
expect(pdf).to have_received(:puts).with(
23+
[{ size: TestUtils.default_font_size, text: "Some sample content" }],
24+
{ leading: TestUtils.adjust_leading },
25+
{ bounding_box: nil, left_indent: 0 }
26+
)
27+
end
28+
end
1329
end

spec/units/prawn_html/tags/hr_spec.rb

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@
77

88
it { expect(described_class).to be < PrawnHtml::Tag }
99

10-
context 'without attributes' do
11-
before do
12-
hr.process_styles
13-
end
14-
15-
it 'returns the expected styles for hr tag' do
16-
expected_styles = {
17-
color: 'ffbb11',
18-
margin_bottom: PrawnHtml::Utils.convert_size(described_class::MARGIN_BOTTOM.to_s),
19-
margin_top: PrawnHtml::Utils.convert_size(described_class::MARGIN_TOP.to_s)
20-
}
21-
expect(hr.styles).to match(expected_styles)
22-
end
23-
end
24-
2510
describe '#block?' do
2611
subject(:block?) { hr.block? }
2712

@@ -69,4 +54,40 @@
6954
end
7055
end
7156
end
57+
58+
context 'without attributes' do
59+
before do
60+
hr.process_styles
61+
end
62+
63+
it 'returns the expected styles for hr tag' do
64+
expected_styles = {
65+
color: 'ffbb11',
66+
margin_bottom: PrawnHtml::Utils.convert_size(described_class::MARGIN_BOTTOM.to_s),
67+
margin_top: PrawnHtml::Utils.convert_size(described_class::MARGIN_TOP.to_s)
68+
}
69+
expect(hr.styles).to match(expected_styles)
70+
end
71+
end
72+
73+
describe 'tag rendering' do
74+
include_context 'with pdf wrapper'
75+
76+
let(:html) { 'Some content<hr>More content' }
77+
78+
before { append_html_to_pdf(html) }
79+
80+
it 'sends the expected buffer elements to the pdf', :aggregate_failures do
81+
expect(pdf).to have_received(:puts).with(
82+
[{ size: TestUtils.default_font_size, text: "Some content" }],
83+
{ leading: TestUtils.adjust_leading },
84+
{ bounding_box: nil, left_indent: 0 }
85+
)
86+
expect(pdf).to have_received(:puts).with(
87+
[{ size: TestUtils.default_font_size, text: "More content" }],
88+
{ leading: TestUtils.adjust_leading },
89+
{ bounding_box: nil, left_indent: 0 }
90+
)
91+
end
92+
end
7293
end

spec/units/prawn_html/tags/i_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,34 @@
1414
expect(i.styles).to match(color: 'ffbb11', styles: [:italic])
1515
end
1616
end
17+
18+
describe 'tag rendering' do
19+
include_context 'with pdf wrapper'
20+
21+
before { append_html_to_pdf(html) }
22+
23+
context 'with an I tag' do
24+
let(:html) { '<i>Some sample content</i>' }
25+
26+
it 'sends the expected buffer elements to the pdf' do
27+
expect(pdf).to have_received(:puts).with(
28+
[{ size: TestUtils.default_font_size, styles: [:italic], text: "Some sample content" }],
29+
{ leading: TestUtils.adjust_leading },
30+
{ bounding_box: nil, left_indent: 0 }
31+
)
32+
end
33+
end
34+
35+
context 'with an Em tag' do
36+
let(:html) { '<em>Some sample content</em>' }
37+
38+
it 'sends the expected buffer elements to the pdf' do
39+
expect(pdf).to have_received(:puts).with(
40+
[{ size: TestUtils.default_font_size, styles: [:italic], text: "Some sample content" }],
41+
{ leading: TestUtils.adjust_leading },
42+
{ bounding_box: nil, left_indent: 0 }
43+
)
44+
end
45+
end
46+
end
1747
end

0 commit comments

Comments
 (0)