diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-07-13 11:49:28 +0200 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-07-24 14:51:20 +0200 |
commit | 43a5c191358699fe8b19314763998cb8ca77ed90 (patch) | |
tree | efebe1570ca2c77a66bfb81edeb3f86044e63174 /spec/ruby/core/binding | |
parent | 14d16bdb1ad8e98d76ec2c43b2c1c412ff707d0b (diff) |
Use the caller location as default filename for eval family of methods
[Feature #19755]
Before (in /tmp/test.rb):
```ruby
Object.class_eval("p __FILE__") # => "(eval)"
```
After:
```ruby
Object.class_eval("p __FILE__") # => "(eval at /tmp/test.rb:1)"
```
This makes it much easier to track down generated code in case
the author forgot to provide a filename argument.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8070
Diffstat (limited to 'spec/ruby/core/binding')
-rw-r--r-- | spec/ruby/core/binding/eval_spec.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/spec/ruby/core/binding/eval_spec.rb b/spec/ruby/core/binding/eval_spec.rb index 1b3b670b5e..bb2036f739 100644 --- a/spec/ruby/core/binding/eval_spec.rb +++ b/spec/ruby/core/binding/eval_spec.rb @@ -60,10 +60,12 @@ describe "Binding#eval" do bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 end - it "uses (eval) as __FILE__ if single argument given" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__FILE__").should == '(eval)' + ruby_version_is ""..."3.3" do + it "uses (eval) as __FILE__ if single argument given" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("__FILE__").should == '(eval)' + end end it "uses 1 as __LINE__" do @@ -104,4 +106,10 @@ describe "Binding#eval" do bind.eval("'bar'.foo").should == "foo" end + + ruby_version_is "3.3" do + it "uses the caller location as default filename" do + binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] + end + end end |