Last active
November 20, 2015 18:27
-
-
Save ebeigarts/0c273ea93a5dcd766f77 to your computer and use it in GitHub Desktop.
become_matcher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "timeout" | |
RSpec::Matchers.define :become do |expected| | |
supports_block_expectations | |
match do |block| | |
begin | |
Timeout.timeout(Capybara.default_wait_time * 3) do | |
sleep(0.1) until (@actual = block.call) && @actual == expected | |
true | |
end | |
rescue TimeoutError | |
false | |
end | |
end | |
failure_message do | |
"expected #{@actual.inspect} to become #{expected.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment