From 2dca77060ab33fe35ce3996f9721657a8d604ca3 Mon Sep 17 00:00:00 2001 From: David Balatero Date: Wed, 5 Oct 2011 12:09:37 -0700 Subject: [PATCH] This adds a server_host option to Capybara. In order to run Selenium via Capybara on my virtual machine, you need to be able to bind the server IP to a net interface on the same subnet as the VM. This patch exposes an configuration variable to allow you to bind the test server to any net interface on your local machine. Falls back to 127.0.0.1 if the config var is not set. --- lib/capybara.rb | 2 +- lib/capybara/server.rb | 2 +- spec/server_spec.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/capybara.rb b/lib/capybara.rb index eb70581a..df0d7b17 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -16,7 +16,7 @@ module Capybara class << self attr_accessor :asset_root, :app_host, :run_server, :default_host - attr_accessor :server_port, :server_boot_timeout + attr_accessor :server_host, :server_port, :server_boot_timeout attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements, :prefer_visible_elements attr_accessor :save_and_open_page_path, :automatic_reload diff --git a/lib/capybara/server.rb b/lib/capybara/server.rb index 38707072..09e593db 100644 --- a/lib/capybara/server.rb +++ b/lib/capybara/server.rb @@ -32,7 +32,7 @@ module Capybara end def host - "127.0.0.1" + Capybara.server_host || "127.0.0.1" end def url(path) diff --git a/spec/server_spec.rb b/spec/server_spec.rb index edfb73e5..bc2aec7a 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -17,6 +17,16 @@ describe Capybara::Server do end.should_not raise_error end + it "should bind to the specified host" do + Capybara.server_host = '0.0.0.0' + + app = proc { |env| [200, {}, "Hello Server!"]} + server = Capybara::Server.new(app).boot + server.host.should == '0.0.0.0' + + Capybara.server_host = nil + end + it "should use specified port" do Capybara.server_port = 22789