Paul Sturgess

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.

Confidence

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.

Easier upgrades

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.

Time saver

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.

Capybara

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…

Tags: ruby, rails, bdd, testing

See more posts

Add a comment

Note: comments are moderated before publication.

Most Popular

Is imitation really the sincerest form of flattery?

Piers Palmer

A new site has appeared on the wonderful inter-tubes, brought to us by a web design firm in Minnesota – Rocket 55 – that looks remarkably similar to ours. As designers we all stand on the shoulders of giants, borrowing ideas and concepts, using the same typefaces, co…

Kyan.com design process

Lee Whitelock

It’s great when you get a project you can really sink your teeth into. We pride ourselves on the effort we put into all our projects, of course, but when it’s for your own agency you can really ‘go to town’ and try new things. Our current website was out…

Easy image rollovers

Robin Whittleton

Recently themeforest.net ran a quick tutorial on how to achieve an image slide effect similar to our homepage. I thought I’d go into some more detail about the design decisions we made.