From 15a625275ea080d0e1b1f9d53e1179799a5eeb03 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 26 Dec 2011 17:27:56 -0800 Subject: [PATCH] HashWithIndifferentAccess test --- .../util/hash_with_indifferent_access_test.rb | 38 ++++++++++++++++++ .../util/hash_with_indifferent_access_test.rb | 39 ------------------- 2 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 test/unit/vagrant/util/hash_with_indifferent_access_test.rb delete mode 100644 test/unit_legacy/vagrant/util/hash_with_indifferent_access_test.rb diff --git a/test/unit/vagrant/util/hash_with_indifferent_access_test.rb b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb new file mode 100644 index 000000000..82356dc00 --- /dev/null +++ b/test/unit/vagrant/util/hash_with_indifferent_access_test.rb @@ -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 diff --git a/test/unit_legacy/vagrant/util/hash_with_indifferent_access_test.rb b/test/unit_legacy/vagrant/util/hash_with_indifferent_access_test.rb deleted file mode 100644 index b4a8058e8..000000000 --- a/test/unit_legacy/vagrant/util/hash_with_indifferent_access_test.rb +++ /dev/null @@ -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