Capybara not waiting on expect
<p>I have a page with a link that opens a bootstrap modal with a simple input field. I'm having a hard time understanding why Capybara doesn't wait for the modal to open, and fails immediately.</p>

<p>I added <code>expect(page).to have_content('Did you')</code> so capybara will wait a few seconds until the modal is shown.
But for some reason it's not waiting and raises <code>Capybara::ExpectationNotMet: expected to find text "Did you" in ...."</code></p>

<p>If I put a sleep of 1 second it will then find the modal, but it's not good enough because then a DB clean callback found in my <strong>spec_helper.rb</strong> is called:</p>

<pre><code>config.after(:each) do
  DatabaseCleaner.clean
end
</code></pre>

<p>This is the spec:</p>

<pre><code>RSpec.describe "follower button", type: :request do
  it "sends email #15B to owner", :js do
    using_wait_time 20 do
      FactoryGirl.create(:apartment_with_event)

      visit apartment_path(Apartment.last)
      click_on 'follow-events'
      expect(page).to have_content('Did you')
      within('#follow-events-modal') do
        fill_in 'follower-email-signup-mail', with: 'follower@example.com'
        click_button 'follower-signup-submit'
      end

      expect(page).to have_content(I18n.t("followers.create.title_success"))
      expect(Follower.all.count).to eq(1)
    end
  end
end
</code></pre>

<p>I also set <code>Capybara.default_max_wait_time = 10</code> in <strong>spec_helper.rb</strong>, even though it should wait for 20 seconds for this example.</p>

<p>Forgot to mention, I'm using <strong>Capybara-wekbit</strong> as the driver.</p>

<p>I really spent hours trying to discover why it's happening, while other examples run just fine.</p>

<p><strong>UPDATE:</strong>
Adding full backtrace of failure.</p>

<pre><code>Failures:

  1) leeron's button sends email #15B to owner
     Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"

     ActionController::RoutingError:
       No route matches [GET] "/images/slider/missing.png"
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rollbar-1.2.13/lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/railties-4.2.4/lib/rails/rack/logger.rb:38:in `call_app'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `block in call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/railties-4.2.4/lib/rails/rack/logger.rb:20:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/request_store-1.2.0/lib/request_store/middleware.rb:8:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/railties-4.2.4/lib/rails/engine.rb:518:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/railties-4.2.4/lib/rails/application.rb:165:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/urlmap.rb:66:in `block in call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `each'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/urlmap.rb:50:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/capybara-2.7.1/lib/capybara/server.rb:43:in `call'
     # /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
     # ------------------
     # --- Caused by: ---
     # Capybara::ExpectationNotMet:
     #   expected to find text "Did you" in "...(REMOVED BY ME TO SAVE SPACE)..."
     #   /Users/etaiso/.rbenv/versions/2.2.3/gemsets/dorbel/gems/capybara-2.7.1/lib/capybara/node/matchers.rb:527:in `block in assert_text'

Finished in 3.87 seconds (files took 9.79 seconds to load)
1 example, 1 failure
</code></pre>