summaryrefslogtreecommitdiff
path: root/spec/ruby/core/exception
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-08 19:43:27 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-01 15:36:20 +0900
commit826f44834fe11f3f9c52343443a15b6c83466889 (patch)
treef2c2abed62db1c750515cd8b0fbac6442b6d4200 /spec/ruby/core/exception
parent3a2073e61b6ccce6d07d31ebd89d4c385b9a55f2 (diff)
Drop support for ruby 2.4 from ruby/spec
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2892
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r--spec/ruby/core/exception/full_message_spec.rb134
-rw-r--r--spec/ruby/core/exception/hierarchy_spec.rb8
2 files changed, 70 insertions, 72 deletions
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb
index 3df2d47f61..9cac9fb037 100644
--- a/spec/ruby/core/exception/full_message_spec.rb
+++ b/spec/ruby/core/exception/full_message_spec.rb
@@ -1,94 +1,92 @@
require_relative '../../spec_helper'
-ruby_version_is "2.5" do
- describe "Exception#full_message" do
- it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do
- e = RuntimeError.new("Some runtime error")
- e.set_backtrace(["a.rb:1", "b.rb:2"])
+describe "Exception#full_message" do
+ it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do
+ e = RuntimeError.new("Some runtime error")
+ e.set_backtrace(["a.rb:1", "b.rb:2"])
- full_message = e.full_message
- full_message.should include "RuntimeError"
- full_message.should include "Some runtime error"
- full_message.should include "a.rb:1"
- full_message.should include "b.rb:2"
- end
+ full_message = e.full_message
+ full_message.should include "RuntimeError"
+ full_message.should include "Some runtime error"
+ full_message.should include "a.rb:1"
+ full_message.should include "b.rb:2"
+ end
- ruby_version_is "2.5.1" do
- it "supports :highlight option and adds escape sequences to highlight some strings" do
- e = RuntimeError.new("Some runtime error")
+ ruby_version_is "2.5.1" do
+ it "supports :highlight option and adds escape sequences to highlight some strings" do
+ e = RuntimeError.new("Some runtime error")
- full_message = e.full_message(highlight: true, order: :bottom)
- full_message.should include "\e[1mTraceback\e[m (most recent call last)"
- full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
+ full_message = e.full_message(highlight: true, order: :bottom)
+ full_message.should include "\e[1mTraceback\e[m (most recent call last)"
+ full_message.should include "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)"
- full_message = e.full_message(highlight: false, order: :bottom)
- full_message.should include "Traceback (most recent call last)"
- full_message.should include "Some runtime error (RuntimeError)"
- end
+ full_message = e.full_message(highlight: false, order: :bottom)
+ full_message.should include "Traceback (most recent call last)"
+ full_message.should include "Some runtime error (RuntimeError)"
+ end
- it "supports :order option and places the error message and the backtrace at the top or the bottom" do
- e = RuntimeError.new("Some runtime error")
- e.set_backtrace(["a.rb:1", "b.rb:2"])
+ it "supports :order option and places the error message and the backtrace at the top or the bottom" do
+ e = RuntimeError.new("Some runtime error")
+ e.set_backtrace(["a.rb:1", "b.rb:2"])
- 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
+ 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 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
+ 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
- it "contains cause of exception" do
+ ruby_version_is "2.6" do
+ it "contains cause of exception" do
+ begin
begin
- begin
- raise 'the cause'
- rescue
- raise 'main exception'
- end
- rescue => e
- exception = e
+ raise 'the cause'
+ rescue
+ raise 'main exception'
end
-
- exception.full_message.should include "main exception"
- exception.full_message.should include "the cause"
+ rescue => e
+ exception = e
end
- it 'contains all the chain of exceptions' do
+ exception.full_message.should include "main exception"
+ exception.full_message.should include "the cause"
+ end
+
+ it 'contains all the chain of exceptions' do
+ begin
begin
begin
- begin
- raise 'origin exception'
- rescue
- raise 'intermediate exception'
- end
+ raise 'origin exception'
rescue
- raise 'last exception'
+ raise 'intermediate exception'
end
- rescue => e
- exception = e
+ rescue
+ raise 'last exception'
end
-
- exception.full_message.should include "last exception"
- exception.full_message.should include "intermediate exception"
- exception.full_message.should include "origin exception"
+ rescue => e
+ exception = e
end
+
+ exception.full_message.should include "last exception"
+ exception.full_message.should include "intermediate exception"
+ exception.full_message.should include "origin exception"
end
end
end
diff --git a/spec/ruby/core/exception/hierarchy_spec.rb b/spec/ruby/core/exception/hierarchy_spec.rb
index e52811c761..6514eb1994 100644
--- a/spec/ruby/core/exception/hierarchy_spec.rb
+++ b/spec/ruby/core/exception/hierarchy_spec.rb
@@ -37,7 +37,9 @@ describe "Exception" do
FloatDomainError => nil,
},
RegexpError => nil,
- RuntimeError => nil,
+ RuntimeError => {
+ FrozenError => nil,
+ },
SystemCallError => nil,
ThreadError => nil,
TypeError => nil,
@@ -47,9 +49,7 @@ describe "Exception" do
SystemStackError => nil,
},
}
- ruby_version_is "2.5" do
- hierarchy[Exception][StandardError][RuntimeError] = {FrozenError => nil}
- end
+
traverse = -> parent_class, parent_subclass_hash {
parent_subclass_hash.each do |child_class, child_subclass_hash|
child_class.class.should == Class