Testing AJAX with Cucumber and Capybara
For a recent project, I used Cucumber and Capybara for my user stories. When I decided to AJAXify the functionality, I wrote some stories tagged with @javascript that were nearly identical to my non-javascript versions (non-JS and JS). Since the changes to the page content should be the same with or without Javascript, testing the page content wouldn't actually verify that the AJAX funtionality was working. To solve this, I created the step "Then the page should not change" with the following definition:
Then 'the page should not change again' do
evaluate_script('window.onunload = window.stop')
end
Now, if the user clicks a link that doesn't have its behavior overwritten by Javascript, a blank page will be displayed and any following steps will fail.