Permalink
Browse files

Add some basic testing for the browser to make sure the random port c…

…ode is working
  • Loading branch information...
1 parent 9f75414 commit 3d39b590716ecb6e031d63a33b447c86a64dba67 @j16r j16r committed Jul 6, 2011
Showing with 30 additions and 1 deletion.
  1. +3 −1 lib/capybara/driver/webkit/browser.rb
  2. +27 −0 spec/browser_spec.rb
@@ -4,6 +4,8 @@
class Capybara::Driver::Webkit
class Browser
+ attr :server_port
+
def initialize(options = {})
@socket_class = options[:socket_class] || TCPSocket
start_server
@@ -84,7 +86,7 @@ def fork_server
def discover_server_port(read_pipe)
return unless IO.select([read_pipe], nil, nil, 10)
- ((read_pipe.first || '').match(/listening on port: (\d+)/) || [])[1]
+ ((read_pipe.first || '').match(/listening on port: (\d+)/) || [])[1].to_i
end
def connect
View
@@ -0,0 +1,27 @@
+require 'spec/spec_helper'
+require 'capybara/driver/webkit/browser'
+
+describe Capybara::Driver::Webkit::Browser do
+
+ let(:browser) { Capybara::Driver::Webkit::Browser.new }
+
+ describe '#server_port' do
+ subject { browser.server_port }
+ it 'returns a valid port number' do
+ should be_a(Integer)
+ end
+
+ it 'returns a port in the allowed range' do
+ should > 0x400
+ should < 0xffff
+ end
+ end
+
+ context 'random port' do
+ it 'chooses a new port number for a new browser instance' do
+ new_browser = Capybara::Driver::Webkit::Browser.new
+ new_browser.server_port.should_not == browser.server_port
+ end
+ end
+
+end

0 comments on commit 3d39b59

Please sign in to comment.