title: Capybara Webkit doesn't seem to submit the form quickly enough
body: <p>I'm using Capybara to test a basic form - when the user fills it out and submits it should create a new <code>User</code> record</p>
  
  <pre><code>it "creates a new user" do
    visit some_random_path
  
    # Fill In Form
    fill_in("name", with: "foo bar")
    fill_in("email", with: "foo.bar@example.com")
  
    expect do
      click_button("Submit")
    end.to change { User.count }.by(1)
  end
  </code></pre>
  
  <p>The <code>expect</code> blocks throws an error because it doesn't see the <code>User.count</code> increase by 1. However I noticed that if I do something like </p>
  
  <pre><code>click_button("Submit") &amp;&amp; sleep(0.1)
  </code></pre>
  
  <p>it works just fine!</p>
  
  <p>So it looks like RSpec is trying to check <em>too</em> quickly - i.e. before the browser that Capybara runs has a chance to actually submit the form and commit the results against the DB. </p>
  
  <p>I'm not using any JavaScript, just a plain old <code>:webkit</code> spec. </p>
  
  <p>Any thoughts on why this might be happening?</p>
  
  <p>Below is my Capybara configuration. I have a multi-tenant app (I'm using the <a href="https://github.com/influitive/apartment/" rel="nofollow noreferrer">apartment gem</a> for whatever it matters) so I use <code>localhost</code> and <code>lvh.me</code> as the app hosts as noted below, but I can't imagine that would interfere with the above.</p>
  
  <pre><code>Capybara.configure do |config|
    config.ignore_hidden_elements = true
    Capybara.default_driver = :webkit
    config.javascript_driver = :webkit
  end
  
  Capybara::Webkit.configure do |config|
    config.block_unknown_urls
    config.allow_url("lvh.me")
  end
  
  RSpec.configure do |config|
    config.before(:suite) do
      Capybara.always_include_port = true
      # The default is to treat each spec as single tennat, in which case
      # we want to hit localhost. Hitting the Capbyara default of www.example.com
      # causes the apartment setup to try and parse the `www` as a subdomain
      Capybara.app_host = "http://localhost"
    end
  
    config.before(:each, multi_tenant: true) do
      # For multi-tenant specs, use "lvh.me"
      Capybara.app_host = "http://lvh.me"
    end
  end
  </code></pre>
  
  <p>Thanks!</p>