mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Allow the Rack handler to be configured via Capybara.server {|app, port| ...}
For example, to use mongrel rather than thin or webrick: Capybara.server do |app, port| require 'rack/handler/mongrel' Rack::Handler::Mongrel.run(app, :Port => port) end
This commit is contained in:
parent
d34c2bf10a
commit
91e59f3572
3 changed files with 52 additions and 8 deletions
|
@ -108,6 +108,38 @@ module Capybara
|
|||
@drivers ||= {}
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Register a proc that Capybara will call to run the Rack application.
|
||||
#
|
||||
# Capybara.server do |app, port|
|
||||
# require 'rack/handler/mongrel'
|
||||
# Rack::Handler::Mongrel.run(app, :Port => port)
|
||||
# end
|
||||
#
|
||||
# By default, Capybara will try to run thin, falling back to webrick.
|
||||
#
|
||||
# @yield [app, port] This block recieves a rack app and port and should run a Rack handler
|
||||
#
|
||||
def server(&block)
|
||||
if block_given?
|
||||
@server = block
|
||||
else
|
||||
@server
|
||||
end
|
||||
end
|
||||
|
||||
def run_default_server(app, port)
|
||||
begin
|
||||
require 'rack/handler/thin'
|
||||
Thin::Logging.silent = true
|
||||
Rack::Handler::Thin.run(app, :Port => port)
|
||||
rescue LoadError
|
||||
require 'rack/handler/webrick'
|
||||
Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
||||
end
|
||||
end
|
||||
|
||||
def deprecate(method, alternate_method)
|
||||
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
|
||||
end
|
||||
|
@ -133,6 +165,7 @@ end
|
|||
|
||||
Capybara.configure do |config|
|
||||
config.run_server = true
|
||||
config.server {|app, port| Capybara.run_default_server(app, port)}
|
||||
config.default_selector = :css
|
||||
config.default_wait_time = 2
|
||||
config.ignore_hidden_elements = false
|
||||
|
|
|
@ -62,14 +62,7 @@ module Capybara
|
|||
Capybara::Server.ports[@app.object_id] = @port
|
||||
|
||||
Thread.new do
|
||||
begin
|
||||
require 'rack/handler/thin'
|
||||
Thin::Logging.silent = true
|
||||
Rack::Handler::Thin.run(Identify.new(@app), :Port => @port)
|
||||
rescue LoadError
|
||||
require 'rack/handler/webrick'
|
||||
Rack::Handler::WEBrick.run(Identify.new(@app), :Port => @port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
||||
end
|
||||
Capybara.server.call(Identify.new(@app), @port)
|
||||
end
|
||||
|
||||
Capybara.timeout(10) { if responsive? then true else sleep(0.5) and false end }
|
||||
|
|
|
@ -25,4 +25,22 @@ describe Capybara do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".server" do
|
||||
after do
|
||||
Capybara.server {|app, port| Capybara.run_default_server(app, port)}
|
||||
end
|
||||
|
||||
it "should default to a proc that calls run_default_server" do
|
||||
mock_app = mock('app')
|
||||
Capybara.should_receive(:run_default_server).with(mock_app, 8000)
|
||||
Capybara.server.call(mock_app, 8000)
|
||||
end
|
||||
|
||||
it "should return a custom server proc" do
|
||||
server = lambda {|app, port|}
|
||||
Capybara.server(&server)
|
||||
Capybara.server.should == server
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue