From 46288ab0024ae86da5163b02b29e6b90572b0e9c Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Fri, 26 Jul 2013 16:52:15 -0700 Subject: [PATCH] Ignore -n and disable_auto_reload in tempfile cases --- lib/pry/commands/edit.rb | 13 +++---------- spec/commands/edit_spec.rb | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index 7969c01d..a3b55999 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -30,7 +30,7 @@ class Pry opt.on :t, :temp, "Open an empty temporary file" opt.on :l, :line, "Jump to this line in the opened file", :argument => true, :as => Integer - opt.on :n, :"no-reload", "Don't automatically reload the edited code" + opt.on :n, :"no-reload", "Don't automatically reload the edited file" opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)" opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)" opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch" @@ -62,10 +62,8 @@ class Pry def repl_edit content = Pry::Editor.edit_tempfile_with_content(initial_temp_file_content, initial_temp_file_content.lines.count) - if repl_reload? - silence_warnings do - eval_string.replace content - end + silence_warnings do + eval_string.replace content end end @@ -170,11 +168,6 @@ class Pry opts.present?(:'no-reload') || Pry.config.disable_auto_reload end - # conditions much less strict than for reload? (which is for file-based reloads) - def repl_reload? - !never_reload? - end - def reload?(file_name="") (reloadable? || file_name.end_with?(".rb")) && !never_reload? end diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index c969eec4..5150aec4 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -338,13 +338,27 @@ describe "edit" do @t.eval_string.should == "'FOO'\n" end - it "should not evaluate the expression with -n" do + it "should ignore -n for tempfiles" do Pry.config.editor = lambda {|file, line| File.open(file, 'w'){|f| f << "'FOO'\n" } nil } - @t.process_command 'edit -n' - @t.eval_string.should == '' + @t.process_command "edit -n" + @t.eval_string.should == "'FOO'\n" + end + + it "should not evaluate a file with -n" do + Pry.config.editor = lambda {|file, line| + File.open(file, 'w'){|f| f << "'FOO'\n" } + nil + } + begin + @t.process_command 'edit -n spec/fixtures/foo.rb' + File.read("spec/fixtures/foo.rb").should == "'FOO'\n" + @t.eval_string.should == '' + ensure + FileUtils.rm "spec/fixtures/foo.rb" + end end end