addasd
addasd

Reputation: 21

How to unit test for exception in threads

I need to unit test that an exception in raised in code like:

def test
  assert_raise Timeout::Error do
    Thread.new {
      raise  Timeout::Error
    }
  end
end

How to get this working?

Upvotes: 2

Views: 279

Answers (1)

Rein Henrichs
Rein Henrichs

Reputation: 15605

in the assert_raise block:

t = Thread.new { raise Timeout::Error }
t.join

Upvotes: 1

Related Questions