Sha256: 7db46e5a5c988bb43debfc8e8c3c85c4d34b30e0ad85a909c8fca78f52aeefcc

Contents?: true

Size: 1.12 KB

Versions: 12

Compression:

Stored size: 1.12 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'
    }
  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 '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

12 entries across 12 versions & 1 rubygems

Version Path
arstotzka-1.4.1 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.4.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.3.2 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.3.1 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.3.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.2.4 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.2.3 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.2.2 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.2.1 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.2.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.1.0 spec/integration/yard/arstotzka/type_cast_spec.rb
arstotzka-1.0.4 spec/integration/yard/arstotzka/type_cast_spec.rb