Raise Webrat::PageLoadError when a failure occurs so that application exceptions can be more accurately tested (Ryan Briones)

This commit is contained in:
Bryan Helmkamp 2008-11-10 14:15:40 -05:00
parent 59704da270
commit 82c6be380e
4 changed files with 28 additions and 2 deletions

View File

@ -1,3 +1,9 @@
== Trunk
* Minor enhancements
* Raise Webrat::PageLoadError when a failure occurs so that application exceptions can be more accurately tested (Ryan Briones)
== 0.3.2 / 2008-11-08
* Minor enhancements

View File

@ -8,6 +8,9 @@ module Webrat
def self.root #:nodoc:
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
end
class WebratError < StandardError
end
end
# We need Nokogiri's CSS to XPath support, even if using REXML

View File

@ -4,10 +4,12 @@ require "ostruct"
require "webrat/core/mime"
module Webrat
class PageLoadError < WebratError
end
class Session
extend Forwardable
include Logging
include Flunk
attr_reader :current_url
@ -85,7 +87,7 @@ module Webrat
end
save_and_open_page if exception_caught?
flunk("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
@_scopes = nil
@_page_scope = nil

View File

@ -69,5 +69,20 @@ describe Webrat::Session do
lambda { @session.http_accept(:oogabooga) }.should raise_error(ArgumentError)
end
end
describe "#request_page" do
before(:each) do
@session = Webrat::Session.new
end
it "should raise an error if the request is not a success" do
@session.stub!(:get)
@session.stub!(:response_body).and_return("Exception caught")
@session.stub!(:response_code).and_return(500)
@session.stub!(:formatted_error).and_return("application error")
@session.stub!(:save_and_open_page)
lambda { @session.request_page('some url', :get, {}) }.should raise_error(Webrat::PageLoadError)
end
end
end