Sha256: cda65b8b79f17b9c115076de07cee58d0161f88feb5b487271cb386982c102f6

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'Array Source' do
  it 'just works in a console' do
    expected = <<~TABLE
      +---+---+---+
      | a | b | c |
      +---+---+---+
      | d | e | f |
      +---+---+---+
    TABLE
    [%w[a b c], %w[d e f]].to_table.to_s.should == expected
  end

  def do_just_works_test(meth_id)
    orig_stdout = $stdout
    sio = StringIO.new
    $stdout = sio
    send(meth_id, [%w[a b c], %w[d e f]].to_table)
    sio.string
  ensure
    $stdout = orig_stdout
  end

  def just_works(meth_id)
    expected = <<~TABLE
      +---+---+---+
      | a | b | c |
      +---+---+---+
      | d | e | f |
      +---+---+---+
    TABLE

    actual = do_just_works_test(meth_id)
    actual.should == expected
  end

  it 'just works with print' do
    just_works(:print)
  end

  it 'just works with puts' do
    just_works(:puts)
  end

  it 'just works with p' do
    expected = <<~TABLE
      +---+---+---+
      | a | b | c |
      +---+---+---+
      | d | e | f |
      +---+---+---+
    TABLE

    actual = do_just_works_test(:p)
    actual.should == "#{expected}\n"
  end

  it 'just works with inspect' do
    expected = <<~TABLE
      +---+---+---+
      | a | b | c |
      +---+---+---+
      | d | e | f |
      +---+---+---+
    TABLE
    [%w[a b c], %w[d e f]].to_table.inspect.should == expected
  end

  it 'just works with inspect two element integer array' do
    expected = <<~TABLE
      +---+
      | 1 |
      | 3 |
      +---+
    TABLE
    [1, 3].to_table.inspect.should == expected
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tablesmith-0.6.2 spec/array_table_spec.rb
tablesmith-0.6.0 spec/array_table_spec.rb