Sha256: ff85939b3a1598796cb956da48195a58dc8ba78d0008a2a2225dc8d4c5d390d2

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 KB

Contents

require File.join(File.dirname(__FILE__), 'spec_helper')

require 'stringio'

context "PrettyTable" do
  setup do
    @data1 = [
      {:x => 3, :y => 4}
    ]
    
    @data2 = [
      {:a => 23, :b => 45},
      {:a => 45, :b => 2377}
    ]

    @data3 = [
      {:aaa => 1},
      {:bb => 2},
      {:c => 3}
    ]

    @output = StringIO.new
    @orig_stdout = $stdout
    $stdout = @output
  end

  teardown do
    $stdout = @orig_stdout
  end
  
  specify "should infer the columns if not given" do
    Sequel::PrettyTable.print(@data1)
    @output.rewind
    @output.read.should =~ \
      /\n(\|x\|y\|)|(\|y\|x\|)\n/
  end
  
  specify "should calculate the maximum width of each column correctly" do
    Sequel::PrettyTable.print(@data2, [:a, :b])
    @output.rewind
    @output.read.should == \
      "+--+----+\n|a |b   |\n+--+----+\n|23|  45|\n|45|2377|\n+--+----+\n"
  end

  specify "should also take header width into account" do
    Sequel::PrettyTable.print(@data3, [:aaa, :bb, :c])
    @output.rewind
    @output.read.should == \
      "+---+--+-+\n|aaa|bb|c|\n+---+--+-+\n|  1|  | |\n|   | 2| |\n|   |  |3|\n+---+--+-+\n"
  end
  
  specify "should print only the specified columns" do
    Sequel::PrettyTable.print(@data2, [:a])
    @output.rewind
    @output.read.should == \
      "+--+\n|a |\n+--+\n|23|\n|45|\n+--+\n"
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
colincasey-sequel-2.10.1 spec/sequel_core/pretty_table_spec.rb
colincasey-sequel-2.10.2 spec/sequel_core/pretty_table_spec.rb
colincasey-sequel-2.10.4 spec/sequel_core/pretty_table_spec.rb
epugh-sequel-0.0.0 spec/core/pretty_table_spec.rb
sequel-2.11.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.10.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.4.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.3.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.8.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.6.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.5.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.7.0 spec/sequel_core/pretty_table_spec.rb
sequel-2.7.1 spec/sequel_core/pretty_table_spec.rb
sequel-2.9.0 spec/sequel_core/pretty_table_spec.rb
sequel_core-2.1.0 spec/pretty_table_spec.rb
sequel_core-2.0.1 spec/pretty_table_spec.rb
sequel_core-1.5.1 spec/pretty_table_spec.rb
sequel_core-1.5.0 spec/pretty_table_spec.rb
sequel_core-2.0.0 spec/pretty_table_spec.rb
sequel_core-2.2.0 spec/pretty_table_spec.rb