Sha256: 7bbe1f9d9b0a766ead4beb8a9dd28908ad384c74930b8089f16bb98ea6448f7d

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Turnip::Table do
  describe '#raw' do
    it 'returns the raw table' do
      table = Turnip::Table.new([['foo', 'bar'], ['quox', '42']])
      table.raw.should == [['foo', 'bar'], ['quox', '42']]
    end
  end

  describe '#to_a' do
    it 'returns the raw table' do
      table = Turnip::Table.new([['foo', 'bar'], ['quox', '42']])
      table.to_a.should == [['foo', 'bar'], ['quox', '42']]
    end
  end

  describe '#headers' do
    it 'returns the first row' do
      table = Turnip::Table.new([['foo', 'bar'], ['quox', '42']])
      table.headers.should == ['foo', 'bar']
    end
  end

  describe '#rows' do
    it 'returns the rows beyond the first' do
      table = Turnip::Table.new([['foo', 'bar'], ['moo', '55'], ['quox', '42']])
      table.rows.should == [['moo', '55'], ['quox', '42']]
    end
  end

  describe '#hashes' do
    it 'returns a list of hashes based on the headers' do
      table = Turnip::Table.new([['foo', 'bar'], ['moo', '55'], ['quox', '42']])
      table.hashes.should == [
        {'foo' => 'moo', 'bar' => '55'},
        {'foo' => 'quox', 'bar' => '42'}
      ]
    end
  end
  
  describe '#rows_hash' do
    it 'converts this table into a Hash where the first column is used as keys and the second column is used as values' do
      table = Turnip::Table.new([['foo', 'moo'], ['bar', '55']])
      table.rows_hash.should == {'foo' => 'moo', 'bar' => '55'}
    end
  end

  describe '#map' do
    it 'iterates over the raw table' do
      table = Turnip::Table.new([['moo', '55'], ['quox', '42']])
      table.map(&:first).should == ['moo', 'quox']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
turnip-0.3.0 spec/table_spec.rb