Skip to content

Commit c6d77b3

Browse files
committed
Added a version check for the exception assertions.
1 parent c6f6347 commit c6d77b3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

test/test_tree.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,18 @@ def test_freeze_tree_bang
941941
assert_equal('ABC', @root.content, "Content should be 'ABC'")
942942
@root.freeze_tree!
943943
# Note: The error raised here depends on the Ruby version.
944-
# For Ruby > 2.6, FrozenError is raised
944+
# For Ruby > 2.5, FrozenError is raised
945945
# For Ruby > 1.9, RuntimeError is raised
946946
# For Ruby ~ 1.8, TypeError is raised
947-
assert_raise(RuntimeError, FrozenError, TypeError) {@root.content = '123'}
948-
assert_raise(RuntimeError, FrozenError, TypeError) {@root[0].content = '123'}
947+
require 'rubygems' # Only needed for ruby pre-1.9.0 but it's safe for later versions (evaluates to false).
948+
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.9.0')
949+
assert_raise(RuntimeError, TypeError) {@root.content = '123'}
950+
assert_raise(RuntimeError, TypeError) {@root[0].content = '123'}
951+
else
952+
assert_raise(FrozenError) {@root.content = '123'}
953+
assert_raise(FrozenError) {@root[0].content = '123'}
954+
end
955+
949956
end
950957

951958
# Test whether the content is accessible

0 commit comments

Comments
 (0)