Skip to content

Instantly share code, notes, and snippets.

@pierrickouw
Last active June 28, 2023 08:53
Show Gist options
  • Save pierrickouw/65ec4af6072965784d8cd81b042da500 to your computer and use it in GitHub Desktop.
Save pierrickouw/65ec4af6072965784d8cd81b042da500 to your computer and use it in GitHub Desktop.
# make sure all expect wait for turbo before expecting
module RSpec
module Matchers
expect_old = instance_method(:expect).bind(self)
define_method(:expect) do |*args, &block|
expect_old.call(page).not_to have_selector('html[aria-busy="true"]')
expect_old.call(page).not_to have_selector('turbo-frame[busy]')
expect_old.call(*args, &block)
end
end
end
# make sure we wait for turbo after every `click_on`, etc
module Capybara
module DSL
def page
Capybara.current_session
end
Session::DSL_METHODS.each do |method|
class_eval <<~METHOD, __FILE__, __LINE__ + 1
def #{method}(...)
page.method("#{method}").call(...)
expect(page).not_to have_selector('html[aria-busy="true"]')
expect(page).not_to have_selector('turbo-frame[busy]')
end
METHOD
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment