Sha256: 43897390e2d4abe76b1887979e9ccb2792ade5813d208e656f6008c615e3b549

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

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

require 'spec_helper'

describe TTY::Conversion do
  let(:described_class) { Class.new { include TTY::Conversion } }
  let(:object) { described_class.new }
  let(:enumerable) { [] }

  subject { object.convert_to_array(enumerable) }

  context 'Array type' do
    it { should == enumerable }
  end

  context 'Hash type' do
    let(:enumerable) { {:a => 1, :b => 2} }

    it { should include([:a, 1]) }

    it { should include([:b, 2]) }
  end

  context 'responds to #to_ary' do
    let(:converted) { [] }
    let(:enumerable) { double('Enumerable', :to_ary => converted) }

    it { should == converted }
  end

  context 'does not respond to #to_ary' do
    let(:enumerable) { double('Enumerable') }

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/support/conversion_spec.rb
tty-0.0.10 spec/tty/support/conversion_spec.rb