title: Error occurring in arbitrary frequency during Capybara tests
body: <p>In an App I write I create, update and delete Objects of a 'places' class. Depending on whether a user is logged in or not the place needs to be reviewed first before it becomes visible to the public inside an index view.</p>
  
  <p>We use Minitest and Capybara as our testing framework from the beginning on we had trouble with some of our Capybara specs...</p>
  
  <p>a) ... passing and not passing on different machines (especially on our local systems and Travis CI)</p>
  
  <p>b) ... passing and not passing seemingly arbitrary throughout different runs on our local machines</p>
  
  <p>I have to admit it's a bit of a miracle for me and even harder to track down the sources of errors. The following specs show this behaviour:</p>
  
  <pre><code>require_relative '../../test_helper'
  
  feature 'Review place' do
    before do
      create(:place, :reviewed)
    end
  
    scenario 'Do not show user edits in review index', :js do
      login
      visit '/places/1/edit'
      fill_in('place_name', with: 'USER CHANGE')
      click_on('Update Place')
      visit '/places/review_index'
      page.wont_have_content('USER CHANGE')
    end
  
    scenario 'Show guest edits in review index and review place', :js do
      visit '/places/1/edit'
      fill_in('place_name', with: 'GUEST CHANGE')
      validate_captcha
      click_on('Update Place')
      login
      visit '/places/review_index'
      page.must_have_content('SomeReviewedPlace')
      visit '/1/review_place'
      sleep(1)
      page.must_have_content('SomeReviewedPlace')
      page.must_have_content('GUEST CHANGE')
    end
  end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>require_relative '../../test_helper'
  
  feature 'Edit place' do
    before do
      create(:place, :reviewed)
    end
  
    scenario 'Do valid place update as user and show in index afterwards', :js do
      login
      visit '/places/1/edit'
  
      fill_in('place_name', with: 'Any place')
      fill_in('place_street', with: 'Schulze-Boysen-Str.')
      fill_in('place_house_number', with: '80')
      fill_in('place_postal_code', with: '10963')
      fill_in('place_city', with: 'Berlin')
      fill_in('place_email', with: 'schnipp@schnapp.com')
      fill_in('place_homepage', with: 'http://schnapp.com')
      fill_in('place_phone', with: '03081763253')
      click_on('Update Place')
      visit '/places'
  
      page.must_have_content('Any place')
      page.must_have_content('10963 Berlin')
    end
  
    scenario 'Do valid place update as guest and show in index afterwards as to be reviewed', :js do
      visit '/places/1/edit'
      fill_in('place_name', with: 'Some changes')
      validate_captcha
      click_on('Update Place')
      visit '/places'
  
      page.must_have_content('Some changes')
      page.must_have_css('.glyphicon-eye-open')
    end
  
    scenario 'Do valid place update as guest and do not show changes within other users session', :js do
      visit '/places/1/edit'
      fill_in('place_name', with: 'SomeOtherName')
      validate_captcha
      click_on('Update Place')
  
      Capybara.reset_sessions!
      visit '/places'
      page.wont_have_content('SomeOtherName')
      page.must_have_content('SomeReviewedPlace')
      page.wont_have_css('.glyphicon-eye-open')
    end
  end
  </code></pre>
  
  <p>Both tests arbitrarily fail with </p>
  
  <blockquote>
    <p>ActiveRecord::RecordNotFound: Couldn't find Place with 'id'=1</p>
  </blockquote>
  
  <p>although such a place has to exist due to</p>
  
  <pre><code>before do
    create(:place, :reviewed)
  end
  </code></pre>
  
  <p>Running the test files individually the error does not appear, only SOMETIMES within the complete chain that's passed within <code>rake test</code>. Does anyone have a clue why?</p>
  
  <p>best and thanks,
  Andi</p>