mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Default server to puma and improve reuse_server tests
This commit is contained in:
parent
ecfe2b4eb4
commit
1a07da3d10
7 changed files with 33 additions and 15 deletions
|
@ -14,3 +14,5 @@ gem 'rspec-mocks', github: 'rspec/rspec-mocks'
|
|||
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
|
||||
gem 'cucumber', github: 'cucumber/cucumber-ruby'
|
||||
|
||||
gem 'puma', github: 'puma/puma'
|
||||
|
||||
|
|
|
@ -8,3 +8,5 @@ gem 'xpath', github: 'teamcapybara/xpath'
|
|||
gem 'selenium-webdriver', :path => '../../selenium/build/rb'
|
||||
gem 'rack', github: 'rack/rack'
|
||||
gem 'sinatra', github: 'sinatra/sinatra', branch: 'master'
|
||||
|
||||
gem 'puma', github: 'puma/puma'
|
|
@ -5,4 +5,3 @@ gemspec :path => '..'
|
|||
|
||||
gem 'xpath', github: 'teamcapybara/xpath'
|
||||
gem 'rspec', '~>3.4.0'
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ module Capybara
|
|||
# @param [Integer] port The port to run the application on
|
||||
#
|
||||
def run_default_server(app, port)
|
||||
servers[:webrick].call(app, port, server_host)
|
||||
servers[:puma].call(app, port, server_host)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -186,5 +186,5 @@ class TestApp < Sinatra::Base
|
|||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
Rack::Handler::WEBrick.run TestApp, Port: 8070
|
||||
Rack::Handler::Puma.run TestApp, Port: 8070
|
||||
end
|
||||
|
|
|
@ -79,6 +79,19 @@ RSpec.describe Capybara do
|
|||
end
|
||||
end
|
||||
|
||||
describe "server=" do
|
||||
after do
|
||||
Capybara.server = :default
|
||||
end
|
||||
|
||||
it "should have a :webrick server registered" do
|
||||
Capybara.server = :webrick
|
||||
session = Capybara::Session.new(:selenium, TestApp.new)
|
||||
session.visit('/')
|
||||
expect(session.body).to include("Hello world!")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'app_host' do
|
||||
after do
|
||||
Capybara.app_host = nil
|
||||
|
|
|
@ -98,24 +98,23 @@ RSpec.describe Capybara::Server do
|
|||
end
|
||||
|
||||
it "detects and waits for all reused server sessions pending requests" do
|
||||
done = false
|
||||
done = 0
|
||||
|
||||
app = proc do |env|
|
||||
request = Rack::Request.new(env)
|
||||
sleep request.params['wait_time'].to_f
|
||||
done = true
|
||||
done += 1
|
||||
[200, {}, ["Hello Server!"]]
|
||||
end
|
||||
|
||||
server1 = Capybara::Server.new(app).boot
|
||||
server2 = Capybara::Server.new(app).boot
|
||||
|
||||
start_request(server1, 0.5)
|
||||
start_request(server2, 1.0)
|
||||
|
||||
expect {
|
||||
start_request(server1, 1.0)
|
||||
start_request(server2, 3.0)
|
||||
server1.wait_for_pending_requests
|
||||
}.to change{done}.from(false).to(true)
|
||||
}.to change{done}.from(0).to(2)
|
||||
expect(server2.send(:pending_requests?)).to eq(false)
|
||||
end
|
||||
|
||||
|
@ -147,25 +146,27 @@ RSpec.describe Capybara::Server do
|
|||
end
|
||||
|
||||
it "detects and waits for only one sessions pending requests" do
|
||||
done = false
|
||||
done = 0
|
||||
|
||||
app = proc do |env|
|
||||
request = Rack::Request.new(env)
|
||||
sleep request.params['wait_time'].to_f
|
||||
done = true
|
||||
done += 1
|
||||
[200, {}, ["Hello Server!"]]
|
||||
end
|
||||
|
||||
server1 = Capybara::Server.new(app).boot
|
||||
server2 = Capybara::Server.new(app).boot
|
||||
|
||||
start_request(server1, 0.5)
|
||||
start_request(server2, 1.0)
|
||||
|
||||
expect {
|
||||
start_request(server1, 1.0)
|
||||
start_request(server2, 3.0)
|
||||
server1.wait_for_pending_requests
|
||||
}.to change{done}.from(false).to(true)
|
||||
}.to change{done}.from(0).to(1)
|
||||
expect(server2.send(:pending_requests?)).to eq(true)
|
||||
expect {
|
||||
server2.wait_for_pending_requests
|
||||
}.to change{done}.from(1).to(2)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -199,6 +200,7 @@ RSpec.describe Capybara::Server do
|
|||
# Start request, but don't wait for it to finish
|
||||
socket = TCPSocket.new(server.host, server.port)
|
||||
socket.write "GET /?wait_time=#{wait_time.to_s} HTTP/1.0\r\n\r\n"
|
||||
sleep 0.1
|
||||
socket.close
|
||||
sleep 0.1
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue