git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-06-29 14:35:37 +00:00
parent 6a4aa4838c
commit 5b593e3889
79 changed files with 1555 additions and 304 deletions

View file

@ -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

View file

@ -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]"