2010-09-17 19:56:32 -04:00
|
|
|
require 'spec_helper'
|
2009-12-13 08:33:14 -05:00
|
|
|
|
|
|
|
describe Capybara::Server do
|
|
|
|
|
|
|
|
it "should spool up a rack server" do
|
|
|
|
@app = proc { |env| [200, {}, "Hello Server!"]}
|
2010-01-30 14:31:52 -05:00
|
|
|
@server = Capybara::Server.new(@app).boot
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res.body.should include('Hello Server')
|
|
|
|
end
|
2010-03-12 13:14:10 -05:00
|
|
|
|
|
|
|
it "should do nothing when no server given" do
|
|
|
|
running do
|
|
|
|
@server = Capybara::Server.new(nil).boot
|
|
|
|
end.should_not raise_error
|
|
|
|
end
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2010-09-02 09:03:49 -04:00
|
|
|
it "should use specified port" do
|
|
|
|
Capybara.server_port = 22789
|
|
|
|
|
|
|
|
@app = proc { |env| [200, {}, "Hello Server!"]}
|
|
|
|
@server = Capybara::Server.new(@app).boot
|
2010-09-28 16:37:43 -04:00
|
|
|
|
2010-09-02 09:03:49 -04:00
|
|
|
@res = Net::HTTP.start(@server.host, 22789) { |http| http.get('/') }
|
|
|
|
@res.body.should include('Hello Server')
|
|
|
|
|
|
|
|
Capybara.server_port = nil
|
|
|
|
end
|
2010-09-28 16:37:43 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
it "should find an available port" do
|
|
|
|
@app1 = proc { |env| [200, {}, "Hello Server!"]}
|
|
|
|
@app2 = proc { |env| [200, {}, "Hello Second Server!"]}
|
|
|
|
|
2010-01-30 14:31:52 -05:00
|
|
|
@server1 = Capybara::Server.new(@app1).boot
|
|
|
|
@server2 = Capybara::Server.new(@app2).boot
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res1 = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') }
|
|
|
|
@res1.body.should include('Hello Server')
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res2 = Net::HTTP.start(@server2.host, @server2.port) { |http| http.get('/') }
|
|
|
|
@res2.body.should include('Hello Second Server')
|
|
|
|
end
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
it "should use the server if it already running" do
|
|
|
|
@app1 = proc { |env| [200, {}, "Hello Server!"]}
|
|
|
|
@app2 = proc { |env| [200, {}, "Hello Second Server!"]}
|
|
|
|
|
2010-01-30 14:31:52 -05:00
|
|
|
@server1a = Capybara::Server.new(@app1).boot
|
|
|
|
@server1b = Capybara::Server.new(@app1).boot
|
|
|
|
@server2a = Capybara::Server.new(@app2).boot
|
|
|
|
@server2b = Capybara::Server.new(@app2).boot
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res1 = Net::HTTP.start(@server1b.host, @server1b.port) { |http| http.get('/') }
|
|
|
|
@res1.body.should include('Hello Server')
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@res2 = Net::HTTP.start(@server2b.host, @server2b.port) { |http| http.get('/') }
|
|
|
|
@res2.body.should include('Hello Second Server')
|
2010-09-15 12:19:50 -04:00
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
@server1a.port.should == @server1b.port
|
|
|
|
@server2a.port.should == @server2b.port
|
|
|
|
end
|
|
|
|
|
2010-11-17 10:40:39 -05:00
|
|
|
it "should wait specified time for the app to boot" do
|
2011-03-05 18:02:52 -05:00
|
|
|
pending 'this test does not work: https://groups.google.com/d/msg/ruby-capybara/QrSKTbjh5rY/egvcVFYiWZMJ'
|
|
|
|
|
2010-11-17 10:40:39 -05:00
|
|
|
@slow_app = proc { |env| sleep(1); [200, {}, "Hello Slow Server!"] }
|
|
|
|
|
|
|
|
Capybara.server_boot_timeout = 1.5
|
|
|
|
@server = Capybara::Server.new(@slow_app).boot
|
|
|
|
|
|
|
|
@res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
|
|
|
|
@res.body.should include('Hello Slow Server')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise an exception if boot timeout is exceeded" do
|
2011-03-05 18:02:52 -05:00
|
|
|
pending 'this test does not work: https://groups.google.com/d/msg/ruby-capybara/QrSKTbjh5rY/egvcVFYiWZMJ'
|
|
|
|
|
2010-11-17 10:40:39 -05:00
|
|
|
@slow_app = proc { |env| sleep(1); [200, {}, "Hello Slow Server!"] }
|
|
|
|
|
|
|
|
Capybara.server_boot_timeout = 0.5
|
2010-11-21 12:37:51 -05:00
|
|
|
server = Capybara::Server.new(@slow_app)
|
|
|
|
server.stub(:exit).and_return(:timeout)
|
|
|
|
server.stub(:puts)
|
|
|
|
server.boot.should == :timeout
|
2010-11-17 10:40:39 -05:00
|
|
|
end
|
|
|
|
|
2009-12-13 08:33:14 -05:00
|
|
|
end
|