Sha256: 3f39b3f6090ab49e384dbe9152ae959c8ab8ea51d06d70cac2ae3b50c43954a3

Contents?: true

Size: 1.26 KB

Versions: 101

Compression:

Stored size: 1.26 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'].should == 'bar'
    @hash[:foo].should  == 'bar'

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

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

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

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

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

Version data entries

101 entries across 96 versions & 12 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.5 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.4 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.3 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
wijet-thor-0.14.10 spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.2 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.1 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.7.0 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
wijet-thor-0.14.9 spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.9 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.8 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.7 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.6 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.5 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.4 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.3 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.2 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb
classiccms-0.6.1 vendor/bundle/gems/thor-0.14.6/spec/core_ext/hash_with_indifferent_access_spec.rb