Skip to content

Commit 3d8edf7

Browse files
committed
Added a test for Array#flatten that passes in 1.8.7, but fails in 1.9.2 to demonstrate a change in behaviour between the two versions :-
Array#flatten does not call to_ary on an elements if element does not respond to to_ary FAILED Expected to not get NotNoMethodError I'd like to confirm whether this change in behaviour is intentional. See [this Ruby mailing list thread](http://www.ruby-forum.com/topic/450307) and [this Mocha ticket](http://floehopper.lighthouseapp.com/projects/22289/tickets/70) for more details.
1 parent 7dbeac1 commit 3d8edf7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/array/flatten_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@
9898
lambda { [obj].flatten.should == [obj] }.should_not raise_error(NoMethodError)
9999
end
100100

101+
it "does not call to_ary on an elements if element does not respond to to_ary" do
102+
NotNoMethodError = Class.new(StandardError)
103+
obj = Class.new do
104+
def method_missing(symbol, *args, &block)
105+
symbol == :to_ary ? raise(NotNoMethodError) : super
106+
end
107+
def respond_to?(symbol, include_private = false)
108+
symbol == :to_ary ? false : super
109+
end
110+
end.new
111+
lambda { [obj].flatten.should == [obj] }.should_not raise_error(NotNoMethodError)
112+
end
113+
101114
it "ignores the return value of to_ary if it is nil" do
102115
obj = Class.new do
103116
def to_ary

0 commit comments

Comments
 (0)