Skip to content

Commit

Permalink
Fixed the behaviour of Table when the specified width exceeds the tot…
Browse files Browse the repository at this point in the history
…al column width
  • Loading branch information
bcandrea committed Mar 4, 2013
1 parent a8f9179 commit fc44bc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/terminal-table/table.rb
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions spec/table_spec.rb
Expand Up @@ -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']
Expand Down

1 comment on commit fc44bc8

@terabyte
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.