summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-27 20:38:20 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-27 20:38:20 +0000
commiteae7fbb6820db5e1bb3e9e5626fbb5e97052f6a2 (patch)
treea389cfc553f8bdafcfad9d2aab5fba47353bf2e3 /spec
parent047111584f0e3d8e5d0e52cdda2a674d418e9af4 (diff)
Update to ruby/mspec@820486a
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/mspec/lib/mspec/matchers/block_caller.rb34
1 files changed, 16 insertions, 18 deletions
diff --git a/spec/mspec/lib/mspec/matchers/block_caller.rb b/spec/mspec/lib/mspec/matchers/block_caller.rb
index 4149586747..30fab4fc68 100644
--- a/spec/mspec/lib/mspec/matchers/block_caller.rb
+++ b/spec/mspec/lib/mspec/matchers/block_caller.rb
@@ -1,26 +1,24 @@
class BlockingMatcher
def matches?(block)
- started = false
- blocking = true
-
- thread = Thread.new do
- started = true
+ t = Thread.new do
block.call
-
- blocking = false
end
- 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
+ loop do
+ case t.status
+ when "sleep" # blocked
+ t.kill
+ t.join
+ return true
+ when false # terminated normally, so never blocked
+ t.join
+ return false
+ when nil # terminated exceptionally
+ t.value
+ else
+ Thread.pass
+ end
end
- thread.kill
- thread.join
-
- blocking
end
def failure_message
@@ -33,7 +31,7 @@ class BlockingMatcher
end
module MSpecMatchers
- private def block_caller(timeout = 0.1)
+ private def block_caller
BlockingMatcher.new
end
end