Limit the amount of error pages open.

This commit is contained in:
Damian Janowski 2010-04-23 18:57:11 -03:00
parent 7cde0573c0
commit 39183b031a
4 changed files with 36 additions and 5 deletions

View File

@ -93,7 +93,7 @@ module Webrat
end end
def open_error_files? #:nodoc: def open_error_files? #:nodoc:
@open_error_files ? true : false !! @open_error_files
end end
# Allows setting of webrat's mode, valid modes are: # Allows setting of webrat's mode, valid modes are:

View File

@ -76,6 +76,7 @@ For example:
@default_headers = {} @default_headers = {}
@custom_headers = {} @custom_headers = {}
@current_url = nil @current_url = nil
@exceptions = 0
reset reset
end end
@ -118,8 +119,7 @@ For example:
process_request(http_method, url, data, h) process_request(http_method, url, data, h)
save_and_open_page if exception_caught? && Webrat.configuration.open_error_files? process_response_errors
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
reset reset
@ -299,5 +299,14 @@ For example:
@_page_scope = nil @_page_scope = nil
end end
def process_response_errors
if exception_caught? && @exceptions < 3 && Webrat.configuration.open_error_files?
save_and_open_page
@exceptions += 1
end
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
end
end end
end end

View File

@ -41,6 +41,10 @@ class RackApp < Sinatra::Base
uploaded_file = params[:uploaded_file] uploaded_file = params[:uploaded_file]
Marshal.dump(:tempfile => uploaded_file[:tempfile].read, :type => uploaded_file[:type], :filename => uploaded_file[:filename]) Marshal.dump(:tempfile => uploaded_file[:tempfile].read, :type => uploaded_file[:type], :filename => uploaded_file[:filename])
end end
get "/error" do
["Exception caught: you wanted it."]
end
end end
__END__ __END__

View File

@ -58,6 +58,24 @@ class WebratRackTest < Test::Unit::TestCase
assert_equal "webrat_rack_test.rb", upload[:filename] assert_equal "webrat_rack_test.rb", upload[:filename]
assert_equal File.read(__FILE__), upload[:tempfile] assert_equal File.read(__FILE__), upload[:tempfile]
end end
def test_open_errors
$open_pages = []
Webrat.configure do |config|
config.open_error_files = true
end
def webrat_session.open_in_browser(path)
$open_pages << path
end
5.times do
visit "/error"
end
assert_equal 3, $open_pages.size
end
end end
class WebratRackSetupTest < Test::Unit::TestCase class WebratRackSetupTest < Test::Unit::TestCase