Fix `exit` after previous syntax error in `exit` command. #550

Merged
merged 1 commit into from Apr 25, 2012
View
5 lib/pry/default_commands/navigating_pry.rb
@@ -41,11 +41,14 @@ module DefaultCommands
end
command "exit-all", "End the current Pry session (popping all bindings) and returning to caller. Accepts optional return value. Aliases: !!@" do
+ # calculate user-given value
+ exit_value = target.eval(arg_string)
+
# clear the binding stack
_pry_.binding_stack.clear
# break out of the repl loop
- throw(:breakout, target.eval(arg_string))
+ throw(:breakout, exit_value)
end
alias_command "!!@", "exit-all"
View
6 test/test_default_commands/test_context.rb
@@ -77,6 +77,12 @@ def method; "moo"; end
it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit, and return user-given value' do
Pry.start(0, :input => StringIO.new("exit :john")).should == :john
end
+
+ it 'should break out the repl loop of Pry instance even after an exception in user-given value' do
+ redirect_pry_io(InputTester.new("exit = 42", "exit"), StringIO.new) do
+ ins = Pry.new.tap { |v| v.repl(0).should == nil }
+ end
+ end
end
describe "jump-to" do