From 01efbc128d1379d02dd14acf324d011944a1c429 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 19 Dec 2017 21:14:55 +0000 Subject: Handle `FrozenError` if it is available This pull request handles `FrozenError` introduced by Ruby 2.5. Refer https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/61131 Since `FrozenError` is a subclass of `RuntimeError` minitest used by master branch can handle it, though it would be better to handle `FrozenError` explicitly if possible. `FrozenError` does not exist in Ruby 2.4 or lower, `frozen_error_class` handles which exception is expected to be raised. This pull request is intended to be merged to master, then backported to `5-1-stable` to address #31508 --- activesupport/test/abstract_unit.rb | 4 ++++ activesupport/test/core_ext/hash_ext_test.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index 3ac11e0fe0..f214898145 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -38,4 +38,8 @@ class ActiveSupport::TestCase private def jruby_skip(message = "") skip message if defined?(JRUBY_VERSION) end + + def frozen_error_class + Object.const_defined?(:FrozenError) ? FrozenError : RuntimeError + end end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 746d7ad416..17952e9fc7 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -446,7 +446,7 @@ class HashExtTest < ActiveSupport::TestCase original.freeze assert_nothing_raised { original.except(:a) } - assert_raise(RuntimeError) { original.except!(:a) } + assert_raise(frozen_error_class) { original.except!(:a) } end def test_except_does_not_delete_values_in_original -- cgit v1.2.3