From a18d90b9e8531b84ffd55c7099aa39da6855ec7e Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 24 Jan 2012 22:54:57 +1300 Subject: [PATCH] hist --replay now uses eval_string <<, fixes #443 This ensures that the replayed lines end up in the pry input cache. This behaviour is now inline with the way play works. --- lib/pry/default_commands/input.rb | 6 ++++-- test/test_default_commands/test_input.rb | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index 4d8eafa6..c544c772 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -235,8 +235,10 @@ class Pry def process_replay @history = @history.between(opts[:r]) - _pry_.input_stack << _pry_.input - _pry_.input = StringIO.new(@history.raw) + + # not 100% sure why i need the \n here, but i do. + eval_string << "#{@history.raw}\n" + run "show-input" unless _pry_.complete_expression?(eval_string) end end diff --git a/test/test_default_commands/test_input.rb b/test/test_default_commands/test_input.rb index 5ac637a0..ae2df1b8 100644 --- a/test/test_default_commands/test_input.rb +++ b/test/test_default_commands/test_input.rb @@ -276,24 +276,29 @@ describe "Pry::DefaultCommands::Input" do end it 'should replay history correctly (single item)' do - @hist.push ":blah" - @hist.push ":bucket" - @hist.push ":ostrich" + o = Object.new + @hist.push "@x = 10" + @hist.push "@y = 20" + @hist.push "@z = 30" str_output = StringIO.new redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do - pry + o.pry end - str_output.string.should =~ /ostrich/ + o.instance_variable_get(:@x).should == nil + o.instance_variable_get(:@y).should == nil + o.instance_variable_get(:@z).should == 30 end it 'should replay a range of history correctly (range of items)' do - @hist.push ":hello" - @hist.push ":carl" + o = Object.new + @hist.push "@x = 10" + @hist.push "@y = 20" str_output = StringIO.new redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do - pry + o.pry end - str_output.string.should =~ /:hello\n.*:carl/ + o.instance_variable_get(:@x).should == 10 + o.instance_variable_get(:@y).should == 20 end it 'should grep for correct lines in history' do