1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Ignore -n and disable_auto_reload in tempfile cases

This commit is contained in:
Ryan Fitzgerald 2013-07-26 16:52:15 -07:00
parent b460170039
commit 46288ab002
2 changed files with 20 additions and 13 deletions

View file

@ -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

View file

@ -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