From e26ad59c12187428a8da86b4b649038c8c08d6f3 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 17 Jan 2012 23:05:07 -0800 Subject: [PATCH] Remove off-by-one in history [Fixes #368] Remove unnecessary stubbing of history in tests that hid the problem. --- lib/pry/default_commands/input.rb | 2 +- test/helper.rb | 5 +---- test/test_default_commands/test_input.rb | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index b7114f55..12a3de84 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -163,7 +163,7 @@ class Pry end def process - @history = Pry::Code(Pry.history.to_a[0..-2]) + @history = Pry::Code(Pry.history.to_a) @history = case when opts.present?(:head) diff --git a/test/helper.rb b/test/helper.rb index 7c8ff126..10aaa449 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -121,15 +121,12 @@ end class InputTester def initialize(*actions) - if actions.last.is_a?(Hash) && actions.last.keys == [:history] - @hist = actions.pop[:history] - end @orig_actions = actions.dup @actions = actions end def readline(*) - @actions.shift.tap{ |line| @hist << line if @hist } + @actions.shift end def rewind diff --git a/test/test_default_commands/test_input.rb b/test/test_default_commands/test_input.rb index ea9cbbce..c19ac667 100644 --- a/test/test_default_commands/test_input.rb +++ b/test/test_default_commands/test_input.rb @@ -235,7 +235,7 @@ describe "Pry::DefaultCommands::Input" do @hist.push "hello" @hist.push "world" str_output = StringIO.new - redirect_pry_io(InputTester.new("hist", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do pry end str_output.string.should =~ /hello\n.*world/ @@ -246,7 +246,7 @@ describe "Pry::DefaultCommands::Input" do @hist.push ":bucket" @hist.push ":ostrich" str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay -1", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do pry end str_output.string.should =~ /ostrich/ @@ -256,7 +256,7 @@ describe "Pry::DefaultCommands::Input" do @hist.push ":hello" @hist.push ":carl" str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do pry end str_output.string.should =~ /:hello\n.*:carl/ @@ -274,21 +274,21 @@ describe "Pry::DefaultCommands::Input" do @hist.push "place holder" str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --grep o", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do pry end str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/ # test more than one word in a regex match (def blah) str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), str_output) do pry end str_output.string.should =~ /def blah 1/ # test more than one word with leading white space in a regex match (def boink) str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), str_output) do pry end str_output.string.should =~ /def boink 2/ @@ -300,7 +300,7 @@ describe "Pry::DefaultCommands::Input" do end str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --tail 3", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do pry end @@ -316,7 +316,7 @@ describe "Pry::DefaultCommands::Input" do end str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --head 4", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do pry end @@ -332,7 +332,7 @@ describe "Pry::DefaultCommands::Input" do end str_output = StringIO.new - redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do pry end @@ -342,7 +342,7 @@ describe "Pry::DefaultCommands::Input" do it "should not contain duplicated lines" do str_output = StringIO.new - redirect_pry_io(InputTester.new("3", "_ += 1", "_ += 1", "hist", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new("3", "_ += 1", "_ += 1", "hist", "exit-all"), str_output) do pry end @@ -351,7 +351,7 @@ describe "Pry::DefaultCommands::Input" do it "should not contain duplicated lines" do str_output = StringIO.new - redirect_pry_io(InputTester.new(":place_holder", "2 + 2", "", "", "3 + 3", "hist", "exit-all", :history => @hist), str_output) do + redirect_pry_io(InputTester.new(":place_holder", "2 + 2", "", "", "3 + 3", "hist", "exit-all"), str_output) do pry end