Monday, 26 August 2013

Testing javascript refreshes using multiple VCR cassettes

Testing javascript refreshes using multiple VCR cassettes

I'm using Capybara and Poltergeist to test an index page that uses
setTimeout to periodically refresh page content. The page content
transitions between three states, based on an external service, and I've
got a cassette for each of these states.
I'm trying to test the refresh using code like this:
VCR.use_cassette 'object_new' do
visit index_path
page.should have_content 'New'
end
VCR.use_cassette 'object_running' do
page.should have_content 'Running'
end
VCR.use_cassette 'object_complete' do
page.should have_content 'Complete'
end
The first have_content succeeds, but the second does not. Capybara should
be waiting for any async calls to return and update the DOM so that these
assertions pass. I've tried using_wait_time to force the assertion to wait
long after the ajax call returns, but it doesn't help. Any ideas as to
what might be missing from my spec to make this work? The functionality
does work in the browser; it's just the tests that aren't passing.

No comments:

Post a Comment