Skip to content

meleu/tdd-ruby

Repository files navigation

Learn Ruby with TDD

This is a work in progress by meleu!

This "book" is my attempt to teach idiomatic Ruby and Test-Driven Development (TDD).

(spoiler: we're going to use Minitest, not RSpec)

Why?

Why Ruby?

Ruby has an elegant syntax that is natural to read and easy to write. It offers an extremely productive ecosystem where we can quickly build a product and put it online.

Why TDD?

There are many books and articles talking about the benefits of TDD. There are also articles defaming TDD, but if you're reading this book I believe you have some hope that it's a useful skill.

Of course I'm on the side of those who think that TDD is useful. I notice that TDD promotes a better software design. By using TDD you are encouraged to make your code testable, which means less coupled and easier to maintain. But instead of repeating all the good arguments already mentioned in those books, I'm going to mention a new one:

In the current AI era TDD is more valuable than ever.

With AIs writing code much faster than humans, such activity becomes cheaper. This leads me to a conclusion that the real value is less in the code, and more in the tests. Your ability to convert real world requirements into runnable tests will make you more productive and a valuable professional.

What you should expect

  • Explore the Ruby language by writing tests.
  • Get a solid grounding with TDD.
  • Be confident that you'll be able to start writing robust, well-tested software in Ruby.

The chapters are presented in a sequence where new Ruby features are introduced and used to create a program. The implementation is always driven by tests, reinforcing the TDD cycle.

Initially the cycle may seem tedious, but as you progress through the book you'll see how productive it is to get instant feedback on your work.

In the first chapters we use a procedural programming paradigm to show both the fundamentals of Ruby syntax and how TDD works. Once the basic Ruby concepts are addressed we start to write our code using Object-Oriented Programming.

You'll notice that the programs are really simple. That's intentional. The greatest value will be in the way we solve the problems. The tools we use, the tests we write, the way we organize our code...

If I used "real world problems", I would need to spend words explaining the problem's domain and then talk about the techniques. That would be lengthy and confusing. By keeping the problems simple, I'm sure you'll find a way to adapt the techniques to the "real world problem" you have to solve.

Who this is for

  • People who are interested in picking up Ruby.
  • People who already know some Ruby but want to explore testing more.

I assume you already wrote some code (any language) and understand the basic concepts of algorithms.

It's also expected that you're comfortable using the terminal (or at least not scared to use it).

Basic knowledge of git is helpful, but not mandatory.

What you'll need

  • A computer
  • A Unix-like operating system (Linux, MacOS or Windows with WSL)
  • Installed Ruby (3.1+)
  • Installed git
  • A text editor
  • A terminal

Feedback

Open issues or submit Pull Requests in this book's repository.

Credits

This book is heavily inspired by the awesome Learn Go with Tests, by Chris James. If you're interested in Golang, you should check that!