Sha256: bd7a756c62bbc8d205473fa81164229c3cc4e859feb0abc4a7bd22123aa5d95b

Contents?: true

Size: 755 Bytes

Versions: 3

Compression:

Stored size: 755 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe TTY::Table::Row, '#call' do
  let(:object) { described_class.new(data) }

  subject { object[attribute] }

  context 'when integer' do
    let(:data) { ['a', 'b'] }

    let(:attribute) { 1 }

    it { is_expected.to eql('b') }
  end

  context 'when symbol' do
    let(:data) { {:id => 1} }

    context 'when hash access' do
      let(:attribute) { :id }

      it { is_expected.to eql(1) }
    end

    context 'when array access' do
      let(:attribute) { 0 }

      it { is_expected.to eql(1) }
    end
  end

  context 'when unkown attribute' do
    let(:data) { {:id => 1} }

    let(:attribute) { :other }

    specify { expect { subject }.to raise_error(TTY::UnknownAttributeError) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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