Sha256: cba730711c5e73e2d0f3bafbed25cc09be00f8bf67191182a53b4e38440db11a

Contents?: true

Size: 753 Bytes

Versions: 3

Compression:

Stored size: 753 Bytes

Contents

require "rspec/expectations"

# Custom matcher that repeatedly evaluates the block until it matches the expected value or 5 seconds have elapsed
#
# This allows asynchronous operations to be tested in a synchronous manner with a timeout
#
# Example:
#     expect("Hello").to become_equal_to { subject.greeting }
#
RSpec::Matchers.define :become_equal_to do
  match do |expected|
    max = Plumbing.config.timeout * 10
    counter = 0
    matched = false
    while (counter < max) && (matched == false)
      sleep 0.1
      counter += 1
      matched = true if (@result = block_arg.call) == expected
    end
    matched
  end

  failure_message do |expected|
    "expected block to return #{expected} but was #{@result} after timeout expired"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.3 spec/become_equal_to_matcher.rb
standard-procedure-plumbing-0.4.2 spec/become_equal_to_matcher.rb
standard-procedure-plumbing-0.4.1 spec/become_equal_to_matcher.rb