Skip to content

Instantly share code, notes, and snippets.

@ebeigarts
Last active November 20, 2015 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebeigarts/0c273ea93a5dcd766f77 to your computer and use it in GitHub Desktop.
Save ebeigarts/0c273ea93a5dcd766f77 to your computer and use it in GitHub Desktop.
become_matcher.rb
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