Class: BlockingMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(timeout = 0.1) ⇒ BlockingMatcher

Returns a new instance of BlockingMatcher.



2
3
4
# File 'lib/mspec/matchers/block_caller.rb', line 2

def initialize(timeout = 0.1)
  @timeout = timeout
end

Instance Method Details

#failure_messageObject



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

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

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(block)
  blocking = true

  thread = Thread.new do
    block.call

    blocking = false
  end

  thread.join(@timeout)
  thread.kill

  blocking
end

#negative_failure_messageObject



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

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