Add custom host IP address support - Issue #716 #879
Conversation
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.
|
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'. |
There was a problem hiding this comment.
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) -> |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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}/" |
There was a problem hiding this comment.
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?
spec/integration/driver_spec.rb
Outdated
# 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'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitalization
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
c9ac701
to
2acbc7c
Compare
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
2acbc7c
to
7fd258e
Compare
I've incorporated the suggestions to the branch |
@arturocastro Thanks, once you fix the tests this breaks then it should be good to go. |
7fd258e
to
97be0eb
Compare
Fixed the tests! |
Thanks! |
Travis CI test uses a custom host, in local environments it can be tested with the POLTERGEIST_TEST_HOST env var.