From 1a2a9f8bd2132fbd33774d8fb35fd0ad66e39d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Tue, 22 Dec 2020 13:51:40 +0100 Subject: [PATCH 1/2] Make binding.eval Ruby 3.0 compatible. Ruby 3.0 changes behavior of `binding.eval` [[1]] resulting in test failure: ~~~ WebConsole::EvaluatorTest#test_Evaluator_callers_are_cleaned_up_of_unneeded_backtraces [/home/travis/build/rails/web-console/test/web_console/evaluator_test.rb:63]: --- expected +++ actual @@ -1,3 +1,3 @@ "RuntimeError: oops -\tfrom /home/travis/build/rails/web-console/test/web_console/evaluator_test.rb:61:in `block in ' +\tfrom (eval):1:in `block in ' ~~~ Fixes #301 [1]: https://bugs.ruby-lang.org/issues/17419 --- lib/web_console/evaluator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/web_console/evaluator.rb b/lib/web_console/evaluator.rb index b229c90b..615b43af 100644 --- a/lib/web_console/evaluator.rb +++ b/lib/web_console/evaluator.rb @@ -19,7 +19,14 @@ def initialize(binding = TOPLEVEL_BINDING) end def eval(input) - "=> #{@binding.eval(input).inspect}\n" + # Binding#source_location is available since Ruby 2.6. But if this should + # be removed the `WebConsole::SessionTest#test_use_first_binding_if_no_application_bindings` + # must be adjusted. + if @binding.respond_to? :source_location + "=> #{@binding.eval(input, *@binding.source_location).inspect}\n" + else + "=> #{@binding.eval(input).inspect}\n" + end rescue Exception => exc format_exception(exc) end From 006f73911b0e024d4d79f2bb23c4b6fd57d33c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Tue, 22 Dec 2020 13:55:02 +0100 Subject: [PATCH 2/2] Mock binding object must provide #source_location call. This is not really necessary ATM, but should the condition introduced by 1a2a9f8bd2132fbd33774d8 be removed one day, it will be needed anyway. --- lib/web_console/evaluator.rb | 4 +--- test/web_console/session_test.rb | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/web_console/evaluator.rb b/lib/web_console/evaluator.rb index 615b43af..dc91d061 100644 --- a/lib/web_console/evaluator.rb +++ b/lib/web_console/evaluator.rb @@ -19,9 +19,7 @@ def initialize(binding = TOPLEVEL_BINDING) end def eval(input) - # Binding#source_location is available since Ruby 2.6. But if this should - # be removed the `WebConsole::SessionTest#test_use_first_binding_if_no_application_bindings` - # must be adjusted. + # Binding#source_location is available since Ruby 2.6. if @binding.respond_to? :source_location "=> #{@binding.eval(input, *@binding.source_location).inspect}\n" else diff --git a/test/web_console/session_test.rb b/test/web_console/session_test.rb index b407e8f5..2b2d4313 100644 --- a/test/web_console/session_test.rb +++ b/test/web_console/session_test.rb @@ -51,6 +51,9 @@ def eval(string) end end + def source_location + end + self end