Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #661 from raggi/catch_server_errors

Add code to catch server errors at server boot time, and during responsi...
  • Loading branch information...
commit 990fbc9f43d9ff0c9551df50cbd9b8e69bc8c552 2 parents bb7f4b1 + ab62b27
Jonas Nicklas jnicklas authored
Showing with 22 additions and 2 deletions.
  1. +5 −2 lib/capybara/server.rb
  2. +17 −0 spec/server_spec.rb
7 lib/capybara/server.rb
View
@@ -28,6 +28,7 @@ def ports
def initialize(app)
@app = app
+ @server_thread = nil # supress warnings
end
def host
@@ -43,6 +44,8 @@ def url(path)
end
def responsive?
+ return false if @server_thread && @server_thread.join(0)
+
res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
@@ -60,11 +63,11 @@ def boot
@port = Capybara.server_port || find_available_port
Capybara::Server.ports[@app.object_id] = @port
- Thread.new do
+ @server_thread = Thread.new do
Capybara.server.call(Identify.new(@app), @port)
end
- Timeout.timeout(60) { sleep(0.1) until responsive? }
+ Timeout.timeout(60) { @server_thread.join(0.1) until responsive? }
end
end
rescue TimeoutError
17 spec/server_spec.rb
View
@@ -71,4 +71,21 @@
@server1a.port.should == @server1b.port
@server2a.port.should == @server2b.port
end
+
+ it "should raise server errors when the server errors before the timeout" do
+ begin
+ Capybara.server do
+ sleep 0.1
+ raise 'kaboom'
+ end
+
+ proc do
+ Capybara::Server.new(proc {|e|}).boot
+ end.should raise_error(RuntimeError, 'kaboom')
+ ensure
+ # TODO refactor out the defaults so it's reliant on unset state instead of
+ # a one-time call in capybara.rb
+ Capybara.server {|app, port| Capybara.run_default_server(app, port)}
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.