Last active
December 16, 2015 02:29
-
-
Save blatyo/5363393 to your computer and use it in GitHub Desktop.
In order to avoid sleeping for long periods of time, switch to a frequent polling mechanism, so the success case is fast.
This file contains hidden or 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
| expect{current_path}.to eventually_eql('/') | |
| expect{current_path}.to eventually_match(%r{/boxes/PS\d+/shipping_information/new}) | |
| expect{get_me_the_cookie('foo')[:value]}.to eventually_eql('bar') |
This file contains hidden or 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" | |
| module PollingMatchers | |
| extend RSpec::Matchers::DSL | |
| def eventually(actual_block, operator, expected) | |
| Timeout.timeout(Capybara.default_wait_time) do | |
| sleep(0.1) until actual_block.call.send(operator, expected) | |
| true | |
| end | |
| rescue TimeoutError | |
| false | |
| end | |
| matcher :eventually_eql do |expected| | |
| match do |block| | |
| eventually(block, :==, expected) | |
| end | |
| end | |
| matcher :eventually_match do |expected_regex| | |
| match do |block| | |
| eventually(block, :=~, expected_regex) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment