Sha256: 8ed4efddfa26a6bac8e73f7603d03e821c6eb29509c08b8cb6b917c9f55d7501

Contents?: true

Size: 1.71 KB

Versions: 39

Compression:

Stored size: 1.71 KB

Contents

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

describe "object table" do
  def table(*args)
    Helpers::ObjectTable.render(*args)
  end

  before_all {
    @pets = [stub(:name=>'rufus', :age=>7, :to_s=>'rufus'), stub(:name=>'alf', :age=>101, :to_s=>'alf')]
  }
  it "renders" do
    expected_table = <<-TABLE.unindent
    +-------+-----+
    | name  | age |
    +-------+-----+
    | rufus | 7   |
    | alf   | 101 |
    +-------+-----+
    2 rows in set
    TABLE
    table(@pets, :fields=>[:name, :age]).should == expected_table
  end
  
  it "with no options defaults to to_s field" do
    expected_table = <<-TABLE.unindent
    +-------+
    | value |
    +-------+
    | rufus |
    | alf   |
    +-------+
    2 rows in set
    TABLE
    table(@pets).should == expected_table
  end

  it "renders simple arrays" do
    expected_table = <<-TABLE.unindent
    +-------+
    | value |
    +-------+
    | 1     |
    | 2     |
    | 3     |
    | 4     |
    +-------+
    4 rows in set
    TABLE
    table([1,2,3,4]).should == expected_table
  end

  it "renders simple arrays with custom header" do
    expected_table = <<-TABLE.unindent
    +-----+
    | num |
    +-----+
    | 1   |
    | 2   |
    | 3   |
    | 4   |
    +-----+
    4 rows in set
    TABLE
    table([1,2,3,4], :headers=>{:to_s=>'num'}).should == expected_table
  end

  it "with empty fields" do
    expected_table = <<-TABLE.unindent
    0 rows in set
    TABLE
    table(@pets, :fields => []).should == expected_table
  end

  it "doesn't raise error for objects that don't have :send defined" do
    object = Object.new
    class<<object; self; end.send :undef_method, :send
    should.not.raise(NoMethodError) { table([object], :fields=>[:to_s]) }
  end
end

Version data entries

39 entries across 38 versions & 5 rubygems

Version Path
hirber-0.8.7 test/object_table_test.rb
hirber-0.8.6 test/object_table_test.rb
hirber-0.8.5 test/object_table_test.rb
hirber-0.8.4 test/object_table_test.rb
hirber-0.8.2 test/object_table_test.rb
hirber-0.8.1 test/object_table_test.rb
hirber-0.8.0 test/object_table_test.rb
hirb-0.7.3 test/object_table_test.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
hirb-0.7.2 test/object_table_test.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/hirb-0.7.1/test/object_table_test.rb
hirb-0.7.1 test/object_table_test.rb
hirb-0.7.0 test/object_table_test.rb
hirb-0.6.2 test/object_table_test.rb