Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the behaviour of Table when the specified width exceeds column width #30

Merged
merged 1 commit into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/terminal-table/table.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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