Remove sleeps from specs

This commit is contained in:
Rohan Mitchell
2013-01-22 12:12:29 +11:00
parent fec81b7ed4
commit 5b22cce950
2 changed files with 12 additions and 2 deletions

View File

@@ -103,9 +103,9 @@ feature %q{
login_to_admin_section
click_link 'Order Cycles'
click_link oc.name
wait_until { page.find('#order_cycle_name').value.present? }
# Then I should see the basic settings
sleep(1)
page.find('#order_cycle_name').value.should == oc.name
page.find('#order_cycle_orders_open_at').value.should == oc.orders_open_at.to_s
page.find('#order_cycle_orders_close_at').value.should == oc.orders_close_at.to_s
@@ -160,7 +160,7 @@ feature %q{
login_to_admin_section
click_link 'Order Cycles'
click_link oc.name
sleep 1
wait_until { page.find('#order_cycle_name').value.present? }
# And I update it
fill_in 'order_cycle_name', with: 'Plums & Avos'

View File

@@ -89,6 +89,16 @@ module WebHelper
DirtyFormDialog.new(page)
end
# http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
# Do not use this without good reason. Capybara's built-in waiting is very effective.
def wait_until
require "timeout"
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = yield
value
end
end
private
def wait_for_ajax
wait_until { page.evaluate_script("$.active") == 0 }