module Capybara::Compose::Synchronization
Internal: Provides helper functions to perform asynchronous assertions.
Constants
- EXPECTATION_ERRORS
Internal: Errors that will be retried in a `synchronize_expectation` block.
Protected Instance Methods
synchronize(wait: Capybara.default_max_wait_time, **options, &block)
click to toggle source
Public: Used to implement more specific synchronization helpers.
By default Capybara's methods like `find` and `have_css` already use synchronize to achieve asynchronicity, so it's not necessary to use this.
# File lib/capybara/compose/synchronization.rb, line 38 def synchronize(wait: Capybara.default_max_wait_time, **options, &block) (current_element? ? current_context : page.document).synchronize(wait, **options, &block) end
synchronize_expectation(retry_on_errors: [], **options) { || ... }
click to toggle source
Public: Can be used to make an asynchronous expectation, that will be retried until the max wait time configured in Capybara
.
# File lib/capybara/compose/synchronization.rb, line 20 def synchronize_expectation(retry_on_errors: [], **options) synchronize(errors: EXPECTATION_ERRORS + retry_on_errors, **options) { begin yield rescue RSpec::Expectations::ExpectationNotMetError => error # NOTE: Rethrow as ExpectationError because the RSpec exception is not # a StandardError so capybara wouldn't rescue it inside synchronize. raise ExpectationError, error end } rescue ExpectationError => error raise error.cause # Unwrap this internal error and raise the original error. end