summaryrefslogtreecommitdiff
path: root/spec/ruby/core/exception
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-21 15:38:59 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-21 15:38:59 +0000
commitda7976235fbc2986925969646071bebe3702e49f (patch)
tree83bbf6a8e03cf990369feabe6c1c9d45c69f4c85 /spec/ruby/core/exception
parentb8e389a0f3226c90e96e02e6396686a3bef6a456 (diff)
Update to ruby/spec@7a16e01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r--spec/ruby/core/exception/cause_spec.rb25
-rw-r--r--spec/ruby/core/exception/dup_spec.rb13
-rw-r--r--spec/ruby/core/exception/full_message_spec.rb19
3 files changed, 57 insertions, 0 deletions
diff --git a/spec/ruby/core/exception/cause_spec.rb b/spec/ruby/core/exception/cause_spec.rb
index 736ff1a046..007df41366 100644
--- a/spec/ruby/core/exception/cause_spec.rb
+++ b/spec/ruby/core/exception/cause_spec.rb
@@ -16,4 +16,29 @@ describe "Exception#cause" do
end
end
end
+
+ it "is set for user errors caused by internal errors" do
+ -> {
+ begin
+ 1 / 0
+ rescue
+ raise "foo"
+ end
+ }.should raise_error(RuntimeError) { |e|
+ e.cause.should be_kind_of(ZeroDivisionError)
+ }
+ end
+
+ it "is set for internal errors caused by user errors" do
+ cause = RuntimeError.new "cause"
+ -> {
+ begin
+ raise cause
+ rescue
+ 1 / 0
+ end
+ }.should raise_error(ZeroDivisionError) { |e|
+ e.cause.should equal(cause)
+ }
+ end
end
diff --git a/spec/ruby/core/exception/dup_spec.rb b/spec/ruby/core/exception/dup_spec.rb
index 3ad1fc063b..c7fcd280dd 100644
--- a/spec/ruby/core/exception/dup_spec.rb
+++ b/spec/ruby/core/exception/dup_spec.rb
@@ -58,4 +58,17 @@ describe "Exception#dup" do
@obj.dup.backtrace.should == @obj.backtrace
end
+
+ it "does copy the cause" do
+ begin
+ raise StandardError, "the cause"
+ rescue StandardError => cause
+ begin
+ raise RuntimeError, "the consequence"
+ rescue RuntimeError => e
+ e.cause.should equal(cause)
+ e.dup.cause.should equal(cause)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb
index bc611c165b..3df2d47f61 100644
--- a/spec/ruby/core/exception/full_message_spec.rb
+++ b/spec/ruby/core/exception/full_message_spec.rb
@@ -33,6 +33,25 @@ ruby_version_is "2.5" do
e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
end
+
+ it "shows the caller if the exception has no backtrace" do
+ e = RuntimeError.new("Some runtime error")
+ e.backtrace.should == nil
+ full_message = e.full_message(highlight: false, order: :top)
+ full_message.should include("#{__FILE__}:#{__LINE__-1}:in `")
+ full_message.should include("': Some runtime error (RuntimeError)\n")
+ end
+
+ it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
+ begin
+ line = __LINE__; raise "first line\nsecond line"
+ rescue => e
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should include("#{__FILE__}:#{line}:in `")
+ full_message[0].should include(": first line (RuntimeError)\n")
+ full_message[1].should == "second line\n"
+ end
+ end
end
ruby_version_is "2.6" do