From 4830cc028ae10884f5cc42f1a3b9ba8cb953359f Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Tue, 9 Sep 2014 22:52:45 -0400 Subject: [PATCH] Clean up manual timeouts in feature tests --- .../step_definitions/dependencies_steps.rb | 8 ++--- .../step_definitions/project_list_steps.rb | 4 +-- features/step_definitions/project_steps.rb | 9 ++--- features/step_definitions/todo_edit_steps.rb | 6 ++-- features/support/tracks_step_helper.rb | 33 +++++-------------- 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/features/step_definitions/dependencies_steps.rb b/features/step_definitions/dependencies_steps.rb index c2db3229..4c877837 100644 --- a/features/step_definitions/dependencies_steps.rb +++ b/features/step_definitions/dependencies_steps.rb @@ -85,11 +85,9 @@ Then /^the successors of "(.*)" should include "(.*)"$/ do |parent_name, child_n parent = @current_user.todos.where(:description => parent_name).first expect(parent).to_not be_nil - # wait until the successor is added. TODO: make this not loop indefinitly + # wait until the successor is added. wait_until do - found = !parent.pending_successors.where(:description => child_name).first.nil? - sleep 0.2 unless found - found + !parent.pending_successors.where(:description => child_name).first.nil? end end @@ -119,4 +117,4 @@ Then /^I should see that "([^"]*)" does not have dependencies$/ do |todo_descrip expect(todo).to_not be_nil dependencies_icon = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img" expect(page).to_not have_xpath(dependencies_icon) -end \ No newline at end of file +end diff --git a/features/step_definitions/project_list_steps.rb b/features/step_definitions/project_list_steps.rb index 8b5e4a0a..ca9b09b4 100644 --- a/features/step_definitions/project_list_steps.rb +++ b/features/step_definitions/project_list_steps.rb @@ -7,9 +7,7 @@ When /^I delete project "([^"]*)"$/ do |project_name| end expect(get_confirm_text).to eq("Are you sure that you want to delete the project '#{project_name}'?") - wait_until do - !page.has_css?("a#delete_project_#{project.id}") - end + expect(page).to_not have_css("a#delete_project_#{project.id}") end When /^I drag the project "([^"]*)" below "([^"]*)"$/ do |project_drag, project_drop| diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index f7ce8814..59592ac5 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -214,10 +214,7 @@ When /^I add a note "([^"]*)" to the project$/ do |note_body| expect(elem).to_not be_nil elem.click - wait_until do - !elem.visible? - end - + expect(page).to_not have_css(submit_button, visible: true) end When /^I click on the first note icon$/ do @@ -283,9 +280,7 @@ Then /^I should see the italic text "([^\"]*)" in the project description$/ do | end Then /^the project title should be "(.*)"$/ do |title| - wait_until do - page.find("h2#project_name_container span#project_name").text == title - end + expect(page).to have_css("h2#project_name_container span#project_name", text: title, exact: true) end Then /^I should see the project name is "([^"]*)"$/ do |project_name| diff --git a/features/step_definitions/todo_edit_steps.rb b/features/step_definitions/todo_edit_steps.rb index ad8c91f9..347f0dea 100644 --- a/features/step_definitions/todo_edit_steps.rb +++ b/features/step_definitions/todo_edit_steps.rb @@ -138,9 +138,7 @@ When /^I clear the due date of "([^"]*)"$/ do |action_description| # de same todo more than once within all("div#edit_todo_#{todo.id}")[0] do find("a#due_x_todo_#{todo.id}").click - wait_until do - find("input#due_todo_#{todo.id}").value == "" - end + expect(page).to have_field("due_todo_#{todo.id}", with: "") end submit_edit_todo_form(todo) end @@ -208,4 +206,4 @@ end Then /^I should see an error message$/ do error_block = "//form/div[@id='edit_error_status']" expect(page).to have_xpath(error_block) -end \ No newline at end of file +end diff --git a/features/support/tracks_step_helper.rb b/features/support/tracks_step_helper.rb index 2effe93b..e6306be9 100644 --- a/features/support/tracks_step_helper.rb +++ b/features/support/tracks_step_helper.rb @@ -1,37 +1,20 @@ module TracksStepHelper - def wait_until(timeout = 5) - timeout(timeout) { yield } - end - - def timeout(seconds = 1, error_message = nil, &block) - start_time = Time.now - - result = nil - - until result - return result if result = yield - - delay = seconds - (Time.now - start_time) - if delay <= 0 - raise TimeoutError, error_message || "timed out" - end - - sleep(0.05) + def wait_until(wait_time = Capybara.default_wait_time) + Timeout.timeout(wait_time) do + loop until yield end end def wait_for_animations_to_end wait_until do - page.evaluate_script('$(":animated").length') == 0 + page.evaluate_script('$(":animated").length').zero? end end def wait_for_ajax - start_time = Time.now - expect(page.evaluate_script('jQuery.isReady&&jQuery.active==0').class).to_not eql(String) - until(page.evaluate_script('jQuery.isReady&&jQuery.active==0') || (start_time + 5.seconds) < Time.now) - sleep 0.05 + wait_until do + page.evaluate_script('jQuery.active').zero? end end @@ -123,8 +106,8 @@ module TracksStepHelper arrow.click submenu_css = "div#line_todo_#{todo.id} ul#ultodo_#{todo.id}" - submenu = page.find(submenu_css) - wait_until { submenu.visible? } + expect(page).to have_css(submenu_css, visible: true) + submenu = page.find(submenu_css, visible: true) within submenu do yield