Class: BlockingMatcher

Inherits:
Object show all
Defined in:
lib/extensions/mspec/mspec/matchers/block_caller.rb

Instance Method Summary collapse

Instance Method Details

#failure_messageObject



22
23
24
# File 'lib/extensions/mspec/mspec/matchers/block_caller.rb', line 22

def failure_message
  ['Expected the given Proc', 'to block the caller']
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/extensions/mspec/mspec/matchers/block_caller.rb', line 2

def matches?(block)
  started = false
  blocking = true

  thread = Thread.new do
    started = true
    block.call

    blocking = false
  end

  while !started and status = thread.status and status != "sleep"
    Thread.pass
  end
  thread.kill
  thread.join

  blocking
end

#negative_failure_messageObject



26
27
28
# File 'lib/extensions/mspec/mspec/matchers/block_caller.rb', line 26

def negative_failure_message
  ['Expected the given Proc', 'to not block the caller']
end