title: Capybara Poltergeist getting forced over https when using path helpers
body: <p>Poltergeist is unable to connect to the server. Here's the error I'm getting:</p>
  
  <pre><code> Failure/Error: visit root_path
  
   Capybara::Poltergeist::StatusFailError:
     Request to 'http://127.0.0.1:58638/' failed to reach server, check DNS and/or server status
  </code></pre>
  
  <p>I've got the phantomjs debug output on, and here's what looks like the relevant lines to me:</p>
  
  <pre><code>2016-12-14T14:24:47 [DEBUG] WebpageCallbacks - getJsConfirmCallback
  {"command_id":"5eab3091-26bd-47b7-b779-95ec9523fb5b","response":true}
  {"id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","name":"visit","args":["http://127.0.0.1:58638/"]}
  2016-12-14T14:24:47 [DEBUG] WebPage - updateLoadingProgress: 10
  2016-12-14T14:24:48 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"
  2016-12-14T14:24:48 [DEBUG] WebPage - updateLoadingProgress: 100
  2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
  2016-12-14T14:24:48 [DEBUG] WebPage - setupFrame ""
  2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n      return typeof __poltergeist;\n    })(); })()"
  2016-12-14T14:24:48 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "undefined")
  {"command_id":"1069af41-1b7c-4f5b-a9c7-258185aa8c73","error":{"name":"Poltergeist.StatusFailError","args":["http://127.0.0.1:58638/",null]}}
  {"id":"cbe42cdc-58db-49c5-a230-4a1f4634d830","name":"reset","args":[]}
  </code></pre>
  
  <p>This bit seemed like a clue <code>Network - Resource request error: QNetworkReply::NetworkError(ConnectionRefusedError) ( "Connection refused" ) URL: "https://127.0.0.1/"</code> and that it could be an ssl error, so I added the phantomjs option <code>--ignore-ssl-errors=true</code>, but it makes no difference to the response.</p>
  
  <p>I switched over to <code>capybara-webkit</code> to see if that would provide a bit more info as some people have recommended. I get a very similar error:</p>
  
  <pre><code>"Visit(http://127.0.0.1:64341/)" started page load
  Started request to "http://127.0.0.1:64341/"
  Finished "Visit(http://127.0.0.1:64341/)" with response "Success()"
  Started request to "https://127.0.0.1/"
  Received 301 from "http://127.0.0.1:64341/"
  Received 0 from "https://127.0.0.1/"
  Page finished with false
  Load finished
  Page load from command finished
  Wrote response false "{"class":"InvalidResponseError","message":"Unable to load URL: http://127.0.0.1:64341/ because of error loading https://127.0.0.1/: Unknown error"}"
  Received "Reset()"
  Started "Reset()"
  undefined|0|SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
  </code></pre>
  
  <p>With the help of @thomas-walpole I realised that if I specific a non-https url to visit in capybara, it works. E.g <code>visit "http://localhost:3000"</code> it works. Using <code>visit root_url</code> works, but using <code>visit root_path</code> I get directed to https and the error above.</p>
  
  <p><code>config.force_ssl</code> is not true. I've set <code>config.force_ssl = false</code> in <code>config/environments/test.rb</code> and also used pry to check the <code>Application.config</code> in the context of the test.</p>
  
  <p>Any ideas for why the path helpers are getting sent over https would be greatly appreciated.</p>