Skip to content

Commit cc79c2f

Browse files
bjfisheregon
authored andcommitted
Implement Kernel#raise cause parameter
1 parent aa6c9d6 commit cc79c2f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/kernel/raise_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727

2828
ScratchPad.recorded.should be_nil
2929
end
30+
31+
ruby_version_is "2.6" do
32+
it "accepts a cause keyword argument that sets the cause" do
33+
cause = StandardError.new
34+
-> { raise("error", cause: cause) }.should raise_error(RuntimeError) { |e| e.cause.should == cause }
35+
end
36+
37+
it "accepts a cause keyword argument that overrides the last exception" do
38+
begin
39+
raise "first raise"
40+
rescue => e
41+
cause = StandardError.new
42+
-> { raise("error", cause: cause) }.should raise_error(RuntimeError) { |e| e.cause.should == cause }
43+
end
44+
end
45+
46+
it "raises an ArgumentError when only cause is given" do
47+
cause = StandardError.new
48+
-> { raise(cause: cause) }.should raise_error(ArgumentError)
49+
end
50+
end
3051
end
3152

3253
describe "Kernel#raise" do

0 commit comments

Comments
 (0)