Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 55 lines (48 sloc) 1.651 kb
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
1 require 'spec_helper'
2 require 'capybara/driver/webkit/connection'
3
4 describe Capybara::Driver::Webkit::Connection do
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
23 redirected_connection = Capybara::Driver::Webkit::Connection.new(:stdout => io)
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
37 it "chooses a new port number for a new connection" do
38 new_connection = Capybara::Driver::Webkit::Connection.new
39 new_connection.port.should_not == connection.port
40 end
41
42 let(:connection) { Capybara::Driver::Webkit::Connection.new }
43
44 before(:all) do
45 @app = lambda do |env|
46 body = "<html><body>Hey there</body></html>"
47 [200,
48 { 'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s },
49 [body]]
50 end
51 @rack_server = Capybara::Server.new(@app)
52 @rack_server.boot
53 end
54 end
Something went wrong with that request. Please try again.