Single test fails after switching to capybara-webkit

I wrote some RSpec test for my rails 3.2 application and because the browser that tried to switch from firefox to capybara-webkit canceled me. After that, all tests are still performed, except for one. Invalid line:

 expect { click_button "Create" }.to change(Answer, :count).by(count) 

If I remove the wait and add a method to take a screenshot before and after, I see that the test is running correctly. But if I find the step using Debugger, the log shows me that the entries are created after the second line of the screenshot. I can wait for the click_button button and the corresponding Controller action to be pressed after the next line has been executed.

The Create button is a standard html button, no JS is involved in the create action. Does sb have an explanation for this strange behavior?

+4
source share
1 answer

There is a race condition here between Capybara sending the click action to the server and your test checking the database.

The easiest way to resolve this is to wait until validation:

 expect { click_button "Create"; sleep 2 }.to change(Answer, :count).by(count) 

I do not like it. The best way to verify this would be end-user verification.

For example, after clicking the Create button, does the user see the answer on the answer page?

 fill_in :title, :with => "My answer" click_button 'Create' page.should have_text "My answer" 
+6
source

All Articles