Sha256: d63f6a40455c1e29ef93a95df88ebfa032d0d614902d5d6c3fdfc22ec083e2d5

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

describe Arstotzka::TypeCast do
  subject(:model) { TypeCaster.new(hash) }

  let(:hash) do
    {
      age:     '10',
      payload: { 'key' => 'value' },
      price:   '1.75',
      type:    'type_a'
    }
  end

  describe 'yard' do
    describe 'integer' do
      it 'converts string to integer' do
        expect(model.age).to eq(10)
      end
    end

    describe 'string' do
      it 'converts value to string' do
        expect(model.payload).to eq('{"key"=>"value"}')
      end
    end

    describe 'float' do
      it 'converts value to string' do
        expect(model.price).to eq(1.75)
      end
    end

    describe 'symbol' do
      it 'converts value to string' do
        expect(model.type).to eq(:type_a)
      end
    end

    describe 'extending' do
      subject(:model) { CarCollector.new(hash) }

      let(:hash) do
        {
          cars: [{
            unit: { model: 'fox', maker: 'volkswagen' }
          }, {
            unit: { 'model' => 'focus', 'maker' => 'ford' }
          }]
        }
      end

      it 'converts each unit to be a car' do
        expect(model.cars.first).to be_a(Car)
      end

      it 'converts using the given hash' do
        expect(model.cars.map(&:model)).to eq(%w[fox focus])
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arstotzka-1.6.2 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.6.1 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.6.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.5.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.4.4 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.4.3 spec/integration/yard/arstotzka/type_cast_spec.rb