所以,我可以捕捉 exit 在RSPEC中:
exit
expect { exit }.to raise_error(SystemExit)
但是,如果 出口 在新线程内调用,整个rspec运行退出:
出口
expect { Thread.new { exit } }.to raise_error(SystemExit)
有什么方法可以捕捉 出口 从一条新的线优雅地?
我不知道这是否正是您想要的,但您可以在新创建的线程上调用join。这对我来说似乎很管用。
expect { Thread.new { exit }.join }.to raise_error(SystemExit)