Skip to content

Instantly share code, notes, and snippets.

@djberg96
Last active May 19, 2016 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djberg96/649c423d6a338d6b4694b5cbde77205c to your computer and use it in GitHub Desktop.
Save djberg96/649c423d6a338d6b4694b5cbde77205c to your computer and use it in GitHub Desktop.
require 'test/unit'
require 'weakref'
# Result: <WeakRef::RefError> exception expected but none was thrown - why?
class TC_Stdlib_WeakRef < Test::Unit::TestCase
test "weakref raises an error on garbage collected ref" do
str = 'hello'
ref = WeakRef.new(str)
str = nil
GC.start
assert_raise(WeakRef::RefError){ ref.to_s }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment