From 5b593e388931490c1e2246d0347c892440167b2c Mon Sep 17 00:00:00 2001 From: eregon Date: Thu, 29 Jun 2017 14:35:37 +0000 Subject: Update to ruby/spec@abf1700 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/rubyspec/core/array/shared/inspect.rb | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec/rubyspec/core/array/shared/inspect.rb') diff --git a/spec/rubyspec/core/array/shared/inspect.rb b/spec/rubyspec/core/array/shared/inspect.rb index 823dd40e7e..6a60781b45 100644 --- a/spec/rubyspec/core/array/shared/inspect.rb +++ b/spec/rubyspec/core/array/shared/inspect.rb @@ -18,6 +18,46 @@ describe :array_inspect, shared: true do items.send(@method).should == "[0, 1, 2]" end + it "does not call #to_s on a String returned from #inspect" do + str = "abc" + str.should_not_receive(:to_s) + + [str].send(@method).should == '["abc"]' + end + + it "calls #to_s on the object returned from #inspect if the Object isn't a String" do + obj = mock("Array#inspect/to_s calls #to_s") + obj.should_receive(:inspect).and_return(obj) + obj.should_receive(:to_s).and_return("abc") + + [obj].send(@method).should == "[abc]" + end + + it "does not call #to_str on the object returned from #inspect when it is not a String" do + obj = mock("Array#inspect/to_s does not call #to_str") + obj.should_receive(:inspect).and_return(obj) + obj.should_not_receive(:to_str) + + [obj].send(@method).should =~ /^\[#\]$/ + end + + it "does not call #to_str on the object returned from #to_s when it is not a String" do + obj = mock("Array#inspect/to_s does not call #to_str on #to_s result") + obj.should_receive(:inspect).and_return(obj) + obj.should_receive(:to_s).and_return(obj) + obj.should_not_receive(:to_str) + + [obj].send(@method).should =~ /^\[#\]$/ + end + + it "does not swallow exceptions raised by #to_s" do + obj = mock("Array#inspect/to_s does not swallow #to_s exceptions") + obj.should_receive(:inspect).and_return(obj) + obj.should_receive(:to_s).and_raise(Exception) + + lambda { [obj].send(@method) }.should raise_error(Exception) + end + it "represents a recursive element with '[...]'" do ArraySpecs.recursive_array.send(@method).should == "[1, \"two\", 3.0, [...], [...], [...], [...], [...]]" ArraySpecs.head_recursive_array.send(@method).should == "[[...], [...], [...], [...], [...], 1, \"two\", 3.0]" -- cgit v1.2.3