bakineggs

one spec at a time

My name is Dan Barry. I've been a programming enthusiast for over ten years now.

Professionally, I've been developing web applications using Ruby on Rails. For fun, I'm writing a language called okk.

I'm currently living in San Francisco, California where I work as a software engineer at Square.

Blog

May 1, 2010 @ 11:48pm

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.

Post Comment

© 2008-2012 Dan Barry. Designed by Hunter Hastings.