From 89c3758bae93f95fa4c23d99167136bf16b56998 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 1 Jun 2016 16:15:44 +1000 Subject: [PATCH] Avoid race conditions in feature specs --- spec/features/consumer/shopping/shopping_spec.rb | 1 + spec/features/consumer/shops_spec.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 9b03259ec5..1e69e97b1c 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -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 } diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index 9625640fe7..df44955232 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -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