Skip to content

Commit

Permalink
raise an exception when align value is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Sousa authored and pointlessone committed May 30, 2018
1 parent e615f00 commit 2cdd2e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/prawn/text/formatted/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ def draw_fragment(
else
@at[0] + @width - line_width
end
else
raise ArgumentError,
'align must be one of :left, :right, :center or :justify symbols'
end

x += accumulated_width
Expand Down
14 changes: 14 additions & 0 deletions spec/prawn/text/formatted/box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,20 @@
contents = PDF::Inspector::Text.analyze(pdf.render)
expect(contents.word_spacing).to be_empty
end

it 'raise an exception when align value is not a symbol' do
array = [
{ text: 'hello world ' },
{ text: "\n" },
{ text: 'goodbye' }
]
options = { document: pdf, align: 'justify' }
text_box = described_class.new(array, options)
expect { text_box.render }.to raise_error(
ArgumentError,
'align must be one of :left, :right, :center or :justify symbols'
)
end
end

describe 'Text::Formatted::Box#render with :valign => :center' do
Expand Down

0 comments on commit 2cdd2e7

Please sign in to comment.