Permalink
Browse files

Merge the IO.popen patch, too.

  • Loading branch information...
2 parents 922d197 + d8abcbc commit c36209844db332707ef91c886a5b9d5c9ba85bbc @mike-burns mike-burns committed Aug 19, 2011
Showing with 19 additions and 19 deletions.
  1. +19 −19 lib/capybara/driver/webkit/browser.rb
@@ -81,42 +81,42 @@ def render(path, width, height)
private
def start_server
- read_pipe, write_pipe = fork_server
- @server_port = discover_server_port(read_pipe)
+ pipe = fork_server
+ @server_port = discover_server_port(pipe)
@stdout_thread = Thread.new do
Thread.current.abort_on_exception = true
- forward_stdout(read_pipe)
+ forward_stdout(pipe)
end
end
def fork_server
server_path = File.expand_path("../../../../../bin/webkit_server", __FILE__)
- read_pipe, write_pipe = IO.pipe
+ pipe, @pid = server_pipe_and_pid(server_path)
+
+ at_exit { Process.kill("INT", @pid) }
+
+ pipe
+ end
+
+ def server_pipe_and_pid(server_path)
+ pipe = IO.popen(server_path)
if Process.respond_to?(:spawn)
- @pid = Process.spawn(server_path,
- :in => :in,
- :out => write_pipe,
- :err => :err,
- :close_others => true)
+ [pipe, Process.spawn(server_path,
+ :in => :in,
+ :out => pipe,
+ :err => :err,
+ :close_others => true)]
else
- @pid = fork do
- $stdout.reopen write_pipe
- read_pipe.close
- exec(server_path)
- end
+ [pipe, pipe.pid]
end
- at_exit { Process.kill("INT", @pid) }
-
- write_pipe.close
- [read_pipe, write_pipe]
end
def discover_server_port(read_pipe)
return unless IO.select([read_pipe], nil, nil, 10)
((read_pipe.first || '').match(/listening on port: (\d+)/) || [])[1].to_i
end
-
+
def forward_stdout(pipe)
while !pipe.eof?
line = pipe.readline

0 comments on commit c362098

Please sign in to comment.