describe "String indexing" do before :each do @string = "foo" end it "should return first character's ASCII value for position 0" do @string[0].should == ?f end it "should return las character's ASCII value for position -1" do @string[-1].should == ?o end it "should return the first two characters for substring 0..1" do @string[0..1].should == "fo" end it "should return the last two characters for substring -2..-1" do @string[-2..-1].should == "oo" end it "should replace the second character with a new substring" do @string[1] = "id" @string.should == "fido" end it "should become empty when 0..-1 is set to empty string" do @string[0..-1] = "" @string.should be_empty # calls string.empty? end end describe "String case manipulation" do before :each do @string = "fOo" end it "should be converted to all caps when upcase is sent" do @string.upcase.should == "FOO" end it "should start with a capital letter followed by lowercase when capitalized" do @string.capitalize.should == "Foo" end it "should be converted to all lowercase when downcase is sent" do @string.downcase.should == "foo" end end