KZcoding
KZcoding

Reputation: 1517

rspec: How to capture exit from a new thread?

So, I am able to capture exit in rspec this way:

expect { exit }.to raise_error(SystemExit)

But, if the exit was called inside a new thread, the whole rspec run exits:

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

Is there a way to capture exit from a new thread gracefully?

Upvotes: 1

Views: 87

Answers (1)

Gregory Ostermayr
Gregory Ostermayr

Reputation: 1121

I don't know if this is exactly what you want, but you can call join on that newly created thread. That seems to work for me.

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

Upvotes: 1

Related Questions