Clean up manual timeouts in feature tests

This commit is contained in:
Dan Rice 2014-09-09 22:52:45 -04:00
parent ab7081482e
commit 4830cc028a
5 changed files with 16 additions and 44 deletions

View file

@ -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
end

View file

@ -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|

View file

@ -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|

View file

@ -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
end

View file

@ -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