Skip to content

Commit d845859

Browse files
committed
Add a new C API spec for rb_error_frozen_object.
1 parent 5f5dbac commit d845859

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

spec/ruby/optional/capi/exception_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
end
101101
end
102102

103+
describe "rb_error_frozen_object" do
104+
it "raises a FrozenError regardless of the object's frozen state" do
105+
-> { @s.rb_error_frozen_object(Object.new) }.should raise_error(FrozenError)
106+
-> { @s.rb_error_frozen_object(Object.new.freeze) }.should raise_error(FrozenError)
107+
end
108+
end
109+
103110
describe "rb_syserr_new" do
104111
it "returns system error with default message when passed message is NULL" do
105112
exception = @s.rb_syserr_new(Errno::ENOENT::Errno, nil)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ VALUE exception_spec_rb_set_errinfo(VALUE self, VALUE exc) {
3636
return Qnil;
3737
}
3838

39+
VALUE exception_spec_rb_error_frozen_object(VALUE self, VALUE object) {
40+
rb_error_frozen_object(object);
41+
return Qnil;
42+
}
43+
3944
VALUE exception_spec_rb_syserr_new(VALUE self, VALUE num, VALUE msg) {
4045
int n = NUM2INT(num);
4146
char *cstr = NULL;
@@ -66,6 +71,7 @@ void Init_exception_spec(void) {
6671
rb_define_method(cls, "rb_exc_new3", exception_spec_rb_exc_new3, 1);
6772
rb_define_method(cls, "rb_exc_raise", exception_spec_rb_exc_raise, 1);
6873
rb_define_method(cls, "rb_set_errinfo", exception_spec_rb_set_errinfo, 1);
74+
rb_define_method(cls, "rb_error_frozen_object", exception_spec_rb_error_frozen_object, 1);
6975
rb_define_method(cls, "rb_syserr_new", exception_spec_rb_syserr_new, 2);
7076
rb_define_method(cls, "rb_syserr_new_str", exception_spec_rb_syserr_new_str, 2);
7177
rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1);

0 commit comments

Comments
 (0)