From d84d7668449e96856c5f6bac8cb1526b6d357ce3 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 4 Apr 2018 11:22:49 +0200 Subject: [PATCH] Fix block_caller * First wait the Thread start, then wait until it blocks or finishes. * The bug would be to quit as soon as started is set, even if the Thread never blocked. * Fixes https://github.com/ruby/mspec/issues/39. --- lib/mspec/matchers/block_caller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/mspec/matchers/block_caller.rb b/lib/mspec/matchers/block_caller.rb index 017bce3c..41495867 100644 --- a/lib/mspec/matchers/block_caller.rb +++ b/lib/mspec/matchers/block_caller.rb @@ -10,7 +10,11 @@ def matches?(block) blocking = false end - while !started and status = thread.status and status != "sleep" + Thread.pass while !started + + # Wait until the Thread status is "sleep" (then it's blocking) + # or nil (the Thread finished execution, it did not block) + while status = thread.status and status != "sleep" Thread.pass end thread.kill