代码之家  ›  专栏  ›  技术社区  ›  KZcoding Tharun

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

  •  1
  • KZcoding Tharun  · 技术社区  · 7 年前

    所以,我可以捕捉 exit 在RSPEC中:

    expect { exit }.to raise_error(SystemExit)

    但是,如果 出口 在新线程内调用,整个rspec运行退出:

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

    有什么方法可以捕捉 出口 从一条新的线优雅地?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Gregory Ostermayr    7 年前

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

    expect { Thread.new { exit }.join }.to raise_error(SystemExit)   
    
    推荐文章