Sha256: 07ca1ea874b98db61b0cf7b5dfc98b1f2fe95f8b49552490633f2c4c69ede27f

Contents?: true

Size: 994 Bytes

Versions: 2

Compression:

Stored size: 994 Bytes

Contents

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

require 'spec_helper'

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

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

    it { should be_instance_of(to_enum.class) }

    it 'yields the expected values' do
      subject.to_a.should eql(object.to_a)
    end
  end

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

    subject { object.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(object.data)
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/table/each_spec.rb
tty-0.0.10 spec/tty/table/each_spec.rb