Raise Webrat::PageLoadError when a failure occurs so that application exceptions can be more accurately tested (Ryan Briones)
This commit is contained in:
parent
59704da270
commit
82c6be380e
@ -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
|
== 0.3.2 / 2008-11-08
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
|
@ -8,6 +8,9 @@ module Webrat
|
|||||||
def self.root #:nodoc:
|
def self.root #:nodoc:
|
||||||
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
|
defined?(RAILS_ROOT) ? RAILS_ROOT : Merb.root
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class WebratError < StandardError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# We need Nokogiri's CSS to XPath support, even if using REXML
|
# We need Nokogiri's CSS to XPath support, even if using REXML
|
||||||
|
@ -4,10 +4,12 @@ require "ostruct"
|
|||||||
require "webrat/core/mime"
|
require "webrat/core/mime"
|
||||||
|
|
||||||
module Webrat
|
module Webrat
|
||||||
|
class PageLoadError < WebratError
|
||||||
|
end
|
||||||
|
|
||||||
class Session
|
class Session
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Logging
|
include Logging
|
||||||
include Flunk
|
|
||||||
|
|
||||||
attr_reader :current_url
|
attr_reader :current_url
|
||||||
|
|
||||||
@ -85,7 +87,7 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
save_and_open_page if exception_caught?
|
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
|
@_scopes = nil
|
||||||
@_page_scope = nil
|
@_page_scope = nil
|
||||||
|
@ -70,4 +70,19 @@ describe Webrat::Session do
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user