diff options
author | Xavier Noria <fxn@hashref.com> | 2010-07-28 03:49:04 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-07-28 03:49:04 +0200 |
commit | e17e08efef68e9865cfbd5c0155b3d9734339192 (patch) | |
tree | 89cb96a7d2c6a3c152af9fdbbd1b58e1334eaa28 /activesupport/test/core_ext | |
parent | 5d3e8ee2bdd2225fe6e610c7e465bb69234871ed (diff) | |
download | rails-e17e08efef68e9865cfbd5c0155b3d9734339192.tar.gz rails-e17e08efef68e9865cfbd5c0155b3d9734339192.tar.bz2 rails-e17e08efef68e9865cfbd5c0155b3d9734339192.zip |
adds test coverage for edge-cases of Array.wrap, and better documentation for how it differs from Kernel#Array
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 54376deee5..009a254c64 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -398,6 +398,18 @@ class ArrayWrapperTests < Test::Unit::TestCase def method_missing(*a) @target.send(*a) end end + class DoubtfulToAry + def to_ary + :not_an_array + end + end + + class NilToAry + def to_ary + nil + end + end + def test_array ary = %w(foo bar) assert_same ary, Array.wrap(ary) @@ -438,4 +450,12 @@ class ArrayWrapperTests < Test::Unit::TestCase o = Struct.new(:foo).new(123) assert_equal [o], Array.wrap(o) end + + def test_wrap_returns_nil_if_to_ary_returns_nil + assert_nil Array.wrap(NilToAry.new) + end + + def test_wrap_does_not_complain_if_to_ary_does_not_return_an_array + assert_equal DoubtfulToAry.new.to_ary, Array.wrap(DoubtfulToAry.new) + end end |