Created
March 14, 2014 16:12
-
-
Save mikekellyio/9550882 to your computer and use it in GitHub Desktop.
Get open server port using Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_open_port | |
server = TCPServer.new('127.0.0.1', 0) | |
@port ||= server.addr[1] | |
end | |
Capybara.server_port = find_open_port | |
Capybara.app_host = "http://localhost:%d" % Capybara.server_port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment