Sha256: 01f315cff24d3c67f2d3374434baa40a5fcd41cb5b823385461837af1f0692e6

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8

require 'spec_helper'

RSpec.describe TTY::Table::Renderer::Basic, 'coloring' do
  let(:header)   { ['h1', 'h2'] }
  let(:rows)     { [['a1', 'a2'], ['b1', 'b2']] }
  let(:clear)    { "\e[0m" }
  let(:options)  { {filter: filter } }
  let(:table)    { TTY::Table.new(header, rows) }
  let(:color)    { Pastel.new(enabled: true) }

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

  before { allow(Pastel).to receive(:new).and_return(color) }

  context 'with filter on all fields' do
    let(:filter) {
      proc { |val, row, col| color.decorate val, :blue, :on_green }
    }

    it 'colors all elements' do
      expect(renderer.render).to eql <<-EOS.normalize
        \e[34;42mh1#{clear} \e[34;42mh2#{clear}
        \e[34;42ma1#{clear} \e[34;42ma2#{clear}
        \e[34;42mb1#{clear} \e[34;42mb2#{clear}
      EOS
    end
  end

  context 'with filter only on header' do
    let(:filter) {
      proc { |val, row, col|
        row.zero? ?  color.decorate(val, :blue, :on_green) : val
      }
    }

    it 'colors only header' do
      expect(renderer.render).to eql <<-EOS.normalize
        \e[34;42mh1#{clear} \e[34;42mh2#{clear}
        a1 a2
        b1 b2
      EOS
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.1.2 spec/tty/table/renderer/basic/coloring_spec.rb
tty-0.1.1 spec/tty/table/renderer/basic/coloring_spec.rb