rspec:如何捕获新线程的退出?

时间:2019-01-01 20:30:50

标签: ruby multithreading rspec

因此,我可以通过rspec捕获exit

expect { exit }.to raise_error(SystemExit)

但是,如果在新线程中调用了exit,则会退出整个rspec运行:

expect { Thread.new { exit } }.to raise_error(SystemExit)

是否可以从新线程中正常捕获exit

1 个答案:

答案 0 :(得分:1)

我不知道这是否正是您想要的,但是您可以在新创建的线程上调用join。这似乎对我有用。

expect { Thread.new { exit }.join }.to raise_error(SystemExit)