TDD Basics : Learning Specs


  • Why do we need learning specs?
  • How to write learning specs?


J. B. Rainsberger says in this blog post at :

When you try to learn a new library at the same time as you explore the behavior and design of your application, you slow down more than you think.

When you can’t figure out how to make the new library work for this thing you want to build, you might spend hours fighting, debugging, swearing.

Stop. Write a Learning Test.

  1. Write a new test.
  2. Write a test that checks the things you tried to check earlier with debug statements.
  3. Write a test that has nothing to do with your application and its domain.
  4. Remove unnecessary details from your test.

When this test passes, then you understand what that part of the library does. If it behaves strangely, then you have the perfect test to send to the maintainers of the library.

Example 1 : Mongodb Koans

Step 1

The Mongodb koans are focused on learning Mongodb.

$git clone

Step 2

Read the README file for more instructions.

Version 1

Step 1

First version contains the exercises. Go to the directory where you have mongodb-koans checked out and switch to the initial version by:

$git co 578061ea13bfb2afd85ca7bcf2f3f92a908caa69

Step 2

To run the tests:

$ruby path_to_enlightenment.rb

Version 2

Second version is the solution to all the exercises. You can compare your solution by browsing the source at

Example 2 : Mongodb Learning Specs

Step 1

Download learning Mongodb specs:

$git clone

Step 2

The specs needs Mongodb version v1.6.2. to be running. Follow the installation instructions for Mongodb on its home page. To run Mongo daemon:

$mongod --dbpath /Users/bparanj/data/mongodb

Step 3

To run the spec:

$rspec mongodb_queries_spec.rb 

Example 3 : RSpec Learning Specs

Read the specs to describe features of RSpec at
Here is an example:


Write learning specs for a gem that you would like to learn.

Related Articles

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.