Sha256: 13ef377a89ccf3e8b686dd263373b61668e656ff30977dd64f9e4182b4314c52

Contents?: true

Size: 1.43 KB

Versions: 69

Compression:

Stored size: 1.43 KB

Contents

require 'helper'
require 'thor/core_ext/hash_with_indifferent_access'

describe Thor::CoreExt::HashWithIndifferentAccess do
  before do
    @hash = Thor::CoreExt::HashWithIndifferentAccess.new :foo => 'bar', 'baz' => 'bee', :force => true
  end

  it "has values accessible by either strings or symbols" do
    expect(@hash['foo']).to eq('bar')
    expect(@hash[:foo]).to eq('bar')

    expect(@hash.values_at(:foo, :baz)).to eq(['bar', 'bee'])
    expect(@hash.delete(:foo)).to eq('bar')
  end

  it "handles magic boolean predicates" do
    expect(@hash.force?).to be_true
    expect(@hash.foo?).to be_true
    expect(@hash.nothing?).to be_false
  end

  it "handles magic comparisions" do
    expect(@hash.foo?('bar')).to be_true
    expect(@hash.foo?('bee')).to be_false
  end

  it "maps methods to keys" do
    expect(@hash.foo).to eq(@hash['foo'])
  end

  it "merges keys independent if they are symbols or strings" do
    @hash.merge!('force' => false, :baz => "boom")
    expect(@hash[:force]).to eq(false)
    expect(@hash[:baz]).to eq("boom")
  end

  it "creates a new hash by merging keys independent if they are symbols or strings" do
    other = @hash.merge('force' => false, :baz => "boom")
    expect(other[:force]).to eq(false)
    expect(other[:baz]).to eq("boom")
  end

  it "converts to a traditional hash" do
    expect(@hash.to_hash.class).to eq(Hash)
    expect(@hash).to eq({ 'foo' => 'bar', 'baz' => 'bee', 'force' => true })
  end
end

Version data entries

69 entries across 61 versions & 12 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/thor-0.18.1/spec/core_ext/hash_with_indifferent_access_spec.rb