Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for Exception#detailed_message #1029

Merged
merged 1 commit into from
May 16, 2023

Conversation

AI-Mozi
Copy link
Contributor

@AI-Mozi AI-Mozi commented May 15, 2023

#1016
[Feature #18564]

Exception#detailed_message has been added.
The default error printer calls this method on the Exception object
instead of #message

@AI-Mozi
Copy link
Contributor Author

AI-Mozi commented May 15, 2023

I'm not sure if thats enough. Adding more cases with different errors messages (like what I wrote) imo is not necessary, but maybe an example of creating new error class, with custom #detailed_message?

@AI-Mozi AI-Mozi marked this pull request as ready for review May 15, 2023 14:17
@andrykonchin
Copy link
Member

andrykonchin commented May 15, 2023

I would propose the following test cases:

  • it returns decorated message - message and exception class name
  • it accepts highlight keyword argument and adds escape control sequences (or some similar description)
  • it allows and ignores other keyword arguments
  • it just returns a message if exception class is anonymous
    • I mean the following case - Class.new(RuntimeError).new("message").detailed_message # => message
  • it returns "unhandled exception" when for an instance of RuntimeError with empty message`
    • I mean the following case - RuntimeError.new("").detailed_message # => unhandled exception)
  • returns just a class name for an instance of RuntimeError subclass with empty message
    • C = Class.new(RuntimeError); C.new("").detailed_message # => "C"
  • it returns a generated ... (class name?) for an instance of RuntimeError anonymous subclass with empty message
    • klass = Class.new(RuntimeError); klass.new("").detailed_message # => "#<Class:0x000000010ba06228>"

Also the behaviour of #full_message is changed, so the following cases could be added as well:

  • it relies on #detailed_message
    • so here we can redefine a detailed_message message and demonstrate its value is printed by #full_message
  • it passes all its own keyword arguments to #detailed_message

Original PR with some MRI specs - ruby/ruby#5516

@AI-Mozi AI-Mozi force-pushed the add_specs_for_detailed_message branch 2 times, most recently from 0cff35c to efae009 Compare May 16, 2023 09:12
core/exception/detailed_message_spec.rb Outdated Show resolved Hide resolved
core/exception/detailed_message_spec.rb Show resolved Hide resolved
core/exception/detailed_message_spec.rb Outdated Show resolved Hide resolved
core/exception/full_message_spec.rb Show resolved Hide resolved
@AI-Mozi AI-Mozi force-pushed the add_specs_for_detailed_message branch 2 times, most recently from 6b7718d to 4b01b08 Compare May 16, 2023 10:42
@@ -93,3 +93,7 @@ def call_undefined_class_variable
end
end
end

module DetailedMessageSpec
C = Class.new(RuntimeError)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is C enough, or should it be more meaningful?

Copy link
Member

@andrykonchin andrykonchin May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, it's OK. There are a lot of helper classes like A, B, M etc with short names for readability (I suppose)

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 ingores other keyword arguments" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "allows and ingores other keyword arguments" do
it "allows and ignores other keyword arguments" do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh.. these typos everywhere.. sorry

@AI-Mozi AI-Mozi force-pushed the add_specs_for_detailed_message branch from 4b01b08 to 98e6283 Compare May 16, 2023 11:50
@andrykonchin
Copy link
Member

Thank you for new specs!

@andrykonchin andrykonchin merged commit 2275adc into ruby:master May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants