spec/prawn/text/box_spec.rb in prawn-2.2.2 vs spec/prawn/text/box_spec.rb in prawn-2.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'spec_helper' describe Prawn::Text::Box do let(:pdf) { create_pdf } @@ -54,12 +56,12 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings[0]).to eq('Hello world, how are you?') expect(text.strings[1]).to eq("I'm fine, thank you.") end - it 'should only require enough space for the descender and the ascender ' \ - 'when determining whether a line can fit' do + it 'only requires enough space for the descender and the ascender '\ + 'when determining whether a line can fit' do text = 'Oh hai text rect' options = { document: pdf, height: pdf.font.ascender + pdf.font.descender } @@ -108,12 +110,11 @@ expect(text_box.everything_printed?).to eq true end end describe '#line_gap' do - it 'should == the line gap of the font when using a single ' \ - 'font and font size' do + it '==S the line gap of the font when using a single font and font size' do string = "Hello world, how are you?\nI'm fine, thank you." text_box = described_class.new(string, document: pdf) text_box.render expect(text_box.line_gap).to be_within(0.0001).of(pdf.font.line_gap) end @@ -138,24 +139,24 @@ expect(contents.word_spacing).to be_empty end end describe '#height without leading' do - it 'should == the sum of the height of each line, ' \ - 'not including the space below the last line' do + it 'is the sum of the height of each line, not including the space below '\ + 'the last line' do text = "Oh hai text rect.\nOh hai text rect." options = { document: pdf } text_box = described_class.new(text, options) text_box.render expect(text_box.height).to be_within(0.001) .of(pdf.font.height * 2 - pdf.font.line_gap) end end describe '#height with leading' do - it 'should == the sum of the height of each line plus leading, ' \ - 'but not including the space below the last line' do + it 'is the sum of the height of each line plus leading, but not including '\ + 'the space below the last line' do text = "Oh hai text rect.\nOh hai text rect." leading = 12 options = { document: pdf, leading: leading } text_box = described_class.new(text, options) text_box.render @@ -325,11 +326,11 @@ width: width, height: height } end - context ':rotate_around option of :center' do + context 'with :rotate_around option of :center' do it 'draws content to the page rotated about the center of the text' do options[:rotate_around] = :center text_box = described_class.new(text, options) text_box.render @@ -354,11 +355,11 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings).to_not be_empty end end - context ':rotate_around option of :upper_left' do + context 'with :rotate_around option of :upper_left' do it 'draws content to the page rotated about the upper left corner of '\ 'the text' do options[:rotate_around] = :upper_left text_box = described_class.new(text, options) text_box.render @@ -382,11 +383,11 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings).to_not be_empty end end - context 'default :rotate_around' do + context 'with default :rotate_around' do it 'draws content to the page rotated about the upper left corner of '\ 'the text' do text_box = described_class.new(text, options) text_box.render @@ -409,11 +410,11 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings).to_not be_empty end end - context ':rotate_around option of :upper_right' do + context 'with :rotate_around option of :upper_right' do it 'draws content to the page rotated about the upper right corner of '\ 'the text' do options[:rotate_around] = :upper_right text_box = described_class.new(text, options) text_box.render @@ -439,11 +440,11 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings).to_not be_empty end end - context ':rotate_around option of :lower_right' do + context 'with :rotate_around option of :lower_right' do it 'draws content to the page rotated about the lower right corner of '\ 'the text' do options[:rotate_around] = :lower_right text_box = described_class.new(text, options) text_box.render @@ -469,11 +470,11 @@ text = PDF::Inspector::Text.analyze(pdf.render) expect(text.strings).to_not be_empty end end - context ':rotate_around option of :lower_left' do + context 'with :rotate_around option of :lower_left' do it 'draws content to the page rotated about the lower left corner of '\ 'the text' do options[:rotate_around] = :lower_left text_box = described_class.new(text, options) text_box.render @@ -519,12 +520,12 @@ text_box.render expect(text_box.height).to be_within(pdf.font.height).of(target_height) end end - it 'should use the parent-box bottom if in a stretchy bbox and ' \ - 'overflow is :expand, even with an explicit height' do + it 'uses the parent-box bottom if in a stretchy bbox and overflow is '\ + ':expand, even with an explicit height' do pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.width) do target_height = pdf.y - pdf.bounds.bottom text = "Oh hai\n" * 60 text_box = described_class.new( text, @@ -661,11 +662,11 @@ expect(text_box.text).to_not eq(text) end end end - context 'printing UTF-8 string with higher bit characters' do + context 'when printing UTF-8 string with higher bit characters' do let(:text) { '©' } let(:text_box) do # not enough height to print any text, so we can directly compare against # the input string @@ -712,11 +713,11 @@ height: bounding_height, document: pdf } end - context 'truncated overflow' do + context 'when truncated overflow' do let(:text_box) do described_class.new(text, options.merge(overflow: :truncate)) end it 'is truncated' do @@ -754,11 +755,11 @@ expect(rotated_text_box.render).to eq(remaining_text) end end end - context 'truncated with text and size taken from the manual' do + context 'when truncated with text and size taken from the manual' do it 'returns the right text' do text = 'This is the beginning of the text. It will be cut somewhere ' \ 'and the rest of the text will procede to be rendered this time by '\ 'calling another method.' + ' . ' * 50 options[:width] = 300 @@ -773,11 +774,11 @@ '. . . . . . . . . ' ) end end - context 'expand overflow' do + context 'when expand overflow' do let(:text_box) do described_class.new(text, options.merge(overflow: :expand)) end it 'height expands to encompass all the text '\ @@ -797,11 +798,11 @@ 'the text)' do expect(text_box.render).to eq('') end end - context 'shrink_to_fit overflow' do + context 'when shrink_to_fit overflow' do let(:text_box) do described_class.new( text, options.merge( overflow: :shrink_to_fit, @@ -816,13 +817,11 @@ end it 'render returns an empty string because no text remains unprinted' do expect(text_box.render).to eq('') end - end - context 'shrink_to_fit overflow' do it 'does not drop below the minimum font size' do options[:overflow] = :shrink_to_fit options[:min_font_size] = 10.1 text_box = described_class.new(text, options) text_box.render @@ -1016,11 +1015,11 @@ ) text_box.render expect(text_box.text).to eq(expect) end - it 'wraps lines comprised of a single word of the bounds when '\ + it 'wraps lines comprised of a single non-alpha word of the bounds when '\ 'wrapping text' do text = '©' * 30 pdf.font 'Courier' text_box = described_class.new( @@ -1029,12 +1028,12 @@ document: pdf ) text_box.render - expected = '©' * 25 + "\n" + '©' * 5 - pdf.font.normalize_encoding!(expected) + expected = +'©' * 25 + "\n" + '©' * 5 + expected = pdf.font.normalize_encoding(expected) expected = expected.force_encoding(Encoding::UTF_8) expect(text_box.text).to eq(expected) end it 'wraps non-unicode strings using single-byte word-wrapping' do @@ -1102,10 +1101,10 @@ expect(contents.text_rendering_mode).to eq([2, 0]) end end def reduce_precision(float) - (format '%.5f', float).to_f + float.round(5) end def first_line(str) str.each_line { |line| return line } end