Skip to content

Instantly share code, notes, and snippets.

@juno

juno/usage.rb

Forked from jnicklas/wait_steps.rb
Last active Dec 16, 2015
Embed
What would you like to do?
waiting async processing helper for Capybara 2.5.0
scenario 'User likes the post' do
visit post_path
click_button 'Like'
expect { page.has_css?('.liked-icon') }.to become_true
end
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
You can’t perform that action at this time.