Sha256: d2dddc259940a133ae3e9c69e3ee50d8650b01dfd0ef478b4d50adbf991927b8

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Table::Renderer::Basic, 'filter' do
  let(:header) { ['h1', 'h2', 'h3'] }
  let(:rows)   { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
  let(:table)  { TTY::Table.new(header, rows) }

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

  context 'with header' do
    context 'filtering only rows' do
      let(:filter) { Proc.new { |val, row, col|
          (col == 1 and row > 0) ? val.capitalize : val
        }
      }

      it 'filters only rows' do
        subject.render.should == <<-EOS.normalize
          h1 h2 h3
          a1 A2 a3
          b1 B2 b3
        EOS
      end
    end

    context 'filtering header and rows' do
      let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}

      it 'filters only rows' do
        subject.render.should == <<-EOS.normalize
          h1 H2 h3
          a1 A2 a3
          b1 B2 b3
        EOS
      end
    end
  end

  context 'without header' do
    let(:header) { nil }

    let(:filter) { Proc.new { |val, row, col| col == 1 ?  val.capitalize : val } }

    it 'filters only rows' do
      subject.render.should == <<-EOS.normalize
        a1 A2 a3
        b1 B2 b3
      EOS
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/table/renderer/basic/filter_spec.rb
tty-0.0.10 spec/tty/table/renderer/basic/filter_spec.rb