Skip to content
Newer
Older
100644 84 lines (73 sloc) 2.58 KB
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
1 require 'spec_helper'
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
2 require 'capybara/webkit/connection'
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
3
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
4 describe Capybara::Webkit::Connection do
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
5 it "boots a server to talk to" do
61a6561 @mhoran Session is responsible for starting server
mhoran authored
6 url = "http://#{@rack_server.host}:#{@rack_server.port}/"
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
7 connection.puts "Visit"
8 connection.puts 1
9 connection.puts url.to_s.bytesize
10 connection.print url
11 connection.gets.should == "ok\n"
12 connection.gets.should == "0\n"
13 connection.puts "Body"
14 connection.puts 0
15 connection.gets.should == "ok\n"
16 response_length = connection.gets.to_i
17 response = connection.read(response_length)
18 response.should include("Hey there")
19 end
20
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
21 it 'forwards stderr to the given IO object' do
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
22 io = StringIO.new
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
23 redirected_connection = Capybara::Webkit::Connection.new(:stderr => io)
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
24 script = 'console.log("hello world")'
2ceab4e @mhoran Forward stderr via Open3#popen3
mhoran authored
25 redirected_connection.puts "EnableLogging"
26 redirected_connection.puts 0
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
27 redirected_connection.puts "Execute"
28 redirected_connection.puts 1
29 redirected_connection.puts script.to_s.bytesize
30 redirected_connection.print script
31 sleep(0.5)
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
32 io.string.should =~ /hello world $/
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
33 end
34
9bb7b93 @mhoran Don't forward stderr to nil
mhoran authored
35 it 'does not forward stderr to nil' do
36 IO.should_not_receive(:copy_stream)
37 Capybara::Webkit::Connection.new(:stderr => nil)
38 end
39
a70b7c4 @mhoran Deprecate the stdout option for Connection
mhoran authored
40 it 'prints a deprecation warning if the stdout option is used' do
41 Capybara::Webkit::Connection.any_instance.should_receive(:warn)
42 Capybara::Webkit::Connection.new(:stdout => nil)
43 end
44
45 it 'does not forward stdout to nil if the stdout option is used' do
46 Capybara::Webkit::Connection.any_instance.stub(:warn)
47 IO.should_not_receive(:copy_stream)
48 Capybara::Webkit::Connection.new(:stdout => nil)
49 end
9bb7b93 @mhoran Don't forward stderr to nil
mhoran authored
50
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
51 it "returns the server port" do
52 connection.port.should be_between 0x400, 0xffff
53 end
54
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
55 it 'sets appropriate options on its socket' do
215e244 @jferris Fix tests and remove 'kind_of?'
jferris authored
56 socket = stub('socket')
57 TCPSocket.stub(:open).and_return(socket)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
58 if defined?(Socket::TCP_NODELAY)
e80a9c8 @mhoran Pass fully qualified constants to #setsockopt
mhoran authored
59 socket.should_receive(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
60 else
215e244 @jferris Fix tests and remove 'kind_of?'
jferris authored
61 socket.should_not_receive(:setsockopt)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
62 end
63 Capybara::Webkit::Connection.new
64 end
65
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
66 it "chooses a new port number for a new connection" do
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
67 new_connection = Capybara::Webkit::Connection.new
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
68 new_connection.port.should_not == connection.port
69 end
70
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
71 let(:connection) { Capybara::Webkit::Connection.new }
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
72
73 before(:all) do
74 @app = lambda do |env|
75 body = "<html><body>Hey there</body></html>"
76 [200,
77 { 'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s },
78 [body]]
79 end
80 @rack_server = Capybara::Server.new(@app)
81 @rack_server.boot
82 end
83 end
Something went wrong with that request. Please try again.