diff --git a/spec/acceptance/users/order_a_product.feature b/spec/acceptance/users/order_a_product.feature index fd576f5e..049cc918 100644 --- a/spec/acceptance/users/order_a_product.feature +++ b/spec/acceptance/users/order_a_product.feature @@ -38,6 +38,7 @@ Feature: Ordering a product as a user Then the user should see an empty active order panel And the user clicks on the order 'Heineken beer' twice And the user clicks on the user order button + And I wait 1 second Then an order with 2 products 'Heineken beer' should have been created And no order for the product 'Apple pie' should have been created diff --git a/spec/acceptance_steps/global_user_steps.rb b/spec/acceptance_steps/global_user_steps.rb index 1a03a794..d64c6b84 100644 --- a/spec/acceptance_steps/global_user_steps.rb +++ b/spec/acceptance_steps/global_user_steps.rb @@ -24,7 +24,6 @@ end step "the user should be redirected to the archived list path" do #route_should_be 'user#history_list' - sleep 1 ember_route_should_be "/lists/#{@order.list_id}" page.should have_selector ".order-row-#{@order.id}" end diff --git a/spec/acceptance_steps/suppliers/navigation_steps.rb b/spec/acceptance_steps/suppliers/navigation_steps.rb index 3062ad54..303d9a79 100644 --- a/spec/acceptance_steps/suppliers/navigation_steps.rb +++ b/spec/acceptance_steps/suppliers/navigation_steps.rb @@ -27,5 +27,5 @@ end ## ASSERTIONS step "the supplier should be redirected to the root path" do - ember_route.should == '/' + ember_route_should_be '/' end diff --git a/spec/acceptance_steps/suppliers/settings_steps.rb b/spec/acceptance_steps/suppliers/settings_steps.rb index d02680ba..73760116 100644 --- a/spec/acceptance_steps/suppliers/settings_steps.rb +++ b/spec/acceptance_steps/suppliers/settings_steps.rb @@ -37,7 +37,7 @@ end step "the supplier should be redirected to the supplier settings path" do # route_should_be 'supplier#edit' - ember_route.should == '/settings' + ember_route_should_be '/settings' end step "the supplier email is the new email and the unconfirmed email is empty" do diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb index 76110db7..ff935202 100644 --- a/spec/acceptance_steps/users/order_products_steps.rb +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -13,7 +13,6 @@ end step "the user clicks on the user order button" do find('.order-selected-products-button').click - sleep 1 end step "the user has an active order" do diff --git a/spec/support/route_helpers.rb b/spec/support/route_helpers.rb index 295ea05f..f9e14b55 100644 --- a/spec/support/route_helpers.rb +++ b/spec/support/route_helpers.rb @@ -15,13 +15,26 @@ module SpecRouteHelpers end def ember_route_should_be(route_def) - ember_route.should == route_def + max_wait = 4 + time = 0.0 + time_step = 0.25 + while time < max_wait && ember_route != route_def + time += time_step + sleep time_step + end + ember_route(omit_should_raise: true).should == route_def end - def ember_route + def ember_route(omit_should_raise: nil) # currentRouteName does not include model information: /list/123 => currentRouteName == 'list' # page.evaluate_script %|App.__container__.lookup('controller:application').get('currentRouteName')| # page.evaluate_script %|App.__container__.lookup('router:main').location.lastSetURL| # not working for direct path supplier#/settings - page.evaluate_script %{App.__container__ && (window.location.hash || "#/").substr(1)} + route = page.evaluate_script %{App.__container__ && (window.location.hash || "#/").substr(1)} + unless omit_should_raise + def route.should(*) + raise "Cannot call should on ember route. Use ember_route_should_be instead" + end + end + route end end