title: How to run Capybara/Poltergeist on localhost in production mode?
body: <p>Trying to get some headless UI smoke testing going on Jenkins builds.  Looks like <a href="https://github.com/teampoltergeist/poltergeist" rel="nofollow noreferrer">Poltergeist</a> will be the way to go, but I'm having trouble getting the driver to pick up any content.</p>
  
  <p>Current strategy is to compile all of the assets as if a production deployment is going to occur.</p>
  
  <p><strong>Step One: Make a "localhost production deployment"</strong></p>
  
  <pre><code>bundle install --deployment --retry=3
  npm install
  cd client # where all React.js code lives
  node_modules/.bin/webpack -b --config webpack.production.config
  cd ..
  bundle exec rake assets:precompile RAILS_ENV=production
  mkdir -p public/images;
  cp -R app/assets/images/* public/images/
  </code></pre>
  
  <p><strong>Step Two: Run localhost:3000 in production mode</strong></p>
  
  <pre><code>RAILS_ENV=production bundle exec rails s
  =&gt; Rails 4.2.6 application starting in production on http://localhost:3000
  </code></pre>
  
  <p><strong>Step Three: Run smoke tests that point towards localhost:3000</strong></p>
  
  <pre><code>bundle exec rspec spec/features
  </code></pre>
  
  <p>Here my extremely trivial test example for capybara/poltergeist:</p>
  
  <pre><code>require "rails_helper"
  
  Capybara.javascript_driver = :poltergeist
  Capybara.run_server = false
  Capybara.app_host = "http://localhost:3000"
  
  RSpec.describe "FooBar copyright", js: true do
    context "when on the homepage" do
      it "displays 'All rights reserved'" do
        Rails.env = "production"
        page.visit "/"
        expect(page).to have_content "All rights reserved"
      end
    end
  end
  </code></pre>
  
  <hr>
  
  <p>You would think this would work... It doesn't though.  The tests are failing because they are not picking up any content.  I have done some debugging, and the Rails.env is correct and the <code>current_url</code> is also properly set to <code>localhost:3000</code>.</p>
  
  <p>Manually going to <code>localhost:3000</code> in the browser works fine as well.  The assets are compiling correctly.</p>
  
  <p>For some reason capybara/poltergeist is simply not picking up the content.  Get this error:</p>
  
  <pre><code> Failure/Error: expect(page).to have_content "All rights reserved"
     expected to find text "All rights reserved" in ""
  </code></pre>
  
  <p>Appreciate any help!</p>