title: How do I configure Capybara to work with Poltergeist?
body: <p>I have an RSpec integration test that needs to execute some JavaScript. I've included Poltergeist and installed PhantomJS, but whenever I run the example, I get this error:</p>
  
  <pre><code>Failure/Error: page.execute_script("$('form')[0].submit();")
  Capybara::NotSupportedByDriverError:
    Capybara::Driver::Base#execute_script
  </code></pre>
  
  <p>The spec is:</p>
  
  <pre><code>require 'spec_helper'
  
  describe "Signup", :type =&gt; :feature do
    describe "workflow" do
      it "ensures entry of contact information" do
        visit 'signup/action'
        # snip - use Capybara to fill out form elements
        page.execute_script("$('form')[0].submit();")
        page.should have_content("Name can't be blank")
        page.should have_content("Email can't be blank")
  
        # snip - use Capybara to fill out more form elements
        page.execute_script("$('form')[0].submit();")
        page.should have_content("Next page")
      end
    end
  end
  </code></pre>
  
  <hr>
  
  <p>I think the problem is that I'm not sure how to indicate that Capybara should use Poltergeist as its JavaScript driver. The <a href="https://github.com/teampoltergeist/poltergeist#installation" rel="noreferrer">Poltergeist documentation</a> says:</p>
  
  <blockquote>
    <h1>Installation</h1>
    
    <p>Add poltergeist to your Gemfile, and in your test setup add:</p>
  </blockquote>
  
  <pre><code>require 'capybara/poltergeist'
  Capybara.javascript_driver = :poltergeist
  </code></pre>
  
  <p>But it doesn't say which file specifically it should go into. It <a href="https://github.com/teampoltergeist/poltergeist#customization" rel="noreferrer">also says</a>:</p>
  
  <blockquote>
    <h1>Customization</h1>
    
    <p>You can customize the way that Capybara sets up Poltegeist via the following code in your test setup:</p>
  </blockquote>
  
  <pre><code>Capybara.register_driver :poltergeist do |app|
    Capybara::Poltergeist::Driver.new(app, options)
  end
  </code></pre>
  
  <p>But it's not clear to me if or when I would need to include this in my tests. And again, I'm not sure where to put it if I need to.</p>
  
  <hr>
  
  <p><strong>What am I missing?</strong></p>
  
  <ul>
  <li>Where do I need to put the configuration for Capybara and Poltergiest, and what exactly does it need to say (or how can I determine that for myself)?</li>
  <li>Is there a step or piece of configuration that I missed?</li>
  </ul>