Sha256: 425ab7f4f649bedb103696d15567bf5f3eedea00be531bf649a5cbf3eea8465b

Contents?: true

Size: 790 Bytes

Versions: 10

Compression:

Stored size: 790 Bytes

Contents

# coding: utf-8

require 'spec_helper'

RSpec.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::Table::UnknownAttributeError)
    }
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tty-table-0.10.0 spec/unit/row/call_spec.rb
tty-table-0.9.0 spec/unit/row/call_spec.rb
tty-table-0.8.0 spec/unit/row/call_spec.rb
tty-table-0.7.0 spec/unit/row/call_spec.rb
tty-table-0.6.0 spec/unit/row/call_spec.rb
tty-table-0.5.0 spec/unit/row/call_spec.rb
tty-table-0.4.0 spec/unit/row/call_spec.rb
tty-table-0.3.0 spec/unit/row/call_spec.rb
tty-table-0.2.0 spec/unit/row/call_spec.rb
tty-table-0.1.0 spec/unit/row/call_spec.rb