diff --git a/spec/ruby/core/string/setbyte_spec.rb b/spec/ruby/core/string/setbyte_spec.rb index 910a55363b..143955ef51 100644 --- a/spec/ruby/core/string/setbyte_spec.rb +++ b/spec/ruby/core/string/setbyte_spec.rb @@ -18,7 +18,7 @@ str = "a" str.setbyte(0,98) str.should == 'b' - + # copy-on-write case str1, str2 = "fooXbar".split("X") str2.setbyte(0, 50) @@ -66,6 +66,16 @@ chr.should == "\xe0\xa6\x96" end + it "does not modify the original string when using String.new" do + str1 = "hedgehog" + str2 = String.new(str1) + str2.setbyte(0, 108) + str2.should == "ledgehog" + str2.should_not == "hedgehog" + str1.should == "hedgehog" + str1.should_not == "ledgehog" + end + it "raises a RuntimeError if self is frozen" do str = "cold".freeze str.frozen?.should be_true