Sha256: 67b7ee6615ac9cd18ec2fff542441fb3f6f3b982afd37116897be61da36a3070

Contents?: true

Size: 890 Bytes

Versions: 9

Compression:

Stored size: 890 Bytes

Contents

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

require 'spec_helper'

describe TTY::Coercion do
  let(:described_class) { Class.new { include TTY::Coercion } }
  let(:object) { described_class.new }
  let(:value) { [] }
  let(:coercible) { [ value, Array, :to_a] }

  subject { object.coerce_to( *coercible ) }

  it { should == value }

  context 'coerces into integer' do
    let(:value) { '123' }
    let(:coercible) { [ value, Integer, :to_i] }

    it { should be_kind_of(Integer) }

    it { should == value.to_i }
  end

  context 'coerces into symbol' do
    let(:value) { 'argument' }
    let(:coercible) { [value, Symbol, :to_sym]}

    it { should be_kind_of(Symbol) }

    it { should == value.to_sym }
  end

  context 'coerces into string' do
    let(:value) { true }
    let(:coercible) { [value, String, :to_s] }

    it { should be_kind_of(String) }

    it { should == value.to_s }
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/support/coercion_spec.rb
tty-0.0.10 spec/tty/support/coercion_spec.rb
tty-0.0.9 spec/tty/support/coercion_spec.rb
tty-0.0.8 spec/tty/support/coercion_spec.rb
tty-0.0.7 spec/tty/support/coercion_spec.rb
tty-0.0.6 spec/tty/support/coercion_spec.rb
tty-0.0.5 spec/tty/support/coercion_spec.rb
tty-0.0.4 spec/tty/support/coercion_spec.rb
tty-0.0.3 spec/tty/support/coercion_spec.rb