mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Remove off-by-one in history [Fixes #368]
Remove unnecessary stubbing of history in tests that hid the problem.
This commit is contained in:
parent
2827ded4a0
commit
e26ad59c12
3 changed files with 13 additions and 16 deletions
|
@ -163,7 +163,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
@history = Pry::Code(Pry.history.to_a[0..-2])
|
@history = Pry::Code(Pry.history.to_a)
|
||||||
|
|
||||||
@history = case
|
@history = case
|
||||||
when opts.present?(:head)
|
when opts.present?(:head)
|
||||||
|
|
|
@ -121,15 +121,12 @@ end
|
||||||
|
|
||||||
class InputTester
|
class InputTester
|
||||||
def initialize(*actions)
|
def initialize(*actions)
|
||||||
if actions.last.is_a?(Hash) && actions.last.keys == [:history]
|
|
||||||
@hist = actions.pop[:history]
|
|
||||||
end
|
|
||||||
@orig_actions = actions.dup
|
@orig_actions = actions.dup
|
||||||
@actions = actions
|
@actions = actions
|
||||||
end
|
end
|
||||||
|
|
||||||
def readline(*)
|
def readline(*)
|
||||||
@actions.shift.tap{ |line| @hist << line if @hist }
|
@actions.shift
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewind
|
def rewind
|
||||||
|
|
|
@ -235,7 +235,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
@hist.push "hello"
|
@hist.push "hello"
|
||||||
@hist.push "world"
|
@hist.push "world"
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /hello\n.*world/
|
str_output.string.should =~ /hello\n.*world/
|
||||||
|
@ -246,7 +246,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
@hist.push ":bucket"
|
@hist.push ":bucket"
|
||||||
@hist.push ":ostrich"
|
@hist.push ":ostrich"
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /ostrich/
|
str_output.string.should =~ /ostrich/
|
||||||
|
@ -256,7 +256,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
@hist.push ":hello"
|
@hist.push ":hello"
|
||||||
@hist.push ":carl"
|
@hist.push ":carl"
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /:hello\n.*:carl/
|
str_output.string.should =~ /:hello\n.*:carl/
|
||||||
|
@ -274,21 +274,21 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
@hist.push "place holder"
|
@hist.push "place holder"
|
||||||
|
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
|
str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
|
||||||
|
|
||||||
# test more than one word in a regex match (def blah)
|
# test more than one word in a regex match (def blah)
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /def blah 1/
|
str_output.string.should =~ /def blah 1/
|
||||||
|
|
||||||
# test more than one word with leading white space in a regex match (def boink)
|
# test more than one word with leading white space in a regex match (def boink)
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
str_output.string.should =~ /def boink 2/
|
str_output.string.should =~ /def boink 2/
|
||||||
|
@ -300,7 +300,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
end
|
end
|
||||||
|
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
end
|
end
|
||||||
|
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
end
|
end
|
||||||
|
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
|
|
||||||
it "should not contain duplicated lines" do
|
it "should not contain duplicated lines" do
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ describe "Pry::DefaultCommands::Input" do
|
||||||
|
|
||||||
it "should not contain duplicated lines" do
|
it "should not contain duplicated lines" do
|
||||||
str_output = StringIO.new
|
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
|
pry
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue