2012-09-15 14:50:15 -07:00
|
|
|
describe "exit" do
|
2018-10-13 03:09:29 +08:00
|
|
|
before { @pry = Pry.new(target: :outer, output: StringIO.new) }
|
2012-12-28 18:35:08 -08:00
|
|
|
|
|
|
|
it "should pop a binding" do
|
|
|
|
@pry.eval "cd :inner"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@pry.evaluate_ruby("self")).to eq :inner
|
2012-12-28 18:35:08 -08:00
|
|
|
@pry.eval "exit"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@pry.evaluate_ruby("self")).to eq :outer
|
2012-09-15 14:50:15 -07:00
|
|
|
end
|
|
|
|
|
2012-12-28 18:35:08 -08:00
|
|
|
it "should break out of the repl when binding_stack has only one binding" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@pry.eval("exit")).to equal false
|
|
|
|
expect(@pry.exit_value).to equal nil
|
2012-09-15 14:50:15 -07:00
|
|
|
end
|
|
|
|
|
2012-12-28 18:35:08 -08:00
|
|
|
it "should break out of the repl and return user-given value" do
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@pry.eval("exit :john")).to equal false
|
|
|
|
expect(@pry.exit_value).to eq :john
|
2012-09-15 14:50:15 -07:00
|
|
|
end
|
|
|
|
|
2012-12-28 18:35:08 -08:00
|
|
|
it "should break out of the repl even after an exception" do
|
|
|
|
@pry.eval "exit = 42"
|
2015-03-10 22:49:29 +02:00
|
|
|
expect(@pry.output.string).to match(/^SyntaxError/)
|
|
|
|
expect(@pry.eval("exit")).to equal false
|
2012-09-15 14:50:15 -07:00
|
|
|
end
|
|
|
|
end
|