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