From ef09e90af1656823a99ae672c02148166921a540 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 22 Mar 2013 23:26:52 -0700 Subject: [PATCH] Use load instead of eval [Fixes #880] --- lib/pry/commands/edit.rb | 2 +- spec/commands/edit_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index d2a54ad2..bddecaa5 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -124,7 +124,7 @@ class Pry if reload?(file_name) silence_warnings do - TOPLEVEL_BINDING.eval(File.read(file_name), file_name) + load file_name end end end diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index 3e2f08f8..ce530cdb 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -66,6 +66,16 @@ describe "edit" do FileUtils.rm(tf_path) end + it "should work with require relative" do + Pry.config.editor = lambda { |file, line| + File.open(file, 'w'){ |f| f << 'require_relative "baz.rb"' } + File.open(file.gsub('bar.rb', 'baz.rb'), 'w'){ |f| f << "Pad.required = true; FileUtils.rm(__FILE__)" } + nil + } + pry_eval "edit #@tf_path" + Pad.required.should == true + end + describe do before do Pad.counter = 0