Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 66 lines (58 sloc) 2.07 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
b538721 @jferris wip
jferris authored
5 it "starts a Webkit session" 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
b538721 @jferris wip
jferris authored
11 puts 'about to gets'
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
12 connection.gets.should == "ok\n"
b538721 @jferris wip
jferris authored
13 puts 'first gets is a go'
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
14 connection.gets.should == "0\n"
15 connection.puts "Body"
16 connection.puts 0
17 connection.gets.should == "ok\n"
18 response_length = connection.gets.to_i
19 response = connection.read(response_length)
20 response.should include("Hey there")
21 end
22
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
23 it 'forwards stderr to the given IO object' do
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
24 io = StringIO.new
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
25 redirected_connection = Capybara::Webkit::Connection.new(:stderr => io)
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
26 script = 'console.log("hello world")'
2ceab4e @mhoran Forward stderr via Open3#popen3
mhoran authored
27 redirected_connection.puts "EnableLogging"
28 redirected_connection.puts 0
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
29 redirected_connection.puts "Execute"
30 redirected_connection.puts 1
31 redirected_connection.puts script.to_s.bytesize
32 redirected_connection.print script
33 sleep(0.5)
ea06a1b @mhoran Forward stderr from server to stderr, drop stdout
mhoran authored
34 io.string.should =~ /hello world $/
665e0fc @jferris Extract a Connection class for booting the server
jferris authored
35 end
36
9bb7b93 @mhoran Don't forward stderr to nil
mhoran authored
37 it 'does not forward stderr to nil' do
38 IO.should_not_receive(:copy_stream)
39 Capybara::Webkit::Connection.new(:stderr => nil)
40 end
41
a70b7c4 @mhoran Deprecate the stdout option for Connection
mhoran authored
42 it 'prints a deprecation warning if the stdout option is used' do
43 Capybara::Webkit::Connection.any_instance.should_receive(:warn)
44 Capybara::Webkit::Connection.new(:stdout => nil)
45 end
46
47 it 'does not forward stdout to nil if the stdout option is used' do
48 Capybara::Webkit::Connection.any_instance.stub(:warn)
49 IO.should_not_receive(:copy_stream)
50 Capybara::Webkit::Connection.new(:stdout => nil)
51 end
9bb7b93 @mhoran Don't forward stderr to nil
mhoran authored
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.