Skip to content

Commit c0353ac

Browse files
committed
Improve specs related to rb_get_alloc_func()
1 parent 9fc322b commit c0353ac

File tree

2 files changed

+65
-61
lines changed

2 files changed

+65
-61
lines changed

spec/ruby/optional/capi/ext/object_spec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ static VALUE speced_allocator_p(VALUE self, VALUE klass) {
374374
return (allocator == speced_allocator) ? Qtrue : Qfalse;
375375
}
376376

377-
static VALUE allocator_nil_p(VALUE self, VALUE klass) {
377+
static VALUE custom_alloc_func_p(VALUE self, VALUE klass) {
378378
rb_alloc_func_t allocator = rb_get_alloc_func(klass);
379-
return allocator ? Qfalse : Qtrue;
379+
return allocator ? Qtrue : Qfalse;
380380
}
381381

382382
void Init_object_spec(void) {
@@ -448,7 +448,7 @@ void Init_object_spec(void) {
448448
rb_define_method(cls, "rb_define_alloc_func", define_alloc_func, 1);
449449
rb_define_method(cls, "rb_undef_alloc_func", undef_alloc_func, 1);
450450
rb_define_method(cls, "speced_allocator?", speced_allocator_p, 1);
451-
rb_define_method(cls, "allocator_nil?", allocator_nil_p, 1);
451+
rb_define_method(cls, "custom_alloc_func?", custom_alloc_func_p, 1);
452452
}
453453

454454
#ifdef __cplusplus

spec/ruby/optional/capi/object_spec.rb

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -886,74 +886,78 @@ def reach
886886
o.instance_variables.should == []
887887
end
888888
end
889+
end
889890

890-
describe "allocator accessors" do
891-
describe "rb_define_alloc_func" do
892-
it "sets up the allocator" do
893-
klass = Class.new
894-
@o.rb_define_alloc_func(klass)
895-
obj = klass.allocate
896-
obj.class.should.equal?(klass)
897-
obj.should have_instance_variable(:@from_custom_allocator)
898-
end
891+
describe "allocator accessors" do
892+
describe "rb_define_alloc_func" do
893+
it "sets up the allocator" do
894+
klass = Class.new
895+
@o.rb_define_alloc_func(klass)
896+
obj = klass.allocate
897+
obj.class.should.equal?(klass)
898+
obj.should have_instance_variable(:@from_custom_allocator)
899+
end
899900

900-
it "sets up the allocator for a subclass of String" do
901-
klass = Class.new(String)
902-
@o.rb_define_alloc_func(klass)
903-
obj = klass.allocate
904-
obj.class.should.equal?(klass)
905-
obj.should have_instance_variable(:@from_custom_allocator)
906-
obj.should == ""
907-
end
901+
it "sets up the allocator for a subclass of String" do
902+
klass = Class.new(String)
903+
@o.rb_define_alloc_func(klass)
904+
obj = klass.allocate
905+
obj.class.should.equal?(klass)
906+
obj.should have_instance_variable(:@from_custom_allocator)
907+
obj.should == ""
908+
end
908909

909-
it "sets up the allocator for a subclass of Array" do
910-
klass = Class.new(Array)
911-
@o.rb_define_alloc_func(klass)
912-
obj = klass.allocate
913-
obj.class.should.equal?(klass)
914-
obj.should have_instance_variable(:@from_custom_allocator)
915-
obj.should == []
916-
end
910+
it "sets up the allocator for a subclass of Array" do
911+
klass = Class.new(Array)
912+
@o.rb_define_alloc_func(klass)
913+
obj = klass.allocate
914+
obj.class.should.equal?(klass)
915+
obj.should have_instance_variable(:@from_custom_allocator)
916+
obj.should == []
917917
end
918+
end
918919

919-
describe "rb_get_alloc_func" do
920-
it "gets the allocator that is defined directly on a class" do
921-
klass = Class.new
922-
@o.rb_define_alloc_func(klass)
923-
@o.speced_allocator?(Object).should be_false
924-
@o.speced_allocator?(klass).should be_true
925-
end
920+
describe "rb_get_alloc_func" do
921+
it "gets the allocator that is defined directly on a class" do
922+
klass = Class.new
923+
@o.rb_define_alloc_func(klass)
924+
@o.speced_allocator?(Object).should == false
925+
@o.speced_allocator?(klass).should == true
926+
end
926927

927-
it "gets the allocator that is inherited" do
928-
parent = Class.new
929-
@o.rb_define_alloc_func(parent)
930-
klass = Class.new(parent)
931-
@o.speced_allocator?(Object).should be_false
932-
@o.speced_allocator?(klass).should be_true
933-
end
928+
it "gets the allocator that is inherited" do
929+
parent = Class.new
930+
@o.rb_define_alloc_func(parent)
931+
klass = Class.new(parent)
932+
@o.speced_allocator?(Object).should == false
933+
@o.speced_allocator?(klass).should == true
934934
end
935+
end
935936

936-
describe "rb_undef_alloc_func" do
937-
it "does nothing when called on a class without a custom allocator" do
938-
-> { @o.allocator_nil?(Class.new) }.should_not raise_error
939-
end
937+
describe "rb_undef_alloc_func" do
938+
it "makes rb_get_alloc_func() return NULL for a class without a custom allocator" do
939+
klass = Class.new
940+
@o.rb_undef_alloc_func(klass)
941+
@o.custom_alloc_func?(klass).should == false
942+
end
940943

941-
it "undefs the allocator for the class" do
942-
klass = Class.new
943-
@o.rb_define_alloc_func(klass)
944-
@o.speced_allocator?(klass).should be_true
945-
@o.rb_undef_alloc_func(klass)
946-
@o.allocator_nil?(klass).should be_true
947-
end
944+
it "undefs the allocator for the class" do
945+
klass = Class.new
946+
@o.rb_define_alloc_func(klass)
947+
@o.speced_allocator?(klass).should == true
948+
@o.rb_undef_alloc_func(klass)
949+
@o.custom_alloc_func?(klass).should == false
950+
end
948951

949-
it "undefs the allocator for a class that inherits a allocator" do
950-
parent = Class.new
951-
@o.rb_define_alloc_func(parent)
952-
klass = Class.new(parent)
953-
@o.speced_allocator?(klass).should be_true
954-
@o.rb_undef_alloc_func(klass)
955-
@o.allocator_nil?(klass).should be_true
956-
end
952+
it "undefs the allocator for a class that inherits a allocator" do
953+
parent = Class.new
954+
@o.rb_define_alloc_func(parent)
955+
klass = Class.new(parent)
956+
@o.speced_allocator?(klass).should == true
957+
@o.rb_undef_alloc_func(klass)
958+
@o.custom_alloc_func?(klass).should == false
959+
960+
@o.speced_allocator?(parent).should == true
957961
end
958962
end
959963
end

0 commit comments

Comments
 (0)