Permalink
Browse files

Limit the amount of error pages open.

  • Loading branch information...
1 parent 7cde057 commit 39183b031a1ddbb0b6b9cc5e9a8c39639770438f @djanowski djanowski committed Apr 23, 2010
@@ -42,7 +42,7 @@ class Configuration
# 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 @@ def initialize # :nodoc:
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
@@ -76,6 +76,7 @@ def initialize(adapter = nil)
@default_headers = {}
@custom_headers = {}
@current_url = nil
+ @exceptions = 0
reset
end
@@ -118,8 +119,7 @@ def request_page(url, http_method, data) #:nodoc:
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 @@ def reset
@_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
@@ -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__
@@ -58,6 +58,24 @@ def test_upload_file
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

0 comments on commit 39183b0

Please sign in to comment.