Best practices

9 tips to improve RSpec maintainability

Use the right tool at the right place for the right purpose

Duong Nguyen
The Startup
Published in
3 min readJun 23, 2020

--

Photo by Kelly Sikkema on Unsplash

Writing good test cases is as important as writing good code. Well written specs would help identify bugs as well as act as good documentation.

Here are 9 tips to UP your RSpec game.

There are 2 principles that will lead us through these tips

  1. DRY — Don’t Repeat Yourself principle
  2. Use the right tool at the right place for the right purpose

LET’S START!!!

1. Structure the code into the right place

There are three fundamental blocks of every test cases

  • Setupbefore, let, let!
  • Assertit
  • Teardownafter

The code should be structured accordingly into the right blocks.

2. Avoid mocking global…

--

--

Duong Nguyen
The Startup

Engineering Manager@ Rakuten Viki. All opinions are my own.