diff --git a/README.md b/README.md index 14123d3..4fa2a01 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,9 @@ makes debugging easier). Running `rake autocompile` will watch the * Fix bug with page Javascript page loading causing problems. [Issue #19] +* Raise an error if a URL fails to load in response to `#visit` or + `#click`. + ### 0.3.0 ### * There was a bad bug to do with clicking elements in a page where the diff --git a/lib/capybara/poltergeist/client/browser.coffee b/lib/capybara/poltergeist/client/browser.coffee index 6992ae7..3ca1b02 100644 --- a/lib/capybara/poltergeist/client/browser.coffee +++ b/lib/capybara/poltergeist/client/browser.coffee @@ -13,7 +13,11 @@ class Poltergeist.Browser @page.onLoadFinished = (status) => if @state == 'loading' - @owner.sendResponse(status) + if status == 'success' + @owner.sendResponse(true) + else + @owner.sendError('URL failed to load') + @state = 'default' visit: (url) -> diff --git a/lib/capybara/poltergeist/client/compiled/browser.js b/lib/capybara/poltergeist/client/compiled/browser.js index 8f7487b..419357c 100644 --- a/lib/capybara/poltergeist/client/compiled/browser.js +++ b/lib/capybara/poltergeist/client/compiled/browser.js @@ -17,7 +17,11 @@ Poltergeist.Browser = (function() { }, this); return this.page.onLoadFinished = __bind(function(status) { if (this.state === 'loading') { - this.owner.sendResponse(status); + if (status === 'success') { + this.owner.sendResponse(true); + } else { + this.owner.sendError('URL failed to load'); + } return this.state = 'default'; } }, this); diff --git a/lib/capybara/poltergeist/client/compiled/main.js b/lib/capybara/poltergeist/client/compiled/main.js index b9ef65e..2caae12 100644 --- a/lib/capybara/poltergeist/client/compiled/main.js +++ b/lib/capybara/poltergeist/client/compiled/main.js @@ -8,9 +8,7 @@ Poltergeist = (function() { try { return this.browser[command.name].apply(this.browser, command.args); } catch (error) { - return this.connection.send({ - error: error.toString() - }); + return this.sendError(error.toString()); } }; Poltergeist.prototype.sendResponse = function(response) { @@ -18,6 +16,11 @@ Poltergeist = (function() { response: response }); }; + Poltergeist.prototype.sendError = function(message) { + return this.connection.send({ + error: message + }); + }; return Poltergeist; })(); Poltergeist.ObsoleteNode = (function() { diff --git a/lib/capybara/poltergeist/client/main.coffee b/lib/capybara/poltergeist/client/main.coffee index 5a07201..5cf8a07 100644 --- a/lib/capybara/poltergeist/client/main.coffee +++ b/lib/capybara/poltergeist/client/main.coffee @@ -7,11 +7,14 @@ class Poltergeist try @browser[command.name].apply(@browser, command.args) catch error - @connection.send({ error: error.toString() }) + this.sendError(error.toString()) sendResponse: (response) -> @connection.send({ response: response }) + sendError: (message) -> + @connection.send({ error: message }) + class Poltergeist.ObsoleteNode toString: -> "Poltergeist.ObsoleteNode" diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 13bf10e..492f11a 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -99,5 +99,9 @@ describe Capybara::Session do sleep 0.1 @session.body.should include("Hello world") end + + it "raises an error if a load fails" do + expect { @session.visit 'omgwtfbbq12345632' }.to raise_error(Capybara::Poltergeist::BrowserError) + end end end