Last active
December 11, 2015 06:39
-
-
Save danmartens/4561192 to your computer and use it in GitHub Desktop.
Capybara JavaScript Helpers
This file contains hidden or 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
| # Example: | |
| # | |
| # it "should alert me" do | |
| # stub_browser_alert | |
| # | |
| # visit "/" | |
| # | |
| # wait_until { browser_alert_messages.count > 0 } | |
| # | |
| # browser_alert_messages.last.should eq("Hello World!") | |
| # end | |
| module CapybaraJavaScriptHelpers | |
| include Capybara::DSL | |
| def stub_browser_alert | |
| page.execute_script(%{ | |
| window.Capybara || (window.Capybara = {}); | |
| window.Capybara.alertMessages = []; | |
| window.alert = function(message) { | |
| window.Capybara.alertMessages.push(message); | |
| } | |
| }) | |
| end | |
| def browser_alert_messages | |
| page.evaluate_script("window.Capybara.alertMessages") | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment