Sha256: afe06dceed2d2dd242314098e844b87be23f30d2d3f9bea4a5bf38d30375d7e4

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

RSpec.describe Hashie::Extensions::Mash::SymbolizeKeys do
  it 'raises an error when included in a class that is not a Mash' do
    expect do
      Class.new do
        include Hashie::Extensions::Mash::SymbolizeKeys
      end
    end.to raise_error(ArgumentError)
  end

  it 'symbolizes all keys in the Mash' do
    my_mash = Class.new(Hashie::Mash) do
      include Hashie::Extensions::Mash::SymbolizeKeys
    end

    expect(my_mash.new('test' => 'value').to_h).to eq(test: 'value')
  end

  context 'implicit to_hash on double splat' do
    let(:destructure) { ->(**opts) { opts } }
    let(:my_mash) do
      Class.new(Hashie::Mash) do
        include Hashie::Extensions::Mash::SymbolizeKeys
      end
    end
    let(:instance) { my_mash.new('outer' => { 'inner' => 42 }, 'testing' => [1, 2, 3]) }

    subject { destructure.call(instance) }

    it 'is converted on method calls' do
      expect(subject).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
    end

    it 'is converted on explicit operator call' do
      expect(**instance).to eq(outer: { inner: 42 }, testing: [1, 2, 3])
    end
  end
end

Version data entries

11 entries across 10 versions & 3 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hashie-3.6.0/spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-4.0.0 spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-3.6.0 spec/hashie/extensions/mash/symbolize_keys_spec.rb
tdiary-5.0.8 vendor/bundle/gems/hashie-3.5.7/spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-3.5.7 spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-3.5.6 spec/hashie/extensions/mash/symbolize_keys_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/hashie-3.5.5/spec/hashie/extensions/mash/symbolize_keys_spec.rb
tdiary-5.0.5 vendor/bundle/gems/hashie-3.5.5/spec/hashie/extensions/mash/symbolize_keys_spec.rb
tdiary-5.0.4 vendor/bundle/gems/hashie-3.5.5/spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-3.5.5 spec/hashie/extensions/mash/symbolize_keys_spec.rb
hashie-3.5.4 spec/hashie/extensions/mash/symbolize_keys_spec.rb