diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/optional/capi/exception_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi/exception_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/exception_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/exception_spec.rb b/spec/ruby/optional/capi/exception_spec.rb new file mode 100644 index 0000000000..4800e6ffc0 --- /dev/null +++ b/spec/ruby/optional/capi/exception_spec.rb @@ -0,0 +1,58 @@ +require File.expand_path('../spec_helper', __FILE__) + +load_extension("exception") + +describe "C-API Exception function" do + before :each do + @s = CApiExceptionSpecs.new + end + + describe "rb_exc_new" do + it "creates an exception from a C string and length" do + @s.rb_exc_new('foo').to_s.should == 'foo' + end + end + + describe "rb_exc_new2" do + it "creates an exception from a C string" do + @s.rb_exc_new2('foo').to_s.should == 'foo' + end + end + + describe "rb_exc_new3" do + it "creates an exception from a Ruby string" do + @s.rb_exc_new3('foo').to_s.should == 'foo' + end + end + + describe "rb_exc_raise" do + it "raises passed exception" do + runtime_error = RuntimeError.new '42' + lambda { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') + end + + it "raises an exception with an empty backtrace" do + runtime_error = RuntimeError.new '42' + runtime_error.set_backtrace [] + lambda { @s.rb_exc_raise(runtime_error) }.should raise_error(RuntimeError, '42') + end + end + + describe "rb_set_errinfo" do + after :each do + @s.rb_set_errinfo(nil) + end + + it "accepts nil" do + @s.rb_set_errinfo(nil).should be_nil + end + + it "accepts an Exception instance" do + @s.rb_set_errinfo(Exception.new).should be_nil + end + + it "raises a TypeError if the object is not nil or an Exception instance" do + lambda { @s.rb_set_errinfo("error") }.should raise_error(TypeError) + end + end +end |