ruby on rails - Capybara does not wait for factory_girl to finish -


given following simple spec:

require 'spec_helper'  feature 'feeds', %q{   in order see latest content of buurtlink   user   should able view neighborhood or postal_code }    background     @neighborhood = factorygirl.create(:neighborhood_with_posts)   end    scenario 'visitor views neighborhood'     visit neighborhood_path(@neighborhood)      find('#header_title').should have_content 'diemen-zuid'      10.times |index|       expect(page).to have_text "title of new post #{index}"     end   end  end 

this test randomly fails. no js used on page, capybara seems visit neighborhood_path before factorygirl done creating necessary posts. when looking @ page using save_and_open_page can see not posts have been created yet.

simply adding sleep 1 above visit neighborhood_path fixes problem, that's not solution.

i'm using rspec, capybara, spork , databasecleaner. monkey-patched activerecord uses shared connection.

try instead of background block:

let!(:neighborhood){factorygirl.create(:neighborhood_with_posts)} 

and can do

 visit neighborhood_path(neighborhood) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -