Skip to content

Commit

Permalink
Make binding.eval Ruby 3.0 compatible.
Browse files Browse the repository at this point in the history
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 <class:EvaluatorTest>'
+\tfrom (eval):1:in `block in <class:EvaluatorTest>'
~~~

Fixes #301

[1]: https://bugs.ruby-lang.org/issues/17419
  • Loading branch information
voxik committed Dec 22, 2020
1 parent 167c240 commit 1a2a9f8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/web_console/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a2a9f8

Please sign in to comment.