Permalink
Browse files

Fixed the behaviour of Table when the specified width exceeds the tot…

…al column width
  • Loading branch information...
1 parent a8f9179 commit fc44bc809b1d56a200924fef2a5b54ee7ee7f9ed @bcandrea committed Mar 4, 2013
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/terminal-table/table.rb
  2. +10 −0 spec/table_spec.rb
@@ -166,7 +166,7 @@ def additional_column_widths
return [] if style.width.nil?
spacing = style.width - columns_width
if spacing < 0
- raise "Table width exceeds wanted width of #{wanted} characters."
+ raise "Table width exceeds wanted width of #{style.width} characters."
else
per_col = spacing / number_of_columns
arr = (1...number_of_columns).to_a.map { |i| per_col }
View
@@ -173,6 +173,16 @@ module Terminal
EOF
end
+ it "should raise an error if the table width exceeds style width" do
+ @table.headings = ['Char', 'Num']
+ @table << ['a', 1]
+ @table << ['b', 2]
+ @table << ['c', 3]
+ @table << ['d', 'x' * 22]
+ @table.style.width = 21
+ expect { @table.render }.to raise_error "Table width exceeds wanted width of 21 characters."
+ end
+
it "should render title properly" do
@table.title = "Title"
@table.headings = ['Char', 'Num']

1 comment on commit fc44bc8

@terabyte

I ran into this bug too. I'm going to open up a separate issue though because a much bigger problem is how you figure out how to wrap a column without knowing its length, there isn't really a way for the user to find out the evetual length to wrap things properly...

Please sign in to comment.