spec/hamster/hash/put_spec.rb in hamster-1.0.1.pre.rc.1 vs spec/hamster/hash/put_spec.rb in hamster-1.0.1.pre.rc2
- old
+ new
@@ -1,19 +1,15 @@
require "spec_helper"
-
require "hamster/hash"
describe Hamster::Hash do
-
describe "#put" do
-
before do
@original = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see")
end
describe "with a block" do
-
it "passes the value to the block" do
@original.put("A") { |value| value.should == "aye" }
end
it "replaces the value with the result of the block" do
@@ -23,15 +19,13 @@
it "supports to_proc methods" do
result = @original.put("A", &:upcase)
result.get("A").should == "AYE"
end
-
end
describe "with a unique key" do
-
before do
@result = @original.put("D", "dee")
end
it "preserves the original" do
@@ -39,15 +33,13 @@
end
it "returns a copy with the superset of key/value pairs" do
@result.should == Hamster.hash("A" => "aye", "B" => "bee", "C" => "see", "D" => "dee")
end
-
end
describe "with a duplicate key" do
-
before do
@result = @original.put("C", "sea")
end
it "preserves the original" do
@@ -55,11 +47,21 @@
end
it "returns a copy with the superset of key/value pairs" do
@result.should == Hamster.hash("A" => "aye", "B" => "bee", "C" => "sea")
end
-
end
- end
+ context "when a String is inserted as key and then mutated" do
+ before do
+ @string = "a string!"
+ @hash = Hamster.hash(@string => 'a value!')
+ @string.upcase!
+ end
-end
+ it "is not affected" do
+ @hash['a string!'].should == 'a value!'
+ @hash['A STRING!'].should be_nil
+ end
+ end
+ end
+end
\ No newline at end of file