Last active
August 29, 2015 14:14
-
-
Save gpleiss/ff68ac8eeee6193e903d to your computer and use it in GitHub Desktop.
Example of Capybara `synchronize` in a matcher
This file contains 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
def has_analytics_message?(msg) | |
document.synchronize do |variable| | |
gaq = evaluate_script('window._gaq') | |
raise Capybara::ElementNotFound, "#{msg} was not fired.\nActual analytics events triggered:\n\n#{gaq}" unless gaq.include?(msg) | |
end | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This matcher is checking the
window._gaq
javascript variable to see if it has a value.We need to wrap this in a
synchronize
block, because we want to wait until this javascript block becomes true.The thing that always gets me: the
synchronize
block needs to throw aCapybara::ElementNotFound
exception. When this exception is caught, it reruns the synchronize block until it's true, or until the default timeout is hit.