Skip to content

Commit 7dbeac1

Browse files
committed
Improved test coverage for Array#flatten.
These tests pass for me on 1.8.7 (2010-08-16 patchlevel 302) and 1.9.2p14 (2010-10-02 revision 29393).
1 parent bbdd2a8 commit 7dbeac1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

core/array/flatten_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@
9292
ary.flatten
9393
ary.should == [1, [2, 3]]
9494
end
95+
96+
it "ignores NoMethodError raised by calling to_ary on element with no to_ary method" do
97+
obj = Object.new
98+
lambda { [obj].flatten.should == [obj] }.should_not raise_error(NoMethodError)
99+
end
100+
101+
it "ignores the return value of to_ary if it is nil" do
102+
obj = Class.new do
103+
def to_ary
104+
nil
105+
end
106+
end.new
107+
[obj].flatten.should == [obj]
108+
end
109+
110+
it "raises TypeError if return value of to_ary is not an Array" do
111+
obj = Class.new do
112+
def to_ary
113+
1
114+
end
115+
end.new
116+
lambda { [obj].flatten }.should raise_error(TypeError)
117+
end
118+
95119
end
96120

97121
describe "Array#flatten!" do

0 commit comments

Comments
 (0)