Skip to content

Commit 10943fc

Browse files
committed
Add a new C API spec for rb_error_frozen_object.
1 parent bddf986 commit 10943fc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

spec/ruby/optional/capi/exception_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@
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+
# The type of the argument we supply doesn't matter. The choice here is arbitrary and we only change the type
106+
# of the argument to ensure the exception messages are set correctly.
107+
-> { @s.rb_error_frozen_object(Hash.new) }.should raise_error(FrozenError, "can't modify frozen Hash")
108+
-> { @s.rb_error_frozen_object(Array.new.freeze) }.should raise_error(FrozenError, "can't modify frozen Array")
109+
end
110+
end
111+
103112
describe "rb_syserr_new" do
104113
it "returns system error with default message when passed message is NULL" do
105114
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)