ruby-changes:53821
From: eregon <ko1@a...>
Date: Wed, 28 Nov 2018 05:38:26 +0900 (JST)
Subject: [ruby-changes:53821] eregon:r66039 (trunk): Update to ruby/mspec@820486a
eregon 2018-11-28 05:38:20 +0900 (Wed, 28 Nov 2018) New Revision: 66039 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66039 Log: Update to ruby/mspec@820486a Modified files: trunk/spec/mspec/lib/mspec/matchers/block_caller.rb Index: spec/mspec/lib/mspec/matchers/block_caller.rb =================================================================== --- spec/mspec/lib/mspec/matchers/block_caller.rb (revision 66038) +++ spec/mspec/lib/mspec/matchers/block_caller.rb (revision 66039) @@ -1,26 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/block_caller.rb#L1 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 https://github.com/ruby/ruby/blob/trunk/spec/mspec/lib/mspec/matchers/block_caller.rb#L31 end module MSpecMatchers - private def block_caller(timeout = 0.1) + private def block_caller BlockingMatcher.new end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/