-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C extension spec for rb_define_finalizer
- Loading branch information
1 parent
b514a21
commit 71d37fd
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "ruby.h" | ||
#include "rubyspec.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
static VALUE define_finalizer(VALUE self, VALUE obj, VALUE finalizer) { | ||
return rb_define_finalizer(obj, finalizer); | ||
} | ||
|
||
void Init_finalizer_spec(void) { | ||
VALUE cls = rb_define_class("CApiFinalizerSpecs", rb_cObject); | ||
|
||
rb_define_method(cls, "rb_define_finalizer", define_finalizer, 2); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require_relative "spec_helper" | ||
|
||
extension_path = load_extension("finalizer") | ||
|
||
describe "CApiFinalizerSpecs" do | ||
before :each do | ||
@s = CApiFinalizerSpecs.new | ||
end | ||
|
||
describe "rb_define_finalizer" do | ||
it "defines a finalizer on the object" do | ||
code = <<~RUBY | ||
require #{extension_path.dump} | ||
obj = Object.new | ||
finalizer = Proc.new { puts "finalizer run" } | ||
CApiFinalizerSpecs.new.rb_define_finalizer(obj, finalizer) | ||
RUBY | ||
|
||
ruby_exe(code).should == "finalizer run\n" | ||
end | ||
end | ||
end |