Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Add custom host IP address support - Issue #716 #879

Merged
merged 1 commit into from Apr 17, 2017

Conversation

arturocastro
Copy link
Contributor

Travis CI test uses a custom host, in local environments it can be tested with the POLTERGEIST_TEST_HOST env var.

@arturocastro
Copy link
Contributor Author

It's my understanding those two failed tests happen as result of PhantomJS version? They seem to occur even before applying my changes from a stable version.

Failures:
  1) Capybara::Poltergeist::Client forcibly kills the child if it does not respond to SIGTERM
     Failure/Error: parts << server.host
       #<Double (anonymous)> received unexpected message :host with (no args)
       Debug info:
     # ./lib/capybara/poltergeist/client.rb:95:in `command'
     # ./lib/capybara/poltergeist/client.rb:70:in `block in start'
     # ./lib/capybara/poltergeist/client.rb:108:in `redirect_stdout'
     # ./lib/capybara/poltergeist/client.rb:69:in `start'
     # ./spec/unit/client_spec.rb:57:in `block (2 levels) in <module:Poltergeist>'
  2) Capybara::Poltergeist::Driver with a :timeout option starts the server with the provided timeout
     Failure/Error: @server ||= Server.new(options[:port], options.fetch(:timeout) { DEFAULT_TIMEOUT }, options[:host])
       #<Capybara::Poltergeist::Server (class)> received :new with unexpected arguments
         expected: (anything, 3)
              got: (nil, 3, nil)
       Debug info:
     # ./lib/capybara/poltergeist/driver.rb:40:in `server'
     # ./spec/unit/driver_spec.rb:116:in `block (3 levels) in <module:Poltergeist>'

README.md Outdated
@@ -281,6 +281,7 @@ end
* `:extensions` (Array) - An array of JS files to be preloaded into
the phantomjs browser. Useful for faking unsupported APIs.
* `:port` (Fixnum) - The port which should be used to communicate
* `:host` (String) - The name or IP of the PhantomJS host. Default is '127.0.0.1'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to move down a line since it split the comment from the :port line

@@ -1,5 +1,8 @@
class Poltergeist.Connection
constructor: (@owner, @port) ->
constructor: (@owner, @port, @host) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add a default value for @host in the function definition

constructor: (@owner, @port) ->
constructor: (@owner, @port, @host) ->
#@socket = new WebSocket "ws://#{@host}:#{@port}/"
if !@host?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed if default value added in function definition

constructor: (@owner, @port, @host) ->
#@socket = new WebSocket "ws://#{@host}:#{@port}/"
if !@host?
@host = "127.0.0.1"
@socket = new WebSocket "ws://127.0.0.1:#{@port}/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this needs to be updated to use the @host value?

# Use /etc/hosts or iptables for this: https://superuser.com/questions/516208/how-to-change-ip-address-to-point-to-localhost
# A custom host and corresponding env var for Travis is specified in .travis.yml
# If var is unspecified, use localhost
env_var = ENV['POLTERGEISt_TEST_HOST']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization

@twalpole
Copy link
Contributor

twalpole commented Apr 2, 2017

The test failures have nothing to do with PhantomJS version, and everything to do with the changes to the Server API and the doubles not being updated to match.

@@ -860,6 +860,23 @@ def create_screenshot(file, *args)
end
end

it 'allows the driver to have a custom host' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip this test if ENV['POLTERGEIST_TEST_HOST'] isn't set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the RSpec provided skip to skip the test so a notice gets printed that a test was skipped

@arturocastro
Copy link
Contributor Author

My bad, I messed my git history. Here it goes again.

time = Time.now

begin
TCPServer.open(HOST, port || 0).tap do |server|
custom_host = custom_host.nil? ? custom_host : HOST
Copy link
Contributor

@twalpole twalpole Apr 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic looks wrong, since it will only assign custom_host if it's nil, looks like you could just do TCPServer.open(custom_host || HOST, port || 0)

CHANGELOG.md Outdated
@@ -1,3 +1,6 @@
### 1.15.0 ###
* Driver now supports specifying a custom IP address (host) with the :host option (Arturo Castro)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the Features section like all other version numbers have

@arturocastro
Copy link
Contributor Author

I've incorporated the suggestions to the branch

@twalpole
Copy link
Contributor

@arturocastro Thanks, once you fix the tests this breaks then it should be good to go.

@arturocastro
Copy link
Contributor Author

Fixed the tests!

@twalpole
Copy link
Contributor

Thanks!

@twalpole twalpole merged commit e0513a7 into teampoltergeist:master Apr 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants