I have this spec:
it 'syncs active campaign contact on user update' do
expect(Marketing::ActiveCampaign::SyncContact).to receive(:run)
login(@user, then_visit: "/account/#{@user.id}/settings")
fill_in('customer[cc_email_address]', with: 'mean@google.com')
find('.user-submit').click
# this does a submit to the server which will result in
# SyncContact.run being called
# a spinner is put up while waiting for the post to
# complete
end
how can I have the spec wait the minimum amount of time so that the expect to receive mock has a chance to receive the message?
I can obviously put in a dead wait after the find, which I hate to do.
I can also do something like this at the end of the spec
expect(page).to have_css('.loading-image-div')
expect(page).to have_no_css('.loading-image-div')
but I don't like this either as the first check may fail if the response from the server is very fast.
What I want is to just have the spec keep waiting (up to max wait time) for the message to be receive, and then only then fail.