HashWithIndifferentAccess test

This commit is contained in:
Mitchell Hashimoto 2011-12-26 17:27:56 -08:00
parent 91562e2111
commit 15a625275e
2 changed files with 38 additions and 39 deletions

View File

@ -0,0 +1,38 @@
require File.expand_path("../../../base", __FILE__)
require "vagrant/util/hash_with_indifferent_access"
describe Vagrant::Util::HashWithIndifferentAccess do
let(:instance) { described_class.new }
it "is a Hash" do
instance.should be_kind_of(Hash)
end
it "allows indifferent access when setting with a string" do
instance["foo"] = "bar"
instance[:foo].should == "bar"
end
it "allows indifferent access when setting with a symbol" do
instance[:foo] = "bar"
instance["foo"].should == "bar"
end
it "allows indifferent key lookup" do
instance["foo"] = "bar"
instance.key?(:foo).should be
instance.has_key?(:foo).should be
instance.include?(:foo).should be
instance.member?(:foo).should be
end
it "allows for defaults to be passed in via an initializer block" do
instance = described_class.new do |h,k|
h[k] = "foo"
end
instance[:foo].should == "foo"
instance["bar"].should == "foo"
end
end

View File

@ -1,39 +0,0 @@
require "test_helper"
class HashWithIndifferentAccessUtilTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Util::HashWithIndifferentAccess
@instance = @klass.new
end
should "be a hash" do
assert @instance.is_a?(Hash)
end
should "allow indifferent access when setting with a string" do
@instance["foo"] = "bar"
assert_equal "bar", @instance[:foo]
end
should "allow indifferent access when setting with a symbol" do
@instance[:foo] = "bar"
assert_equal "bar", @instance["foo"]
end
should "allow indifferent key lookup" do
@instance["foo"] = "bar"
assert @instance.key?(:foo)
assert @instance.has_key?(:foo)
assert @instance.include?(:foo)
assert @instance.member?(:foo)
end
should "forward up block to Hash if given to initializer" do
instance = @klass.new do |h,k|
h[k] = "foo"
end
assert_equal "foo", instance[:foo]
assert_equal "foo", instance["foo"]
end
end