diff options
Diffstat (limited to 'spec/ruby/core/array/plus_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/plus_spec.rb | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/spec/ruby/core/array/plus_spec.rb b/spec/ruby/core/array/plus_spec.rb index 7692163980..7ead927fc0 100644 --- a/spec/ruby/core/array/plus_spec.rb +++ b/spec/ruby/core/array/plus_spec.rb @@ -14,10 +14,23 @@ describe "Array#+" do (ary + ary).should == [1, 2, 3, 1, 2, 3] end - it "tries to convert the passed argument to an Array using #to_ary" do - obj = mock('["x", "y"]') - obj.should_receive(:to_ary).and_return(["x", "y"]) - ([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"] + describe "converts the passed argument to an Array using #to_ary" do + it "successfully concatenates the resulting array from the #to_ary call" do + obj = mock('["x", "y"]') + obj.should_receive(:to_ary).and_return(["x", "y"]) + ([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"] + end + + it "raises a TypeError if the given argument can't be converted to an array" do + -> { [1, 2, 3] + nil }.should.raise(TypeError) + -> { [1, 2, 3] + "abc" }.should.raise(TypeError) + end + + it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to an Array" do + obj = mock("hello") + obj.should_receive(:to_ary).and_raise(NoMethodError) + -> { [1, 2, 3] + obj }.should.raise(NoMethodError) + end end it "properly handles recursive arrays" do @@ -32,26 +45,12 @@ describe "Array#+" do end it "does return subclass instances with Array subclasses" do - (ArraySpecs::MyArray[1, 2, 3] + []).should be_an_instance_of(Array) - (ArraySpecs::MyArray[1, 2, 3] + ArraySpecs::MyArray[]).should be_an_instance_of(Array) - ([1, 2, 3] + ArraySpecs::MyArray[]).should be_an_instance_of(Array) + (ArraySpecs::MyArray[1, 2, 3] + []).should.instance_of?(Array) + (ArraySpecs::MyArray[1, 2, 3] + ArraySpecs::MyArray[]).should.instance_of?(Array) + ([1, 2, 3] + ArraySpecs::MyArray[]).should.instance_of?(Array) end it "does not call to_ary on array subclasses" do ([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2] end - - it "does not get infected even if an original array is tainted" do - ([1, 2] + [3, 4]).tainted?.should be_false - ([1, 2].taint + [3, 4]).tainted?.should be_false - ([1, 2] + [3, 4].taint).tainted?.should be_false - ([1, 2].taint + [3, 4].taint).tainted?.should be_false - end - - it "does not infected even if an original array is untrusted" do - ([1, 2] + [3, 4]).untrusted?.should be_false - ([1, 2].untrust + [3, 4]).untrusted?.should be_false - ([1, 2] + [3, 4].untrust).untrusted?.should be_false - ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false - end end |
