Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added specs for Array#flatten flattening anything that responds to #t…

…o_ary
  • Loading branch information...
commit 738df6bd3bfd46dad9f9e101433b18bfa56d05f0 1 parent 808c8ff
Daniel Luz mernen authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 1.8/core/array/flatten_spec.rb
14 1.8/core/array/flatten_spec.rb
View
@@ -55,6 +55,20 @@
y << x
lambda { x.flatten }.should raise_error(ArgumentError)
end
+
+ it "flattens any element which responds to #to_ary, using the return value of said method" do
+ x = mock("[3,4]")
+ x.should_receive(:to_ary).at_least(:once).and_return([3, 4])
+ [1, 2, x, 5].flatten.should == [1, 2, 3, 4, 5]
+
+ y = mock("MyArray[]")
+ y.should_receive(:to_ary).at_least(:once).and_return(ArraySpecs::MyArray[])
+ [y].flatten.should == []
+
+ z = mock("[2,x,y,5]")
+ z.should_receive(:to_ary).and_return([2, x, y, 5])
+ [1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6]
+ end
it "returns subclass instance for Array subclasses" do
ArraySpecs::MyArray[].flatten.class.should == ArraySpecs::MyArray
Please sign in to comment.
Something went wrong with that request. Please try again.