JavaScript integration testing in Ruby on Rails JavaScript integration testing in Ruby on Rails javascript javascript

JavaScript integration testing in Ruby on Rails


AFAIK, outside of a combination of Capybara with Selenium Web-Driver there is very few options for automated testing of JS code. I use cucumber with capybara and selenium web-driver and because selenium-webdriver actually launches firefox or chrome to go through testing a particular page with ajax call, It does take significantly longer to run through a suite of tests.

There are some alternatives but they dont work all the time or for every situations.For instance: Capybara with envjs


In April 2011 the thoughtbot guys updated their quest for javascript testing.Akephalos has fallen out of favor for the following reasons:

Bugs: as previously mentioned, there are bugs in htmlunit, specifically with jQuery’s live. Although all browser implementations have bugs, it’s more useful if tests experience the same bugs as actual browsers.

Compatibility: htmlunit doesn’t fully implement the feature set that modern browsers do. For example, it doesn’t fully handle DOM ranges or Ajax file uploads.

Rendering: htmlunit doesn’t actually render the page, so tests that depend on CSS visibility or positioning won’t work.

Performance: when most of your tests use Javascript, test suites with htmlunit start to crawl. It takes a while to start up a test with Akephalos, and a large test suite can easily take 10 or 15 minutes.

So they rolled their own solution which is open source - capybara-webkit. It's still fairly new but it looks like the way to go now.