-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1029 from AI-Mozi/add_specs_for_detailed_message
Add specs for `Exception#detailed_message`
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/common' | ||
|
||
describe "Exception#detailed_message" do | ||
ruby_version_is "3.2" do | ||
it "returns decorated message" do | ||
RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)" | ||
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 | ||
|
||
it "returns 'unhandled exception' for an instance of RuntimeError with empty message" do | ||
RuntimeError.new("").detailed_message.should == "unhandled exception" | ||
end | ||
|
||
it "returns just class name for an instance of RuntimeError sublass with empty message" do | ||
DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C" | ||
end | ||
|
||
it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do | ||
klass = Class.new(RuntimeError) | ||
klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/ | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,7 @@ def call_undefined_class_variable | |
end | ||
end | ||
end | ||
|
||
module DetailedMessageSpec | ||
C = Class.new(RuntimeError) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters