From 1b3149db0ba085d73e09d2cd28081f6645810983 Mon Sep 17 00:00:00 2001 From: Herwin Date: Thu, 27 Jun 2024 17:26:37 +0200 Subject: [PATCH 1/2] Update specs for Exception#detailed_message without message There is a specific path for instances of RuntimeError, the other path (returning the name of the class) is used for every other instance, not just for subclasses of RuntimeError. --- core/exception/detailed_message_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/exception/detailed_message_spec.rb b/core/exception/detailed_message_spec.rb index fbe4443da..68cf70ad1 100644 --- a/core/exception/detailed_message_spec.rb +++ b/core/exception/detailed_message_spec.rb @@ -31,8 +31,9 @@ def exception.detailed_message(**) RuntimeError.new("").detailed_message.should == "unhandled exception" end - it "returns just class name for an instance of RuntimeError subclass with empty message" do + it "returns just class name for an instance other than RuntimeError with empty message" do DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C" + StandardError.new("").detailed_message.should == "StandardError" end it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do From 4489e05428d686a69a4a6529ff9e28b502a9d1f9 Mon Sep 17 00:00:00 2001 From: Herwin Date: Thu, 27 Jun 2024 17:51:02 +0200 Subject: [PATCH 2/2] Add more specs for highlight in Exception#detailed_message There is a specific code path for exceptions with an empty message. Test both the RuntimeError and another exception class. Move the existing code a bit, to keep the ordering/grouping of specs a bit more logical. --- core/exception/detailed_message_spec.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/core/exception/detailed_message_spec.rb b/core/exception/detailed_message_spec.rb index 68cf70ad1..8178278b2 100644 --- a/core/exception/detailed_message_spec.rb +++ b/core/exception/detailed_message_spec.rb @@ -15,14 +15,6 @@ def exception.detailed_message(**) exception.full_message(highlight: false).should.include? "new error" end - it "accepts highlight keyword argument and adds escape control sequences" do - RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m" - end - - it "allows and ignores other keyword arguments" do - RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)" - end - it "returns just a message if exception class is anonymous" do Class.new(RuntimeError).new("message").detailed_message.should == "message" end @@ -40,5 +32,21 @@ def exception.detailed_message(**) klass = Class.new(RuntimeError) klass.new("").detailed_message.should =~ /\A#\z/ end + + it "accepts highlight keyword argument and adds escape control sequences" do + RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m" + end + + it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do + RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m" + end + + it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do + StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m" + end + + it "allows and ignores other keyword arguments" do + RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)" + end end end