TDD mistake

TDD:

  1. first, write a failing test
  2. then, write just enough code to make the test pass
  3. repeat from 1.

What TDD does is to focus on the interface of any code you are going to write. IMO, only very basic solutions are good candidates for TDD. By basic I mean not simple but minimal, like a REST API.

How to automatically build a hash

Sorry if the title misled you, but I couldn’t come up with anything better and equally short. A YAML configuration file can be loaded into a hash, and this works pretty much out of the box. Sometimes, however, I need to also add configuration on the fly to the same hash. Then it becomes a little tedious to manually build missing keys, so I created my own Ando::Hash, which is a thin wrapper around Ruby’s Hash.

{[ .ando-hash | 1.hljs(=ruby=) ]}

And here is a very short usage example.

{[ .ando-hash-example | 1.hljs(=ruby=) ]}

How to run Rake tasks programmatically

Some time ago I was told to reimplement some Rake tasks such that they would be available from a simple admin interface. Instead of that, I came up with a web interface for Rake tasks, such that exactly the same code can be run from the web and from a console.

At the core there are a couple of global methods: runnable_tasks and run_task.

{[ .rake-global | 1.hljs(=ruby=) ]}

And here is how that it’s supposed to be used:

{[ .rake-example | 1.hljs(=ruby=) ]}