Sha256: fd63d79353dfa693b5142720297bd35e396f27f0541315dab7d28fb3f1a5e10f

Contents?: true

Size: 713 Bytes

Versions: 3

Compression:

Stored size: 713 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|
    counter = 0
    matched = false
    while (counter < 50) && (matched == false)
      matched = true if (@result = block_arg.call) == expected
      sleep 0.1
      counter += 1
    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.0 spec/become_equal_to_matcher.rb
standard-procedure-plumbing-0.3.3 spec/become_equal_to_matcher.rb
standard-procedure-plumbing-0.3.2 spec/become_equal_to_matcher.rb