Sha256: e0966b4fc17b5c630991375a9220ce3bf3944ec62349904b3cb44e56f56fd403

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'


class Package
  include Virtus

  attribute :dimensions, Hash[Symbol => Float]
  attribute :meta_info , Hash[String => String]
end


describe Package do
  let(:instance) do
    described_class.new(
      :dimensions => { 'width' => "2.2", :height => 2, "length" => 4.5 },
      :meta_info  => { 'from'  => :Me  , :to => 'You' }
    )
  end

  let(:dimensions) { instance.dimensions }
  let(:meta_info)  { instance.meta_info  }

  describe '#dimensions' do
    subject { dimensions }

    it 'has 3 keys' do
      expect(subject.keys.size).to eq(3)
    end
    it { is_expected.to have_key :width  }
    it { is_expected.to have_key :height }
    it { is_expected.to have_key :length }

    it 'should be coerced to [Symbol => Float] format' do
      expect(dimensions[:width]).to  be_eql(2.2)
      expect(dimensions[:height]).to be_eql(2.0)
      expect(dimensions[:length]).to be_eql(4.5)
    end
  end

  describe '#meta_info' do
    subject { meta_info }

    it 'has 2 keys' do
      expect(subject.keys.size).to eq(2)
    end
    it { is_expected.to have_key 'from' }
    it { is_expected.to have_key 'to'   }

    it 'should be coerced to [String => String] format' do
      expect(meta_info['from']).to eq('Me')
      expect(meta_info['to']).to eq('You')
    end
  end
end

Version data entries

15 entries across 13 versions & 5 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/integration/hash_attributes_coercion_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/integration/hash_attributes_coercion_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/virtus-2.0.0/spec/integration/hash_attributes_coercion_spec.rb
virtus2-2.1.0 spec/integration/hash_attributes_coercion_spec.rb
virtus2-2.0.2 spec/integration/hash_attributes_coercion_spec.rb
virtus2-2.0.1 spec/integration/hash_attributes_coercion_spec.rb
virtus-2.0.0 spec/integration/hash_attributes_coercion_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/virtus-1.0.5/spec/integration/hash_attributes_coercion_spec.rb
virtus-1.0.5 spec/integration/hash_attributes_coercion_spec.rb
virtus-1.0.4 spec/integration/hash_attributes_coercion_spec.rb