I just spent 8 hours solving a similar problem, and I found a solution. Fix is so simple that I could cry.
First diagnosis
The reason you get " SQLite3::BusyException: database is locked " is because you are running an asynchronous stream, namely a view form that ends with the "database record" race going to the main test stream. In fact, as your test is already completed and your “after each” database cleanup procedure (defined in your spec_helper) is performed, the form action just started trying to run business logic (which is based on the data that your test after: each the hook is busy destroying).
This problem is much more common in tests that click on the AJAX POST button and then end without claiming something about changing the view.
Secondly, the correction
As it turns out, Capybara is designed to “synchronize” all your requests. But only if you implicitly allow this. Please note that after submitting your form you do not see Capybara on your page. Therefore, he thinks that everything is ready, and your data goes beyond the scope (while the form submission thread hangs in the background.)
Just add the following line of code at the end of the test, and it should suddenly work:
page.should_not have_content "dude, you forgot to assert anything about the view"
Third, make it beautiful
Do not use execute_script. For Kapiba. But also do not rely on "click_on" because it is not a great abstraction. You must know too much about its internal elements. Instead, use a CSS selector like this:
page.find("#submit_button").click
And one more thing: your test should not try to manipulate the DOM. A good Selenium test suggests that it should follow the same steps as a regular user.
So in conclusion
it "should pass when answering all correct", :js => true do login_as(student, :scope => :student) visit ("/student_courses") page.find(".my-js-enabled-button").click page.find("#submit_button").click
source share