Sha256: f56884626915dd20b345959402897cf7b1b5ede2b101d4c6d917bbdbe9099dc8

Contents?: true

Size: 897 Bytes

Versions: 7

Compression:

Stored size: 897 Bytes

Contents

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

require 'spec_helper'

describe TTY::Vector, '#new' do
  let(:object) { described_class }

  subject { object.new(argument) }

  context 'with no arguments' do
    subject { object.new }

    it 'sets elements to empty array' do
      subject.to_a.should == []
    end
  end

  context 'with nil argument' do
    let(:argument) { nil }

    it 'throws type error' do
      expect { subject }.to raise_error(TTY::TypeError)
    end
  end

  context 'with an argument that is a hash' do
    let(:argument) { {:value => 'Piotr'} }

    it 'sets elements' do
      subject.to_a.should == [[:value, 'Piotr']]
    end
  end

  context 'with an argument that respond to #to_ary' do
    let(:argument) {
      Class.new do
        def to_ary
          ['Piotr']
        end
      end.new
    }

    it 'sets elements' do
      subject.to_a.should == ['Piotr']
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/vector/new_spec.rb
tty-0.0.10 spec/tty/vector/new_spec.rb
tty-0.0.9 spec/tty/vector/new_spec.rb
tty-0.0.8 spec/tty/vector/new_spec.rb
tty-0.0.7 spec/tty/vector/new_spec.rb
tty-0.0.6 spec/tty/vector/new_spec.rb
tty-0.0.5 spec/tty/vector/new_spec.rb