From 8c89d57d7ba4e5a8153f7787849e44c14147a410 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:46:06 +0900 Subject: [PATCH 1/5] repair ExceptionHandler#exception_text for Ruby 3.2 --- lib/pry/exception_handler.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pry/exception_handler.rb b/lib/pry/exception_handler.rb index d7f3b8626..74d53f02f 100644 --- a/lib/pry/exception_handler.rb +++ b/lib/pry/exception_handler.rb @@ -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) From d9211083b1c0ace1910660a7159533e9002c2bd1 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:30:47 +0900 Subject: [PATCH 2/5] repair standard error spec --- spec/exception_handler_spec.rb | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/spec/exception_handler_spec.rb b/spec/exception_handler_spec.rb index c9f082f61..1f3f97907 100644 --- a/spec/exception_handler_spec.rb +++ b/spec/exception_handler_spec.rb @@ -25,9 +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 `
'\n") - end + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2') + expect(output.string) + .to include("StandardError: oops\nfrom /bin/pry:23:in `
'\n") + else + expect(output.string) + .to include("StandardError: oops (StandardError)\nfrom /bin/pry:23:in `
'\n") + end + end end context "when exception is a nested standard error" do @@ -54,12 +59,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 From 3d2e1b3f3d230ada03dedc0014f3b4fa4ab78c13 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:49:19 +0900 Subject: [PATCH 3/5] repair spec style --- spec/exception_handler_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/exception_handler_spec.rb b/spec/exception_handler_spec.rb index 1f3f97907..e3d4d2e1b 100644 --- a/spec/exception_handler_spec.rb +++ b/spec/exception_handler_spec.rb @@ -30,9 +30,10 @@ .to include("StandardError: oops\nfrom /bin/pry:23:in `
'\n") else expect(output.string) - .to include("StandardError: oops (StandardError)\nfrom /bin/pry:23:in `
'\n") + .to include("StandardError: oops (StandardError)\n + from /bin/pry:23:in `
'\n") end - end + end end context "when exception is a nested standard error" do From 1d59aa0e8d6fd7a6f2e1c6b46b5b41ffe6b5e5cf Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:51:18 +0900 Subject: [PATCH 4/5] repair ls spec and exception_hander spec --- spec/commands/ls_spec.rb | 21 ++++++++++++++++----- spec/exception_handler_spec.rb | 3 +-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/spec/commands/ls_spec.rb b/spec/commands/ls_spec.rb index f3ef8f9b6..8481b5fa9 100644 --- a/spec/commands/ls_spec.rb +++ b/spec/commands/ls_spec.rb @@ -93,14 +93,25 @@ end it "should show public methods with -p" do - expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods: goo/) + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2') + expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods: goo/) + else + expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods:\n goo/) + 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(/methods:\n goo/) + expect(pry_eval("ls -p Class.new{ def goo; end; private :goo }.new")) + .to match(/methods:\n goo/) + end end it "should work for objects with an overridden method method" do diff --git a/spec/exception_handler_spec.rb b/spec/exception_handler_spec.rb index e3d4d2e1b..a90ee9c3f 100644 --- a/spec/exception_handler_spec.rb +++ b/spec/exception_handler_spec.rb @@ -30,8 +30,7 @@ .to include("StandardError: oops\nfrom /bin/pry:23:in `
'\n") else expect(output.string) - .to include("StandardError: oops (StandardError)\n - from /bin/pry:23:in `
'\n") + .to include("StandardError: oops (StandardError)\nfrom /bin/pry:23:in `
'\n") end end end From 3b106f12374bbe7a67666b051d997ac559517f21 Mon Sep 17 00:00:00 2001 From: hyuraku <32809703+hyuraku@users.noreply.github.com> Date: Fri, 1 Sep 2023 22:17:59 +0900 Subject: [PATCH 5/5] repair ls spec and style --- spec/commands/ls_spec.rb | 11 ++++++----- spec/exception_handler_spec.rb | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/commands/ls_spec.rb b/spec/commands/ls_spec.rb index 8481b5fa9..462953c65 100644 --- a/spec/commands/ls_spec.rb +++ b/spec/commands/ls_spec.rb @@ -93,11 +93,12 @@ end it "should show public methods with -p" do + message = "ls -p Class.new{ def goo; end }.new" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2') - expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods: goo/) + expect(pry_eval(message)).to match(/methods: goo/) else - expect(pry_eval("ls -p Class.new{ def goo; end }.new")).to match(/methods:\n goo/) - end + expect(pry_eval(message)).to match(/##methods: goo/m) + end end it "should show protected/private methods with -p" do @@ -108,9 +109,9 @@ .to match(/methods: goo/) else expect(pry_eval("ls -pM Class.new{ def goo; end; protected :goo }")) - .to match(/methods:\n goo/) + .to match(/##methods: goo/) expect(pry_eval("ls -p Class.new{ def goo; end; private :goo }.new")) - .to match(/methods:\n goo/) + .to match(/##methods: goo/) end end diff --git a/spec/exception_handler_spec.rb b/spec/exception_handler_spec.rb index a90ee9c3f..f4df8834d 100644 --- a/spec/exception_handler_spec.rb +++ b/spec/exception_handler_spec.rb @@ -29,8 +29,9 @@ expect(output.string) .to include("StandardError: oops\nfrom /bin/pry:23:in `
'\n") else + message = "StandardError: oops (StandardError)\nfrom /bin/pry:23:in `
'\n" expect(output.string) - .to include("StandardError: oops (StandardError)\nfrom /bin/pry:23:in `
'\n") + .to include(message) end end end