-
-
Save juno/9a35586fca6c3671d555 to your computer and use it in GitHub Desktop.
waiting async processing helper for Capybara 2.5.0
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
scenario 'User likes the post' do | |
visit post_path | |
click_button 'Like' | |
expect { page.has_css?('.liked-icon') }.to become_true | |
end |
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' | |
# Wating async processing helper. | |
# | |
# Examples | |
# | |
# expect { page.has_css?('...') }.to become_true | |
# | |
module WaitSteps | |
extend RSpec::Matchers::DSL | |
matcher :become_true do | |
match do |block| | |
begin | |
Timeout.timeout(Capybara.default_max_wait_time) do | |
value = nil | |
loop do | |
value = block.call | |
break if value | |
sleep(0.1) | |
end | |
value | |
end | |
rescue TimeoutError | |
false | |
end | |
end | |
def supports_block_expectations? | |
true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment