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

repair ExceptionHandler#exception_text for Ruby 3.2 #2285

Merged
merged 5 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/pry/exception_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ def standard_error_text_for(exception)
end

def exception_text(exception)
"#{exception.class}: #{exception.message}\n" \
"from #{exception.backtrace.first}\n"
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
"#{exception.class}: #{exception.message}\n" \
"from #{exception.backtrace.first}\n"
else
"#{exception.class}: #{exception.detailed_message}\n" \
"from #{exception.backtrace.first}\n"
end
end

def cause_text(cause)
Expand Down
22 changes: 17 additions & 5 deletions spec/commands/ls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,26 @@
end

it "should show public methods with -p" do
expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods: goo/)
message = "ls -p Class.new{ def goo; end }.new"
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
expect(pry_eval(message)).to match(/methods: goo/)
else
expect(pry_eval(message)).to match(/#<Class:.*>#methods: goo/m)
end
end

it "should show protected/private methods with -p" do
expect(pry_eval("ls -pM Class.new{ def goo; end; protected :goo }"))
.to match(/methods: goo/)
expect(pry_eval("ls -p Class.new{ def goo; end; private :goo }.new"))
.to match(/methods: goo/)
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
expect(pry_eval("ls -pM Class.new{ def goo; end; protected :goo }"))
.to match(/methods: goo/)
expect(pry_eval("ls -p Class.new{ def goo; end; private :goo }.new"))
.to match(/methods: goo/)
else
expect(pry_eval("ls -pM Class.new{ def goo; end; protected :goo }"))
.to match(/#<Class:.*>#methods: goo/)
expect(pry_eval("ls -p Class.new{ def goo; end; private :goo }.new"))
.to match(/#<Class:.*>#methods: goo/)
end
end

it "should work for objects with an overridden method method" do
Expand Down
31 changes: 23 additions & 8 deletions spec/exception_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@

it "prints standard error message" do
described_class.handle_exception(output, exception, pry_instance)
expect(output.string)
.to eq("StandardError: oops\nfrom /bin/pry:23:in `<main>'\n")
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
expect(output.string)
.to include("StandardError: oops\nfrom /bin/pry:23:in `<main>'\n")
else
message = "StandardError: oops (StandardError)\nfrom /bin/pry:23:in `<main>'\n"
expect(output.string)
.to include(message)
end
end
end

Expand Down Expand Up @@ -54,12 +60,21 @@

it "prints standard error message" do
described_class.handle_exception(output, exception, pry_instance)
expect(output.string).to match(
/RuntimeError:\souter\soops\n
from\s.+\n
Caused\sby\sRuntimeError:\snested\soops\n
from.+/x
)
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
expect(output.string).to match(
/RuntimeError:\souter\soops\n
from\s.+\n
Caused\sby\sRuntimeError:\snested\soops\n
from.+/x
)
else
expect(output.string).to match(
/RuntimeError:\souter\soops\s\(RuntimeError\)\n
from\s.+\n
Caused\sby\sRuntimeError:\snested\soops\n
from\s.+/x
)
end
end
end
end
Expand Down