次の単純な仕様を考えると:
require 'spec_helper'
feature 'Feeds', %q{
In order see the latest content of Buurtlink
As a user
I should be able to view a neighborhood or postal_code
} do
background do
@neighborhood = FactoryGirl.create(:neighborhood_with_posts)
end
scenario 'Visitor views a neighborhood' do
visit neighborhood_path(@neighborhood)
find('#header_title').should have_content 'Diemen-Zuid'
10.times do |index|
expect(page).to have_text "Title of new post #{index}"
end
end
end
このテストはランダムに失敗します。このページでは JS は使用されていませんが、FactoryGirl が必要なすべての投稿の作成を完了する前に、Capybara が neighbor_path にアクセスしているようです。save_and_open_page を使用してページを見ると、すべての投稿がまだ作成されていないことがあります。
単純に、visit neighbor_path の上に sleep 1 を追加するだけで問題は解決しますが、それは解決策ではありません。
RSpec、Capybara、Spork、および DatabaseCleaner を使用しています。また、共有接続を使用するように、ActiveRecord にモンキー パッチを適用しました。