diff options
author | Andrew White <andrew.white@unboxed.co> | 2016-11-03 14:15:29 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2016-11-03 14:15:29 +0000 |
commit | 7cef8061ab98261887001f8c6fba3f52a85dbaa8 (patch) | |
tree | fa5cedd9411eb24af3094cdc70bc7bedb1f0f6b8 /activesupport/test/core_ext | |
parent | bbe5e07f7a01d4c12767750e6280ce8f56d89070 (diff) | |
download | rails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.tar.gz rails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.tar.bz2 rails-7cef8061ab98261887001f8c6fba3f52a85dbaa8.zip |
Adjust tests for differences between Ruby 1.8 and 1.9
Ruby 1.9 added Hash#select! and return a hash from Hash#select
whereas Ruby 1.8 returned an array.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 8c032dc880..f29b91a324 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -262,16 +262,25 @@ class HashExtTest < Test::Unit::TestCase def test_indifferent_select hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k, v| v == 1 } - assert_equal({ "a" => 1 }, hash) - assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + if RUBY_VERSION > '1.9' + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + else + # Ruby 1.8.7 returns an Array from Hash#select + assert_equal([["a", 1]], hash) + assert_instance_of Array, hash + end end - def test_indifferent_select_bang - indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) - indifferent_strings.select! { |k, v| v == 1 } + if RUBY_VERSION > '1.9' + # Hash#select! was added in Ruby 1.9 + def test_indifferent_select_bang + indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) + indifferent_strings.select! { |k, v| v == 1 } - assert_equal({ "a" => 1 }, indifferent_strings) - assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + assert_equal({ "a" => 1 }, indifferent_strings) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + end end def test_indifferent_reject |