Things I do while debugging — get a working version
TL:DR — getting a working version to compare the broken version helps me fix things
One of the things I’ll try to do when debugging an issue is to get a working version going.
In some cases this is hitting ctrl-z until I’m in a working state, or it may be rolling back to a previous commit, or sometimes its setting up a tiny project with a working case.
My context
I was trying to add rspec-retry
gem to our workflow as we were having problems with flakey tests. Using rspec-retry meant that if a test failed it would retry the test x number of times until it passed.
The problem
After following the setup steps outlined in the documentation it still wasn’t retrying failing tests in our Rails project.
Tiny project (working version)
I created the smallest project I could that would let me use the gem and see it working. This had one test file, one spec_helper file and one Gemfile.
tiny_retry_project- Gemfile
- spec
- spec_helper.rb
- failing_spec.rb
And rspec-retry
worked. I had my working version.
Working vs non-working
Then I tried to look at the differences between my working version (tiny project) and my non-working version (giant rails project).
At the top of my rails spec file it had require "rails_helper"
I did not have this in my working version spec file.
When I deleted this line suddenly rspec-retry
started retrying failed tests! I would never have thought to delete in the first place as its in all our spec files.
Then it was a matter of tracking down the line in rails_helper
that was causing the issues. I could then gain confidence that this was causing the issue by adding the same line to my tiny project and breaking it.
Making the problem as small as it can be
I use this debugging technique a bunch. Sometimes it’s setting up tiny projects on glitch.com, sometimes it’s creating something locally. But I always find removing all the noise of the million extra things going on in a big app and just focusing on the problem is super helpful.