How many times did we deploy our application today?

17 July 2013

As some of you know I’m working on a new project called Timi. I want to tell you why I am so relaxed when I deploy a new feature.

Test driven development is the key

I learned quite a lot over the last few years. Three years ago I wrote my projects without a line of test code. When I started with Rails I rolled into testing, mostly because everybody in the Rails community is testing their code. After a year of Test Driven Development I completely rely on testing and I keep my coverage above 97%. That’s why deploy multiple times a day without breaking a sweat.

So what is test driven development?

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.

source: en.wikipedia.org

Some statistics for Timi

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |   621 |   467 |      14 |      52 |   3 |     6 |
| Helpers              |    55 |    44 |       1 |       8 |   8 |     3 |
| Models               |   227 |   165 |       6 |      26 |   4 |     4 |
| Libraries            |    71 |    49 |       1 |       2 |   2 |    22 |
| Controller specs     |  1153 |   833 |       0 |       1 |   0 |   831 |
| Feature specs        |   946 |   658 |       0 |       2 |   0 |   327 |
| Mailer specs         |    26 |    18 |       0 |       0 |   0 |     0 |
| Model specs          |   386 |   300 |       0 |       0 |   0 |     0 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  3485 |  2534 |      22 |      91 |   4 |    25 |
+----------------------+-------+-------+---------+---------+-----+-------+

Code LOC: 725     
Test LOC: 1809     
Code to Test Ratio: 1:2.5

So what does this mean? This means that for every line of code in my project there are on average 2.5 lines of test code!

You probably wonder what a test looks like in Rails?

This is an example:

it "shows the total duration of a project" do
  project = create(:project, team: @user.team, name: "project z")
  create(:time_entry, project: project, duration: 1.hour, user: @user)
  create(:time_entry, project: project, duration: 1.minute, user: @user)

  visit projects_path

  page.should have_content "1:01"
end
Jankees van Woezik profile picture

Hello, I'm Jankees van Woezik

Like this post? Follow me at @jankeesvw on Twitter