Compare commits

...

1 Commits

Author SHA1 Message Date
Damian Janowski 39183b031a Limit the amount of error pages open. 2010-04-23 18:57:11 -03:00
4 changed files with 36 additions and 5 deletions

View File

@ -42,7 +42,7 @@ module Webrat
# Which port should selenium use to access the application. Defaults to application_port
attr_writer :application_port_for_selenium
def application_port_for_selenium
@application_port_for_selenium || self.application_port
end
@ -91,9 +91,9 @@ module Webrat
tmp_dir = Pathname.new(Dir.pwd).join("tmp")
self.saved_pages_dir = tmp_dir.exist? ? tmp_dir : Dir.pwd
end
def open_error_files? #:nodoc:
@open_error_files ? true : false
!! @open_error_files
end
# Allows setting of webrat's mode, valid modes are:

View File

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

View File

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

View File

@ -58,6 +58,24 @@ class WebratRackTest < Test::Unit::TestCase
assert_equal "webrat_rack_test.rb", upload[:filename]
assert_equal File.read(__FILE__), upload[:tempfile]
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
class WebratRackSetupTest < Test::Unit::TestCase