Sha256: 7c6e4bfa507494da35ac27572f66733db4748eed4bdcbee73328bc5e1f397eb9

Contents?: true

Size: 1.23 KB

Versions: 29

Compression:

Stored size: 1.23 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'thor/core_ext/hash_with_indifferent_access'

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

  it "has values accessible by either strings or symbols" do
    @hash['foo'].must == 'bar'
    @hash[:foo].must  == 'bar'

    @hash.values_at(:foo, :baz).must == ['bar', 'bee']
    @hash.delete(:foo).must == 'bar'
  end

  it "handles magic boolean predicates" do
    @hash.force?.must be_true
    @hash.foo?.must be_true
    @hash.nothing?.must be_false
  end

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

  it "maps methods to keys" do
    @hash.foo.must == @hash['foo']
  end

  it "merges keys independent if they are symbols or strings" do
    @hash.merge!('force' => false, :baz => "boom")
    @hash[:force].must == false
    @hash[:baz].must == "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")
    other[:force].must == false
    other[:baz].must == "boom"
  end
end

Version data entries

29 entries across 29 versions & 5 rubygems

Version Path
wycats-thor-0.11.5 spec/core_ext/hash_with_indifferent_access_spec.rb
puppet-module-0.3.4 vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb
puppet-module-0.3.3 vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb
puppet-module-0.3.2 vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.14.4 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.14.3 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.14.2 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.14.1 spec/core_ext/hash_with_indifferent_access_spec.rb
angry_mob-0.1.0 vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.14.0 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.8 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.7 spec/core_ext/hash_with_indifferent_access_spec.rb
puppet-module-0.3.0 vendor/thor-852190ae/spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.6 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.5 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.4 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.3 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.2 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.1 spec/core_ext/hash_with_indifferent_access_spec.rb
thor-0.13.0 spec/core_ext/hash_with_indifferent_access_spec.rb