mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Test added for .cd taking the CDPATH into account.
This commit is contained in:
parent
d2215dcde4
commit
2c2e39332e
2 changed files with 28 additions and 7 deletions
|
@ -30,17 +30,23 @@ class Pry
|
|||
|
||||
private
|
||||
|
||||
def parse_destination(dest)
|
||||
return "~" if dest.empty?
|
||||
return dest unless dest == "-"
|
||||
state.old_pwd || raise(CommandError, "No prior directory available")
|
||||
end
|
||||
def parse_destination(dest)
|
||||
return "~" if dest.empty?
|
||||
return dest unless dest == "-"
|
||||
state.old_pwd || raise(CommandError, "No prior directory available")
|
||||
end
|
||||
|
||||
def process_cd(dest)
|
||||
def cd_path
|
||||
ENV[ 'CDPATH' ]
|
||||
end
|
||||
|
||||
def process_cd(dest)
|
||||
begin
|
||||
state.old_pwd = Dir.pwd
|
||||
|
||||
# Don't do thinks for ".", "..", "-" and stuff starting with "/" and "~".
|
||||
if dest && (!([ ".", "..", "-" ].include?(dest))) && (dest !~ /^[#{File::PATH_SEPARATOR}~]/)
|
||||
cdpath = ENV[ 'CDPATH' ]
|
||||
cdpath = cd_path()
|
||||
if cdpath && (cdpath.length > 0)
|
||||
paths = cdpath.split(File::PATH_SEPARATOR)
|
||||
paths.each do |next_path|
|
||||
|
@ -51,10 +57,12 @@ class Pry
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
Dir.chdir File.expand_path(dest)
|
||||
rescue Errno::ENOENT
|
||||
raise CommandError, "No such directory: #{dest}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
||||
|
|
|
@ -57,6 +57,19 @@ describe "Command::ShellCommand" do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".cd with CDPATH" do
|
||||
it ".cd with finding location in CDPATH" do
|
||||
allow_any_instance_of(Pry::Command::ShellCommand).to receive(:cd_path).and_return("#{File.dirname( __FILE__ )}#{File::SEPARATOR}..")
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("#{File.dirname( __FILE__ )}#{File::SEPARATOR}..#{File::SEPARATOR}commands"))
|
||||
@t.eval ".cd commands"
|
||||
end
|
||||
it ".cd without finding directory in CDPATH" do
|
||||
allow_any_instance_of(Pry::Command::ShellCommand).to receive(:cd_path).and_return(".")
|
||||
expect(Dir).to receive(:chdir).with(File.expand_path("commands"))
|
||||
@t.eval ".cd commands"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue