Integration testing with Capybara
Capybara is nothing entirely new and acceptance testing certainly isn’t, but there are still a lot of web developers out there that haven’t given it a go yet and they really are missing a trick. I just want to run through the main advantages with some pointers where to get started.
In a nutshell, acceptance testing with Capybara allows a headless browser to run through your application with various scenarios that you’ve defined, checking all of your website features behave as expected.
It means you can make changes to your site, run your acceptance tests and know you haven’t broken something without realising.
Unless you have a team of testers that run through scripts for every single pathway through your website, you are at risk each time you deploy a change.
Acceptance testing gives you confidence to make that change or refactor that legacy code.
With your test suite behind you you know exactly how much effort there will be to upgrade to that latest gem release or version of Rails because you will see precisely what needs fixing.
It is a massive time saver, it will make your life so much easier in the long run.
One of the main reasons developers cite against acceptance tests is the upfront development cost. You definitely need to write a lot more code when implementing a feature, but I actually think this should be embraced by more developers.
Slowing down is good thing, in fact I’ve found the slower I go, the better the code I write. ‘Fast and dirty’ will eventually come back to bite you because more time is spent on bug fixing and re-factoring when the spec changes or a new feature is introduced later down the line.
At Kyan, we use Capybara with Rspec and Steak. Steak is an an alternative to the ‘industry standard’ Cucumber. The main difference between the two is that Cucumber allows you to write your acceptance tests in plain English. However, Cucumber essentially uses Capybara under the hood and until our tests need to be read by anyone other than the developers we’ll probably stick with Steak, for now…Tweet