mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
fixed bug where Command#run "cd .." would error
* error was due to an extra space being appended to string, which messed up `cd` command parsing * fixed by applying a simple #rstrip; updated tests
This commit is contained in:
parent
1e23410e36
commit
81c0130815
2 changed files with 82 additions and 3 deletions
|
@ -180,7 +180,7 @@ class Pry
|
|||
# @example
|
||||
# run "amend-line", "5", 'puts "hello world"'
|
||||
def run(command_string, *args)
|
||||
complete_string = "#{command_string} #{args.join(" ")}"
|
||||
complete_string = "#{command_string} #{args.join(" ")}".rstrip
|
||||
command_set.process_line(complete_string, context)
|
||||
end
|
||||
|
||||
|
|
|
@ -317,6 +317,83 @@ describe "commands" do
|
|||
klass.commands["help"].description.should == "blah"
|
||||
end
|
||||
|
||||
|
||||
describe "Pry::Command#run" do
|
||||
it 'should allow running of commands with following whitespace' do
|
||||
$_scratch = Object.new
|
||||
o = Object.new
|
||||
|
||||
set = Pry::CommandSet.new do
|
||||
import Pry::Commands
|
||||
command "test-run" do
|
||||
run "cd / "
|
||||
end
|
||||
end
|
||||
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
||||
"@nesting1 = _pry_.binding_stack.size",
|
||||
"test-run",
|
||||
"@obj = self",
|
||||
"@nesting2 = _pry_.binding_stack.size",
|
||||
"exit-all")) do
|
||||
Pry.start(o, :commands => set)
|
||||
end
|
||||
|
||||
$_scratch.instance_variable_get(:@nesting1).should == 8
|
||||
o.instance_variable_get(:@obj).should == o
|
||||
o.instance_variable_get(:@nesting2).should == 1
|
||||
$_scratch = nil
|
||||
end
|
||||
|
||||
it 'should allow running of cd command when contained in a single string' do
|
||||
$_scratch = Object.new
|
||||
o = Object.new
|
||||
|
||||
set = Pry::CommandSet.new do
|
||||
import Pry::Commands
|
||||
command "test-run" do
|
||||
run "cd /"
|
||||
end
|
||||
end
|
||||
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
||||
"@nesting1 = _pry_.binding_stack.size",
|
||||
"test-run",
|
||||
"@obj = self",
|
||||
"@nesting2 = _pry_.binding_stack.size",
|
||||
"exit-all")) do
|
||||
Pry.start(o, :commands => set)
|
||||
end
|
||||
|
||||
$_scratch.instance_variable_get(:@nesting1).should == 8
|
||||
o.instance_variable_get(:@obj).should == o
|
||||
o.instance_variable_get(:@nesting2).should == 1
|
||||
$_scratch = nil
|
||||
end
|
||||
|
||||
it 'should allow running of cd command when split into array' do
|
||||
$_scratch = Object.new
|
||||
o = Object.new
|
||||
|
||||
set = Pry::CommandSet.new do
|
||||
import Pry::Commands
|
||||
command "test-run" do
|
||||
run "cd", "/"
|
||||
end
|
||||
end
|
||||
redirect_pry_io(InputTester.new("cd 1/2/3/4/5/6/$_scratch",
|
||||
"@nesting1 = _pry_.binding_stack.size",
|
||||
"test-run",
|
||||
"@obj = self",
|
||||
"@nesting2 = _pry_.binding_stack.size",
|
||||
"exit-all")) do
|
||||
Pry.start(o, :commands => set)
|
||||
end
|
||||
|
||||
$_scratch.instance_variable_get(:@nesting1).should == 8
|
||||
o.instance_variable_get(:@obj).should == o
|
||||
o.instance_variable_get(:@nesting2).should == 1
|
||||
$_scratch = nil
|
||||
end
|
||||
|
||||
it 'should run a command from within a command' do
|
||||
klass = Pry::CommandSet.new do
|
||||
command "v" do
|
||||
|
@ -376,6 +453,8 @@ describe "commands" do
|
|||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'should enable an inherited method to access opts and output and target, due to instance_exec' do
|
||||
klass = Pry::CommandSet.new do
|
||||
command "v" do
|
||||
|
|
Loading…
Reference in a new issue