Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for ObjectSpace.undefine_finalizer #1185

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion core/objectspace/undefine_finalizer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
require_relative '../../spec_helper'

describe "ObjectSpace.undefine_finalizer" do
it "needs to be reviewed for spec completeness"
it "removes finalizers for an object" do
code = <<~RUBY
obj = Object.new
ObjectSpace.define_finalizer(obj, proc { |id| puts "hello" })
ObjectSpace.undefine_finalizer(obj)
RUBY

ruby_exe(code).should.empty?
end

it "should not remove finalizers for a frozen object" do
code = <<~RUBY
obj = Object.new
ObjectSpace.define_finalizer(obj, proc { |id| print "ok" })
obj.freeze
begin
ObjectSpace.undefine_finalizer(obj)
rescue
end
RUBY

ruby_exe(code).should == "ok"
end

it "should raise when removing finalizers for a frozen object" do
obj = Object.new
obj.freeze
-> { ObjectSpace.undefine_finalizer(obj) }.should raise_error(FrozenError)
end
end