1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Replace PryTester#simulate_repl with Pry#eval

This commit is contained in:
Ryan Fitzgerald 2012-12-28 18:35:08 -08:00
parent c1f8c3f954
commit 351d8b6d61
3 changed files with 34 additions and 63 deletions

View file

@ -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

View file

@ -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

View file

@ -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