/
hash_with_indifferent_access_spec.rb
43 lines (35 loc) · 1.25 KB
/
hash_with_indifferent_access_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.expand_path(File.dirname(__FILE__) + '/../spec_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
@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