mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Don't update .last_input on empty lines [Fixes #414]
This commit is contained in:
parent
af5e96bf3c
commit
6280417ad9
2 changed files with 24 additions and 3 deletions
|
@ -225,7 +225,9 @@ class Pry
|
|||
|
||||
code = r(target)
|
||||
|
||||
result = set_last_result(target.eval(code, Pry.eval_path, Pry.current_line), target)
|
||||
result = target.eval(code, Pry.eval_path, Pry.current_line)
|
||||
set_last_result(result, target, code)
|
||||
|
||||
result
|
||||
rescue RescuableException => e
|
||||
result = set_last_exception(e, target)
|
||||
|
@ -403,11 +405,12 @@ class Pry
|
|||
# This method should not need to be invoked directly.
|
||||
# @param [Object] result The result.
|
||||
# @param [Binding] target The binding to set `_` on.
|
||||
def set_last_result(result, target)
|
||||
# @param [String] code The code that was run.
|
||||
def set_last_result(result, target, code="")
|
||||
@last_result_is_exception = false
|
||||
@output_array << result
|
||||
|
||||
self.last_result = result
|
||||
self.last_result = result unless code =~ /\A\s*\z/
|
||||
end
|
||||
|
||||
# Set the last exception for a session.
|
||||
|
|
|
@ -254,6 +254,24 @@ describe Pry do
|
|||
end
|
||||
end
|
||||
|
||||
describe "last_result" do
|
||||
it "should be set to the most recent value" do
|
||||
mock_pry("2", "_ + 82").should =~ /84/
|
||||
end
|
||||
|
||||
it "should be set to the result of a command with :keep_retval" do
|
||||
mock_pry("Pry::Commands.block_command '++', '', {:keep_retval => true} do |a| a.to_i + 1; end", '++ 86', '++ #{_}').should =~ /88/
|
||||
end
|
||||
|
||||
it "should be preserved over an empty line" do
|
||||
mock_pry("2 + 2", " ", "\t", " ", "_ + 92").should =~ /96/
|
||||
end
|
||||
|
||||
it "should be preserved when evalling a command without :keep_retval" do
|
||||
mock_pry("2 + 2", "ls -l", "_ + 96").should =~ /100/
|
||||
end
|
||||
end
|
||||
|
||||
describe "test loading rc files" do
|
||||
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue