Sha256: b7d4ebbe25453a089cbf010af103bbeff0b8d7bc1c4a9ab1fc62a75d03f79e1c

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe 'HashRowsSource' do
  it 'outputs text table of simple hash row with default columns' do
    expected = <<~TABLE
      +---+---+
      | a | b |
      +---+---+
      | 1 | 2 |
      +---+---+
    TABLE
    [{a: 1, b: 2}].to_table.text_table.to_s.should == expected
  end

  it 'outputs text table of hash row with nested Array' do
    expected = <<~TABLE
      +---+--------+
      | a |   b    |
      +---+--------+
      | 1 | [1, 2] |
      +---+--------+
    TABLE
    [{a: 1, b: [1, 2]}].to_table.text_table.to_s.should == expected
  end

  it 'outputs text table of hash row with nested Hash' do
    expected = <<~TABLE
      +---+---------+
      | a |    b    |
      +---+---------+
      | 1 | {:c=>3} |
      +---+---------+
    TABLE
    [{a: 1, b: {c: 3}}].to_table.text_table.to_s.should == expected
  end

  it 'outputs text table of mixed columns hash rows with default columns' do
    expected = <<~TABLE
      +---+---+---+
      | a | b | c |
      +---+---+---+
      | 1 | 2 |   |
      | 2 |   | ! |
      +---+---+---+
    TABLE
    [
      {a: 1, b: 2},
      {a: 2, c: '!'}
    ].to_table.text_table.to_s.should == expected
  end

  it 'outputs text table of deep hash rows with defined columns' do
    expected = <<~TABLE
      +---+---+---+
      | a |   b   |
      +---+---+---+
      |   | c | d |
      +---+---+---+
      | 1 | 2 | 2 |
      +---+---+---+
    TABLE
    b = [{a: 1, b: {c: 2, d: 2}}].to_table
    def b.columns
      [
        Column.new(name: :a),
        {b: [
          Column.new(name: :c)
        ]}
      ]
    end

    # this would be nice.
    # b.text_table.to_s.should == expected
    pending
  end

  it 'keeps OrderedHash keys in order' do
    h = ActiveSupport::OrderedHash.new
    h[:z] = 2
    h[:y] = 1
    expected = <<~TABLE
      +---+---+
      | z | y |
      +---+---+
      | 2 | 1 |
      +---+---+
    TABLE
    h.to_table.text_table.to_s.should == expected
  end

  it 'outputs text table of deep hash rows with default columns'
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tablesmith-0.4.1 spec/hash_rows_table_spec.rb
tablesmith-0.4.0 spec/hash_rows_table_spec.rb
tablesmith-0.3.1 spec/hash_rows_table_spec.rb
tablesmith-0.3.0 spec/hash_rows_table_spec.rb
tablesmith-0.2.2 spec/hash_rows_table_spec.rb