Sha256: c7f0b0553f5e9acd3cb2e50b9f265c072d13aee8bc1c97350180dcba1a21677f

Contents?: true

Size: 971 Bytes

Versions: 3

Compression:

Stored size: 971 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe TTY::Table, '#each' do
  let(:table) { described_class.new header, rows }
  let(:header) { ['Header1'] }
  let(:rows)   { [['a1'], ['b1']] }
  let(:field)  { TTY::Table::Field }

  context 'with no block' do
    subject { table.each }

    it { is_expected.to be_instance_of(to_enum.class) }

    it 'yields the expected values' do
      expect(subject.to_a).to eql(table.to_a)
    end
  end

  context 'with block' do
    let(:yields) { [] }

    subject { table.each { |row| yields << row } }

    it 'yields header and rows' do
      subject
      expect(yields.first).to be_instance_of(TTY::Table::Header)
      expect(yields.last).to be_instance_of(TTY::Table::Row)
    end

    it 'yields header and rows with expected attributes' do
      subject
      expect(yields).to eql(table.data)
    end

    xit 'yields each row' do
      expect { subject }.to change { yields }.from([]).to(table.data)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-0.1.2 spec/tty/table/each_spec.rb
tty-0.1.1 spec/tty/table/each_spec.rb
tty-0.1.0 spec/tty/table/each_spec.rb