When renaming or moving files be careful not to edit the old copy

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the dumb-mistakes-and-gotchas category.

Last Updated: 2024-11-21

I had a test that used a fake version of some service:

let(:fake_doc_services) {
  Class.new do
    def to_sample(_notes_file, _options = {}); end

    # NEW CODE
    def remove_author_name(_notes_file, _options = {}); end
  end
}

Whenever I ran a test that used this fake, it failed to find the latest method I had added: remove_author_name.

# This `stub_const` function tells the test to set the `DocServices` constant to
# the next argument `fake_doc_services`
stub_const('DocServices', fake_doc_services)
...

After a tad too much debugging, I realized that I was editing an old, unused copy of my test file. The reason this happened was because I had recently moved the file from spec/requests to spec/system. However my editor had somehow allowed me to continue working on a copy of the file in the old location (not sure why - I think because I had vim open in two terminal tabs)

Sure enough, the contents of this copy was missing the new method.

let(:fake_doc_services) {
  Class.new do
    def to_sample(_notes_file, _options = {}); end
  end
}