spec/framework_spec/app/spec/language/string_spec.rb in rhodes-3.1.1 vs spec/framework_spec/app/spec/language/string_spec.rb in rhodes-3.2.0.beta.1

- old
+ new

@@ -1,6 +1,6 @@ -require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../spec_helper' +require File.expand_path('../../spec_helper', __FILE__) # Thanks http://www.zenspider.com/Languages/Ruby/QuickRef.html describe "Ruby character strings" do @@ -68,11 +68,11 @@ %|hey #{@ip}|.should == "hey xxx" %?hey #{@ip}?.should == "hey xxx" %/hey #{@ip}/.should == "hey xxx" %,hey #{@ip},.should == "hey xxx" %.hey #{@ip}..should == "hey xxx" - + # surprised? huh %'hey #{@ip}'.should == "hey xxx" %\hey #{@ip}\.should == "hey xxx" %`hey #{@ip}`.should == "hey xxx" %$hey #{@ip}$.should == "hey xxx" @@ -90,11 +90,11 @@ # # \t (tab), \n (newline), \r (carriage return), \f (form feed), \b # (backspace), \a (bell), \e (escape), \s (whitespace), \nnn (octal), # \xnn (hexadecimal), \cx (control x), \C-x (control x), \M-x (meta x), # \M-\C-x (meta control x) - + it "backslashes follow the same rules as interpolation" do "\t\n\r\f\b\a\e\s\075\x62\cx".should == "\t\n\r\f\b\a\e =b\030" '\t\n\r\f\b\a\e =b\030'.should == "\\t\\n\\r\\f\\b\\a\\e =b\\030" end @@ -102,11 +102,11 @@ s = <<HERE foo bar#{@ip} HERE s.should == "foo barxxx\n" end - + it 'allow HEREDOC with <<"identifier", interpolated' do s = <<"HERE" foo bar#{@ip} HERE s.should == "foo barxxx\n" @@ -116,34 +116,69 @@ s = <<'HERE' foo bar#{@ip} HERE s.should == 'foo bar#{@ip}' + "\n" end - + it "allow HEREDOC with <<-identifier, allowing to indent identifier, interpolated" do s = <<-HERE foo bar#{@ip} HERE s.should == " foo barxxx\n" end - + it 'allow HEREDOC with <<-"identifier", allowing to indent identifier, interpolated' do s = <<-"HERE" foo bar#{@ip} HERE s.should == " foo barxxx\n" end - + it "allow HEREDOC with <<-'identifier', allowing to indent identifier, no interpolation" do s = <<-'HERE' foo bar#{@ip} HERE s.should == ' foo bar#{@ip}' + "\n" end + it "call #to_s when the object is not a String" do + obj = mock('to_s') + obj.stub!(:to_s).and_return('42') + + "#{obj}".should == '42' + end + + it "call #to_s as a private method" do + obj = mock('to_s') + obj.stub!(:to_s).and_return('42') + + class << obj + private :to_s + end + + "#{obj}".should == '42' + end + + it "uses an internal representation when #to_s doesn't return a String" do + obj = mock('to_s') + obj.stub!(:to_s).and_return(42) + + # See rubyspec commit 787c132d by yugui. There is value in + # ensuring that this behavior works. So rather than removing + # this spec completely, the only thing that can be asserted + # is that if you interpolate an object that fails to return + # a String, you will still get a String and not raise an + # exception. + "#{obj}".should be_an_instance_of(String) + end + + it "allow a dynamic string to parse a nested do...end block as an argument to a call without parens, interpolated" do + s = eval 'eval "#{proc do; 1; end.call}"' + s.should == 1 + end ruby_version_is '1.9' do it "are produced from character shortcuts" do ?z.should == 'z' end