Sha256: 4a317bc869e770e344c98f2366113a405f9f85377d4ac404b683216c33930967

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe TTY::Table::Renderer::ASCII, 'padding' do
  let(:header) { ['Field', 'Type', 'Null', 'Key', 'Default', 'Extra'] }
  let(:rows)   { [['id', 'int(11)', 'YES', 'nil', 'NULL', '']] }
  let(:table)  { TTY::Table.new(header, rows) }

  subject(:renderer) { described_class.new(table, options) }

  context 'with left & right padding' do
    let(:options) { {padding: [0,1,0,1]} }

    it 'pads each field' do
      expect(renderer.render).to eql <<-EOS.chomp
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  | nil | NULL    |       |
+-------+---------+------+-----+---------+-------+
      EOS
    end
  end

  context 'with top & bottom padding' do
    let(:options) { {padding: [1,0,1,0], multiline: true} }

    it 'pads each field' do
      expect(renderer.render).to eql <<-EOS.chomp
+-----+-------+----+---+-------+-----+
|     |       |    |   |       |     |
|Field|Type   |Null|Key|Default|Extra|
|     |       |    |   |       |     |
+-----+-------+----+---+-------+-----+
|     |       |    |   |       |     |
|id   |int(11)|YES |nil|NULL   |     |
|     |       |    |   |       |     |
+-----+-------+----+---+-------+-----+
      EOS
    end
  end

  context 'with full padding' do
    let(:options) { {padding: [1,1,1,1], multiline: true} }

    it 'pads each field' do
      expect(renderer.render).to eql <<-EOS.chomp
+-------+---------+------+-----+---------+-------+
|       |         |      |     |         |       |
| Field | Type    | Null | Key | Default | Extra |
|       |         |      |     |         |       |
+-------+---------+------+-----+---------+-------+
|       |         |      |     |         |       |
| id    | int(11) | YES  | nil | NULL    |       |
|       |         |      |     |         |       |
+-------+---------+------+-----+---------+-------+
      EOS
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-0.1.2 spec/tty/table/renderer/ascii/padding_spec.rb
tty-0.1.1 spec/tty/table/renderer/ascii/padding_spec.rb
tty-0.1.0 spec/tty/table/renderer/ascii/padding_spec.rb