diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-29 14:35:37 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-29 14:35:37 +0000 |
commit | 5b593e388931490c1e2246d0347c892440167b2c (patch) | |
tree | 70d928d35c01b51bb9a6cdc44af4bd7cc05a669b /spec/rubyspec/core/array | |
parent | 6a4aa4838cc53a520044b86deb4ecddb57bca876 (diff) |
Update to ruby/spec@abf1700
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/core/array')
-rw-r--r-- | spec/rubyspec/core/array/element_set_spec.rb | 23 | ||||
-rw-r--r-- | spec/rubyspec/core/array/shared/inspect.rb | 40 |
2 files changed, 51 insertions, 12 deletions
diff --git a/spec/rubyspec/core/array/element_set_spec.rb b/spec/rubyspec/core/array/element_set_spec.rb index 280b507fc4..6544ad9b6f 100644 --- a/spec/rubyspec/core/array/element_set_spec.rb +++ b/spec/rubyspec/core/array/element_set_spec.rb @@ -258,12 +258,12 @@ describe "Array#[]= with [index]" do end it "sets the value of the element at index" do - a = [1, 2, 3, 4] - a[2] = 5 - a[-1] = 6 - a[5] = 3 - a.should == [1, 2, 5, 6, nil, 3] - end + a = [1, 2, 3, 4] + a[2] = 5 + a[-1] = 6 + a[5] = 3 + a.should == [1, 2, 5, 6, nil, 3] + end it "sets the value of the element if it is right beyond the array boundary" do a = [1, 2, 3, 4] @@ -370,11 +370,11 @@ describe "Array#[]= with [m..n]" do end it "replaces the section defined by range" do - a = [6, 5, 4, 3, 2, 1] - a[1...2] = 9 - a[3..6] = [6, 6, 6] - a.should == [6, 9, 4, 6, 6, 6] - end + a = [6, 5, 4, 3, 2, 1] + a[1...2] = 9 + a[3..6] = [6, 6, 6] + a.should == [6, 9, 4, 6, 6, 6] + end it "replaces the section if m and n < 0" do a = [1, 2, 3, 4, 5] @@ -415,4 +415,3 @@ describe "Array#[] after a shift" do a.should == [3,4] end end - 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 =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/ + 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 =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/ + 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]" |