diff --git a/lib/terminal-table/table.rb b/lib/terminal-table/table.rb index c477f4f..2311940 100755 --- a/lib/terminal-table/table.rb +++ b/lib/terminal-table/table.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 } diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 5d1086f..774c3bb 100755 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -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']