Skip to content

Instantly share code, notes, and snippets.

@juno
Forked from jnicklas/wait_steps.rb
Last active December 16, 2015 15:48
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 juno/9a35586fca6c3671d555 to your computer and use it in GitHub Desktop.
Save juno/9a35586fca6c3671d555 to your computer and use it in GitHub Desktop.
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