Sha256: c09b0074c9a9385e9c43eab849a17ae71d08f15083147c5b49410b7c402e4ae9

Contents?: true

Size: 612 Bytes

Versions: 1

Compression:

Stored size: 612 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|
    wait_for do
      block_arg.call == expected
    end
    true
  rescue Timeout::Error
    false
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.4 lib/plumbing/spec/become_equal_to_matcher.rb