Skip to content

Commit 21ced61

Browse files
committed
Add a spec for c function rb_syserr_new_str
1 parent c7a60f6 commit 21ced61

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spec/ruby/optional/capi/exception_spec.rb

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

103+
describe "rb_syserr_new_str" do
104+
it "returns system error with nil message" do
105+
const = Errno::ENOENT
106+
exception = @s.rb_syserr_new_str(const::Errno, nil)
107+
exception.message.should include("No such file or directory")
108+
exception.class.should == Errno::ENOENT
109+
exception.should.is_a?(SystemCallError)
110+
end
111+
112+
it "returns system error with custom message" do
113+
exception = @s.rb_syserr_new_str(Errno::ENOENT::Errno, "custom message")
114+
exception.message.should include("custom message")
115+
exception.class.should == Errno::ENOENT
116+
exception.should.is_a?(SystemCallError)
117+
end
118+
end
119+
103120
describe "rb_make_exception" do
104121
it "returns a RuntimeError when given a String argument" do
105122
e = @s.rb_make_exception(["Message"])

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

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

39+
VALUE exception_spec_rb_syserr_new_str(VALUE self, VALUE num, VALUE msg) {
40+
int n = NUM2INT(num);
41+
return rb_syserr_new_str(n, msg);
42+
}
3943

4044
VALUE exception_spec_rb_make_exception(VALUE self, VALUE ary) {
4145
int argc = RARRAY_LENINT(ary);
@@ -51,6 +55,7 @@ void Init_exception_spec(void) {
5155
rb_define_method(cls, "rb_exc_new3", exception_spec_rb_exc_new3, 1);
5256
rb_define_method(cls, "rb_exc_raise", exception_spec_rb_exc_raise, 1);
5357
rb_define_method(cls, "rb_set_errinfo", exception_spec_rb_set_errinfo, 1);
58+
rb_define_method(cls, "rb_syserr_new_str", exception_spec_rb_syserr_new_str, 2);
5459
rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1);
5560
}
5661

0 commit comments

Comments
 (0)