title: Capybara tests fail with Timeout::Error in the first test when using Google Maps
body: <p>I am testing with RSpec + Capybara + Selenium (Firefox).  No matter what subset of my acceptance tests I run, the first one fails (next tests do work correctly) with "reason" like this:</p>
  
  <pre><code> Failure/Error: visit '/'
   Timeout::Error:
     Timeout::Error
  </code></pre>
  
  <p>My application relies on GoogleMaps and BackboneJS heavily.  When I run tests, page does not finish to load and "transferring data from maps.googleapis.com" message stays in bottom-left of Firefox window, however page looks like it loaded properly (maps and other content are present).  I've already set timeout to 60 secs to exclude any slow network problems.  And all the subsequent tests do work very fast (like proper Google scripts were fetched and are already cached).  Also when I start server in development environment and access it (<code>localhost:3000</code>) everything works fine.</p>
  
  <p>Firefox 17.0.1.  Some of my gems:</p>
  
  <pre><code>capybara (2.0.1)
  database_cleaner (0.9.1)
  mongoid (3.0.13)
  rspec (2.12.0)
  rspec-core (2.12.1)
  rspec-expectations (2.12.0)
  rspec-mocks (2.12.0)
  rspec-rails (2.12.0)
  selenium-webdriver (2.26.0)
  </code></pre>
  
  <p>Do you have any idea why this happens and how to prevent it?</p>
  
  <p>EDIT:</p>
  
  <p><code>spec/spec_helper.rb</code>:</p>
  
  <pre>
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  
  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
  RSpec.configure do |config|
    config.include FactoryGirl::Syntax::Methods
    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.infer_base_class_for_anonymous_controllers = false
    #config.order = "random"
  end
  </pre>
  
  <p><code>spec/features/features_spec_helper.rb</code>:</p>
  
  <pre>
  require_relative "../spec_helper"
  
  require 'capybara/rspec'
  
  Capybara.default_driver = :selenium
  Capybara.default_wait_time = 60
  </pre>
  
  <p>EDIT2:</p>
  
  <p>It used to work properly before (few weeks ago; this project was halted for that time).  <del>Could be introduced by RSpec upgrade from 2.11 to 2.12 (which I did those few weeks ago), but I've just tried to downgrade it and same things do happen.</del>  I've reverted whole codebase to the point month ago to exclude possible gem regression.  Problem still happens.</p>
  
  <p>EDIT3:</p>
  
  <p>I've just discovered that if I comment out the line responsible for attaching map from Google:</p>
  
  <pre><code>new google.maps.Map($("#map")[0], mapOptions)
  </code></pre>
  
  <p>then everything works like a charm.</p>
  
  <p>EDIT4:</p>
  
  <p>Source code of example application: <a href="https://github.com/skalee/capybara-google-maps-failure" rel="nofollow noreferrer">https://github.com/skalee/capybara-google-maps-failure</a></p>
  
  <p>Running all specs will result with Timeout::Error in the first one (at least for me).  However, all specs will pass when:</p>
  
  <ol>
  <li>You remove <a href="https://github.com/skalee/capybara-google-maps-failure/blob/master/app/assets/javascripts/rmcs.js.coffee#L7" rel="nofollow noreferrer">line which initializes Geocoder</a> (it's not used in example app, but I use it in mine).</li>
  <li>You remove <a href="https://github.com/skalee/capybara-google-maps-failure/blob/master/app/assets/javascripts/views/offers_on_map.js.coffee#L13" rel="nofollow noreferrer">line which initializes Map</a>.</li>
  <li>What surprised me most, when you provide trivial style sheet, like nothing more than that:</li>
  </ol>
  
  <pre>#map{ width: 600px ; height: 600px }</pre>
  
  <p>Gems are exactly the same gems as I use in my app.  There are some 3rd party scripts in <code>/vendor/assets</code>.</p>