From 46e1196e756e2360344c624a142a83c59ec2e21b Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Thu, 16 Aug 2012 23:31:03 -0700 Subject: [PATCH] Fix old_stack behavior on error --- lib/pry/commands/cd.rb | 6 +++--- test/test_default_commands/test_cd.rb | 30 +++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/pry/commands/cd.rb b/lib/pry/commands/cd.rb index 1d4a8055..6a76e660 100644 --- a/lib/pry/commands/cd.rb +++ b/lib/pry/commands/cd.rb @@ -20,9 +20,9 @@ class Pry BANNER def process - stack, old_stack = context_from_object_path(arg_string, _pry_, state.old_stack||[]) - state.old_stack = old_stack - _pry_.binding_stack = stack unless stack.nil? + state.old_stack ||= [] + stack, state.old_stack = context_from_object_path(arg_string, _pry_, state.old_stack) + _pry_.binding_stack = stack if stack end end end diff --git a/test/test_default_commands/test_cd.rb b/test/test_default_commands/test_cd.rb index deffe656..3e62dfa5 100644 --- a/test/test_default_commands/test_cd.rb +++ b/test/test_default_commands/test_cd.rb @@ -20,9 +20,9 @@ describe 'Pry::DefaultCommands::Cd' do eval '_pry_.command_state["cd"]' end - # def old_stack - # eval '_pry_.command_state["cd"].old_stack.dup' - # end + def old_stack + eval '_pry_.command_state["cd"].old_stack.dup' + end end end @@ -42,20 +42,20 @@ describe 'Pry::DefaultCommands::Cd' do end end - # describe 'when an error was raised' do - # it 'should not toggle and should keep correct stacks' do - # proc { - # @t.eval 'cd @' - # }.should.raise(Pry::CommandError) + describe 'when an error was raised' do + it 'should not toggle and should keep correct stacks' do + proc { + @t.eval 'cd @' + }.should.raise(Pry::CommandError) - # @t.old_stack.should == [] - # @t.assert_binding_stack [@o] + @t.old_stack.should == [] + @t.assert_binding_stack [@o] - # @t.eval 'cd -' - # @t.old_stack.should == [] - # @t.assert_binding_stack [@o] - # end - # end + @t.eval 'cd -' + @t.old_stack.should == [] + @t.assert_binding_stack [@o] + end + end describe 'when using simple cd syntax' do it 'should toggle' do