Browse files

Numbers should display correctly in tables

  • Loading branch information...
1 parent 5d1f449 commit 4d30f3a297ca075b0359e9627ff0886765e8909b tomhuda committed Apr 28, 2012
Showing with 25 additions and 1 deletion.
  1. +1 −1 lib/thor/shell/basic.rb
  2. +24 −0 spec/shell/basic_spec.rb
View
2 lib/thor/shell/basic.rb
@@ -123,7 +123,7 @@ def print_table(table, options={})
colcount = table.max{|a,b| a.size <=> b.size }.size
start.upto(colcount - 2) do |i|
- maxima ||= table.map {|row| row[i] ? row[i].size : 0 }.max
+ maxima ||= table.map {|row| row[i] ? row[i].to_s.size : 0 }.max
formats << "%-#{maxima + 2}s"
end
View
24 spec/shell/basic_spec.rb
@@ -172,6 +172,30 @@ def shell
xyz #786 last three
TABLE
end
+
+ it "prints a table with small numbers" do
+ table = [
+ ["Name", "Number", "Color"],
+ ["Erik", 1, "green"]
+ ]
+ content = capture(:stdout){ shell.print_table(table) }
+ content.should == <<-TABLE
+Name Number Color
+Erik 1 green
+TABLE
+ end
+
+ it "prints a table with big numbers" do
+ table = [
+ ["Name", "Number", "Color"],
+ ["Erik", 1234567890123, "green"]
+ ]
+ content = capture(:stdout){ shell.print_table(table) }
+ content.should == <<-TABLE
+Name Number Color
+Erik 1234567890123 green
+TABLE
+ end
end
describe "#file_collision" do

0 comments on commit 4d30f3a

Please sign in to comment.