diff --git a/lib/pry/commands/shell_command.rb b/lib/pry/commands/shell_command.rb index 4f87de92..69559405 100644 --- a/lib/pry/commands/shell_command.rb +++ b/lib/pry/commands/shell_command.rb @@ -16,7 +16,7 @@ class Pry BANNER def process(cmd) - if cmd =~ /^cd\s+(.+)/i + if cmd =~ /^cd\s*(.*)/i process_cd parse_destination($1) else pass_block(cmd) @@ -36,6 +36,7 @@ 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 diff --git a/spec/commands/shell_command_spec.rb b/spec/commands/shell_command_spec.rb index 567f9c6b..a0ee03ba 100644 --- a/spec/commands/shell_command_spec.rb +++ b/spec/commands/shell_command_spec.rb @@ -31,6 +31,13 @@ describe "Command::ShellCommand" do end end + describe "given an empty string" do + it "sends ~ to File.expand_path" do + Dir.expects(:chdir).with(File.expand_path("~")) + @t.eval ".cd " + end + end + describe "given a dash" do describe "given no prior directory" do it "raises the correct error" do