Test-Driven Development (TDD) with Docker and ServerSpec
Docker containers might have a simpler language, but in the end, general concepts remain common and still apply. Testing is good for quality, and writing tests first ensures that we write code that would make a test pass, instead of writing tests after the code is written, which would somehow lead to missed errors. To help us with this, we'll use ServerSpec, based on RSpec, to initiate a TDD workflow along with writing and testing a Docker container. Working like this usually ensures a very high quality of work overall and very sustainable containers.
Getting ready
To step through this recipe, you will need:
- A working Docker installation
- A working Ruby environment (including Bundler)
How to do it…
Our goal is to create an NGINX container following TDD principles. Before we start to code, let's begin by setting up our environment.
Creating a ServerSpec environment using Bundler
ServerSpec comes as a gem (a Ruby package), and...