Approaching Rails Legacy Systems Chapter 4: Understand your tests

Reading Time: 2 minutes

There are many different kinds of testing you can use in your projects, but in this last chapter, rather than discussing the techniques or these tests, we are going to cover some things you can use and benefit from to get a full understanding of your project. Keep reading the last part o this blog post series!

Squint Test

Squint test your files.

Open any specific file, take a step back, and squint your eyes. By doing this you can have a complete idea and full view of your code architecture. Check those basic elements (classes, methods, objects).

Identity the Subject/System Under Test (SUT)

What are we testing? Do you have any unit testing at all (Rspec, mini-test, something else)? Try finding which classes, objects, and methods are tested.

if there is Capybara, Cucumber, Cypress or whatever is being used for testing, take a deep look of what is being tested there.
You will understand a lot about your codebase and business logic by doing this.

Understand the test setup and dependencies

Are we using factorybot? VCR? Are we cleaning our test database after every run?

Check how your test is running, how the configuration looks like… There are many useful insights to be obtained by doing this.

Find out the test coverage

Use simplecov to discover how much of your code is being tested. This tool provides us a way to check for that, and see which things must be considered for improvement before we start working on the code.

simplecov

Remember Single Responsibility Principle also applies to tests

Further reading:

Extract Features

Changing code often will get difficult, so consider extracting features into a new app.

When How
Lack of or outdated documentation Extract code and start documenting it
Single test containing multiple SUT Create a high-level collaborative test suite, check Specification by Example
Low coverage Bring enough code to make tests pass, iterate
Hard test setups Simple is better
Slow test suite Maybe consider migrating to a new tool

Wrap Up

There you go, by this point, you have all that you need to approach a Rails Legacy System. I hope you found this series useful, and that you learned some useful bits of information and tools to land successfully on a Rails Legacy Project. If so, follow us to learn more about Rails, React Native, JS topics. Thanks for your time.

0 Shares:
You May Also Like