diff --git a/lib/pry/test/helper.rb b/lib/pry/test/helper.rb index 120ce796..210fcbcb 100644 --- a/lib/pry/test/helper.rb +++ b/lib/pry/test/helper.rb @@ -122,6 +122,7 @@ class PryTester strs.flatten.each do |str| str = "#{str.strip}\n" @history.push str if @history + if @pry.process_command(str) result = last_command_result_or_output else @@ -142,23 +143,6 @@ class PryTester @pry.push_binding context end - # TODO: eliminate duplication with Pry#repl - def simulate_repl - didnt_exit = nil - break_data = nil - - didnt_exit = catch(:didnt_exit) do - break_data = catch(:breakout) do - yield self - throw(:didnt_exit, true) - end - nil - end - - raise "Failed to exit REPL" if didnt_exit - break_data - end - def last_output @out.string if @out end diff --git a/spec/commands/exit_all_spec.rb b/spec/commands/exit_all_spec.rb index f97fa8b3..fab60cea 100644 --- a/spec/commands/exit_all_spec.rb +++ b/spec/commands/exit_all_spec.rb @@ -1,34 +1,27 @@ require 'helper' describe "exit-all" do - it 'should break out of the repl loop of Pry instance and return nil' do - pry_tester(0).simulate_repl do |t| - t.eval 'exit-all' - end.should == nil + before { @pry = Pry.new } + + it "should break out of the repl and return nil" do + @pry.eval("exit-all").should.be.false + @pry.exit_value.should.be.nil end - it 'should break out of the repl loop of Pry instance wth a user specified value' do - pry_tester(0).simulate_repl do |t| - t.eval "exit-all 'message'" - end.should == 'message' + it "should break out of the repl wth a user specified value" do + @pry.eval("exit-all 'message'").should.be.false + @pry.exit_value.should == "message" end - it 'should break of the repl loop even if multiple bindings still on stack' do - pry_tester(0).simulate_repl do |t| - t.eval 'cd 1', 'cd 2', "exit-all 'message'" - end.should == 'message' + it "should break out of the repl even if multiple bindings still on stack" do + ["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true } + @pry.eval("exit-all 'message'").should.be.false + @pry.exit_value.should == "message" end - it 'binding_stack should be empty after breaking out of the repl loop' do - t = pry_tester(0) do - def binding_stack - @pry.binding_stack - end - end - - t.simulate_repl do |t| - t.eval 'cd 1', 'cd 2', 'exit-all' - end - t.binding_stack.empty?.should == true + it "should have empty binding_stack after breaking out of the repl" do + ["cd 1", "cd 2"].each { |line| @pry.eval(line).should.be.true } + @pry.eval("exit-all").should.be.false + @pry.binding_stack.should.be.empty end end diff --git a/spec/commands/exit_spec.rb b/spec/commands/exit_spec.rb index 6e902a8a..eaf3548d 100644 --- a/spec/commands/exit_spec.rb +++ b/spec/commands/exit_spec.rb @@ -1,34 +1,28 @@ require 'helper' describe "exit" do - it 'should pop a binding with exit' do - pry_tester(:outer).simulate_repl do |t| - t.eval 'cd :inner' - t.eval('self').should == :inner - t.eval 'exit' - t.eval('self').should == :outer - t.eval 'exit-all' - end + before { @pry = Pry.new(:target => :outer, :output => StringIO.new) } + + it "should pop a binding" do + @pry.eval "cd :inner" + @pry.evaluate_ruby("self").should == :inner + @pry.eval "exit" + @pry.evaluate_ruby("self").should == :outer end - it 'should break out of the repl loop of Pry instance when binding_stack has only one binding with exit' do - pry_tester(0).simulate_repl do |t| - t.eval 'exit' - end.should == nil + it "should break out of the repl when binding_stack has only one binding" do + @pry.eval("exit").should.be.false + @pry.exit_value.should.be.nil 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_tester(0).simulate_repl do |t| - t.eval 'exit :john' - end.should == :john + it "should break out of the repl and return user-given value" do + @pry.eval("exit :john").should.be.false + @pry.exit_value.should == :john end - it 'should break out the repl loop of Pry instance even after an exception in user-given value' do - pry_tester(0).simulate_repl do |t| - proc { - t.eval 'exit = 42' - }.should.raise(SyntaxError) - t.eval 'exit' - end.should == nil + it "should break out of the repl even after an exception" do + @pry.eval "exit = 42" + @pry.output.string.should =~ /^SyntaxError/ + @pry.eval("exit").should.be.false end end