Permalink
Browse files

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).
  • Loading branch information...
floehopper committed Nov 18, 2010
1 parent bbdd2a8 commit 7dbeac153443b12a6eb2993bc3f15d14073f51fe
Showing with 24 additions and 0 deletions.
  1. +24 −0 core/array/flatten_spec.rb
View
@@ -92,6 +92,30 @@
ary.flatten
ary.should == [1, [2, 3]]
end
it "ignores NoMethodError raised by calling to_ary on element with no to_ary method" do
obj = Object.new
lambda { [obj].flatten.should == [obj] }.should_not raise_error(NoMethodError)
end
it "ignores the return value of to_ary if it is nil" do
obj = Class.new do
def to_ary
nil
end
end.new
[obj].flatten.should == [obj]
end
it "raises TypeError if return value of to_ary is not an Array" do
obj = Class.new do
def to_ary
1
end
end.new
lambda { [obj].flatten }.should raise_error(TypeError)
end
end
describe "Array#flatten!" do

0 comments on commit 7dbeac1

Please sign in to comment.