Avoid race conditions in feature specs

This commit is contained in:
Maikel Linke
2016-06-01 16:15:44 +10:00
parent 4bde890eaa
commit 89c3758bae
2 changed files with 13 additions and 3 deletions

View File

@@ -254,6 +254,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
variant.update_attributes! on_hand: 0
# -- Messaging
expect(page).to have_input "variants[#{variant.id}]"
fill_in "variants[#{variant.id}]", with: '1'
wait_until { !cart_dirty }

View File

@@ -36,9 +36,8 @@ feature 'Shops', js: true do
it "should show closed shops after clicking the button" do
create(:simple_product, distributors: [d1, d2])
visit shops_path
click_link "Show closed shops"
page.should have_selector 'hub.inactive'
page.should have_selector 'hub.inactive', text: d2.name
click_link_and_ensure("Show closed shops", -> { page.has_selector? 'hub.inactive' })
page.should have_selector 'hub.inactive', text: d2.name
end
it "should link to the hub page" do
@@ -52,4 +51,14 @@ feature 'Shops', js: true do
open_enterprise_modal producer
modal_should_be_open_for producer
end
def click_link_and_ensure(link_text, check)
# Buttons appear to be unresponsive for a while, so keep clicking them until content appears
using_wait_time 0.5 do
10.times do
click_link link_text
break if check.call
end
end
end
end