Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 66 lines (58 sloc) 1.954 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
6 url = @rack_server.url("/")
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
21 it 'forwards stdout to the given IO object' do
22 io = StringIO.new
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
23 redirected_connection = Capybara::Webkit::Connection.new(:stdout => io)
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
24 script = 'console.log("hello world")'
25 redirected_connection.puts "Execute"
26 redirected_connection.puts 1
27 redirected_connection.puts script.to_s.bytesize
28 redirected_connection.print script
29 sleep(0.5)
30 io.string.should include "hello world\n"
31 end
32
33 it "returns the server port" do
34 connection.port.should be_between 0x400, 0xffff
35 end
36
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
37 it 'sets appropriate options on its socket' do
215e244 @jferris Fix tests and remove 'kind_of?'
jferris authored
38 socket = stub('socket')
39 TCPSocket.stub(:open).and_return(socket)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
40 if defined?(Socket::TCP_NODELAY)
215e244 @jferris Fix tests and remove 'kind_of?'
jferris authored
41 socket.should_receive(:setsockopt).with(:IPPROTO_TCP, :TCP_NODELAY, 1)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
42 else
215e244 @jferris Fix tests and remove 'kind_of?'
jferris authored
43 socket.should_not_receive(:setsockopt)
943db04 @benizi Set TCP_NODELAY option on the TCPSocket
benizi authored
44 end
45 Capybara::Webkit::Connection.new
46 end
47
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
48 it "chooses a new port number for a new connection" do
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
49 new_connection = Capybara::Webkit::Connection.new
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
50 new_connection.port.should_not == connection.port
51 end
52
259a38f @jferris Follow new capybara driver naming/module conventions
jferris authored
53 let(:connection) { Capybara::Webkit::Connection.new }
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
54
55 before(:all) do
56 @app = lambda do |env|
57 body = "<html><body>Hey there</body></html>"
58 [200,
59 { 'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s },
60 [body]]
61 end
62 @rack_server = Capybara::Server.new(@app)
63 @rack_server.boot
64 end
65 end
Something went wrong with that request. Please try again.