Tiny testing

September 23, 2014

I recently started getting a lot of spam enquiries through my portfolio site. This began to annoy me after several days of junk emails and I planned to do something about it.

I decided to implement wordpress’ askimet to filter the enquiries before they are sent off to my inbox. Usually (with tiny personal projects) this implementation would be hacked together, deployed and manually tested. This time round I took a different approach and decided to write automated tests.

Solving the problem using tests

I setup cucumber to integration test enquiries. This was my first time using cucumber, I normally write my integration tests in MiniTest but I will definitely give cucumber a go in a few other projects as I really like the separation from the normal unit style specs and it was also pretty painless to configure.

I then turned to MiniTest::Spec to drive the design of an Enquiry object and introduced the Rakismet gem to handle actually talking with the akismet API.

Once I had completed this feature I setup codeship to run whenever code is pushed to GitHub, this provides exposure if something does break. I like to use a git pre-push/pre-commit hook to run tests, but since they don’t get committed to your repo you can’t rely on them always being there.

Overall this probably took more than 10x the amount of time it would take to manually test this feature, however, it was a lot less boring and I got to play with some new tools (cucumber and Rakismet).

Future thoughts

From this scenario I have learnt that automated testing isn’t reserved for large or important apps, it can be used effectively on trivial applications every day to provide confidence in code and enable joyous refactoring.

Since starting to write this post I have also added to the cucumber features to make sure other functionality is working.

The source code for my portfolio is available on GitHub if you’re interested in exploring further.

Pete Hawkins

Hey 👋 I’m Pete a web developer, who loves to ship products and build cool things with React and React Native.
You can follow me on Twitter or Subscribe for updates.