Rimian
Rimian

Reputation: 38428

Capybara/Rspec listening for ajax response explicitly not waiting for x seconds

I'm trying to write an end-to-end test for something that happens in the UI after an ajax request returns a certain JSON response.

Basically, I want to test the whole stack by creating an active record object, requesting it (via an ajax get) and then testing if the front end displays that content somewhere. I'm running Rails 3 with Capybara/Rspec with a Backbone.js front end.

Currently, I am waiting for the response by explicitly setting sleep. This is working fine at the moment but obviously, not the best idea.

How can I wait for the ajax response in Capybara? Do I need to expose the JSON object through a hidden form field or something?

Upvotes: 2

Views: 674

Answers (1)

sockmonk
sockmonk

Reputation: 4255

If you're checking the page content, Capybara automatically waits for the response. If it's not waiting long enough, try increasing the value of Capybara.default_wait_time in your spec_helper.rb file. In my case, I found that the default was only 2 seconds; increasing it to 5 helped my spec to pass.

Upvotes: 0

Related Questions