title: Testing ajax searching with rspec
body: <p>I have strange problem. I have feature test that looks like this:
  require "rails_helper"</p>
  
  <pre><code>feature "Doctors" do
    let(:ordering_unit) { build(:ordering_unit, name: "Test ordering unit") }
    let!(:doctor)  { create(:doctor, fullname: "Doctor", specialization: "Specialization", ordering_unit: ordering_unit)}
    let!(:doctor2) { create(:doctor, fullname: "Test doctort", specialization: "Test specialization") }
    before { visit doctors_path }
  
  feature "Searching" do
  
    scenario "Should find proper doctors", js: true do
      fill_in "search_form_query", with: "Test"
      expect(page).to have_text(doctor2.fullname)
      expect(page).to_not have_text(doctor1.fullname)
      save_and_open_page
    end
  end
  </code></pre>
  
  <p>This test is responsible for testing ajax search on index page. But the problem is that when I run the this test my firefox windows is opening and it not show any doctors on index page. But when I remove "js: true" option and check page using "save_and_open_page" two doctors are on index page. What can be wrong?
  My rails_helper.rb</p>
  
  <pre><code>ENV["RAILS_ENV"] ||= 'test'
  require 'spec_helper'
  require File.expand_path("../../config/environment", __FILE__)
  require 'capybara'
  require 'rspec/rails'
  require 'capybara/rspec'
  ActiveRecord::Migration.maintain_test_schema!
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
  RSpec.configure do |config|
  
    config.include FactoryGirl::Syntax::Methods
    config.include Capybara::DSL
  
    config.before(:suite) do
        DatabaseCleaner.strategy = :transaction
        DatabaseCleaner.clean_with(:truncation)
      end
  
      config.before(:each) do
        DatabaseCleaner.start
      end
  
      config.after(:each) do
        DatabaseCleaner.clean
      end
    config.infer_spec_type_from_file_location!
  end
  </code></pre>