Sha256: 3d0d8dfe5f03c6bd6462e2c1277257f87ec44a8b699d2b93487b8ffcbb5cb880

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

# coding: utf-8

require 'spec_helper'

RSpec.describe TTY::Table::Border::ASCII, '#rendering' do

  subject(:border) { described_class.new(column_widths, [0,0,0,0]) }

  context 'with empty row' do
    let(:row) { TTY::Table::Row.new([]) }
    let(:column_widths) { [] }

    it 'draws top line' do
      expect(border.top_line).to eq("++")
    end

    it 'draws middle line' do
      expect(border.separator).to eq("++")
    end

    it 'draw bottom line' do
      expect(border.bottom_line).to eq("++")
    end

    it 'draws row line' do
      expect(border.row_line(row)).to eq("||")
    end
  end

  context 'with row' do
    let(:column_widths) { [2,2,2] }
    let(:row) { TTY::Table::Row.new(['a1', 'a2', 'a3']) }

    it 'draws top line' do
      expect(border.top_line).to eq("+--+--+--+")
    end

    it 'draw middle line' do
      expect(border.separator).to eq("+--+--+--+")
    end

    it 'draw bottom line' do
      expect(border.bottom_line).to eq("+--+--+--+")
    end

    it 'draws row line' do
      expect(border.row_line(row)).to eq("|a1|a2|a3|")
    end
  end

  context 'with multiline row' do
    let(:column_widths) { [2,2,2]}

    context 'with mixed data' do
      let(:row) { TTY::Table::Row.new(["a1\nb1\nc1", 'a2', 'a3']) }

      it 'draws row line' do
        expect(border.row_line(row)).to eq unindent(<<-EOS)
          |a1|a2|a3|
          |b1|  |  |
          |c1|  |  |
        EOS
      end
    end

    context 'with sparse data' do
      let(:row) { TTY::Table::Row.new(["a1\n\n", "\na2\n", "\n\na3"]) }

      it 'draws row line' do
        expect(border.row_line(row)).to eq unindent(<<-EOS)
          |a1|  |  |
          |  |a2|  |
          |  |  |a3|
        EOS
      end
    end

    context 'with empty data' do
      let(:row) { TTY::Table::Row.new(["\na1\n", "\na2\n", "\na3\n"]) }

      it 'draws row line' do
        expect(border.row_line(row)).to eq unindent(<<-EOS)
          |  |  |  |
          |a1|a2|a3|
          |  |  |  |
        EOS
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tty-table-0.9.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.8.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.7.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.6.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.5.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.4.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.3.0 spec/unit/border/ascii/rendering_spec.rb
tty-table-0.2.0 spec/unit/border/ascii/rendering_spec.rb