class RSpec::BecomeMatcher::Matcher
Constants
- DEFAULT_LIMIT
Attributes
current[R]
expected[R]
expected_block[R]
limit[R]
was[R]
Public Class Methods
new(expected, &block)
click to toggle source
# File lib/rspec/become_matcher.rb, line 9 def initialize(expected, &block) @expected = expected @expected_block = block @limit = DEFAULT_LIMIT end
Public Instance Methods
failure_message()
click to toggle source
# File lib/rspec/become_matcher.rb, line 41 def failure_message <<~MESSAGE Expected #{was} to become #{expected || 'given block'} in #{limit.to_i} second, but not MESSAGE end
failure_message_when_negated()
click to toggle source
# File lib/rspec/become_matcher.rb, line 47 def failure_message_when_negated <<~MESSAGE Expected #{was} not to become #{expected || 'given block'} in #{limit.to_i} second MESSAGE end
in(limit)
click to toggle source
# File lib/rspec/become_matcher.rb, line 36 def in(limit) @limit = limit self end
matches?(block)
click to toggle source
# File lib/rspec/become_matcher.rb, line 15 def matches?(block) Timeout.timeout(limit) do @was = @current = block.call @current = begin sleep 0.1 block.call end until matching_now? true end rescue Timeout::Error false end
matching_now?()
click to toggle source
# File lib/rspec/become_matcher.rb, line 28 def matching_now? if expected_block expected_block.call(current) else current == expected end end
supports_block_expectations?()
click to toggle source
# File lib/rspec/become_matcher.rb, line 53 def supports_block_expectations? true end