samedi 2 juillet 2016

Rails: how can I test a stopwatch in my Capybara integration tests?

Currently writing tests for my Rails app's time tracking functionality. I can't figure out a way to simulate clicking the "play" button on the timer, waiting a few seconds, clicking pause and then submitting the form (creating a new Timestamp object).

test "track time with stopwatch" do
    visit new_project_timestamp_path(@project)
    find('#play_button').click 
    sleep 4.0
    find('#pause_button').click
    click_button "submit_new_timestamp"
    visit project_path(@project)
    assert page.has_content? "4 seconds"
 end

^This is the gist of what I want it to do, but sleep obviously doesn't work because it suspends the thread completely, whereas I want the test to kind of "wait around" while the stopwatch does its thing for a few seconds. The above test fails because no time is actually tracked; pause is clicked immediately after play, in the eyes of the timer, and so the form is submitted with no actual time logged, which of course throws a validation error.

Is there a way I'd be able to simulate waiting a few seconds without actually suspending the thread?

Aucun commentaire:

Enregistrer un commentaire