Search⌘ K

Getting Started with Legacy Code

Explore how to handle legacy Ruby on Rails codebases by getting the code under version control, ensuring it runs properly, and making the test suite functional. Understand common issues such as outdated fixtures or broken tests and learn strategies for upgrading tools like RSpec. This lesson helps you build a foundation for applying test-driven development to legacy projects, enabling you to fix bugs while maintaining existing functionality.

Legacy code starting points

When we’re presented with a new codebase, our first job is to figure out exactly what the heck is going on. Toward that end, we should do three things immediately.

Get the code in source control

These days it probably is already under source control, but we can’t be too careful. Make sure we have all the access to any code repository that we need. While starting on a new legacy codebase is not the time to get fancy with new tools, we’ll be much better served by using Git or some other source-control system that lets us easily create and manipulate branches. This will enable us to easily explore changes to the codebase using branches as scratch pads that can be kept or discarded as needed.

Get the code running

If the legacy project was conceived without much knowledge of Rails community practices (evidenced by the lack of tests), it wouldn’t surprise if the production environment is also a little sketchy. Conventional wisdom suggests that our ...