vendredi 2 novembre 2018

How to fully diagnose test environment issues in Rails 5

So, a nightmare of time playing wackamole with rails test errors, and I'm pretty sure something has happened to the test environment and I don't know how to fix it. Hoping to not get fed a fish here, but rather a helping hand in how to figure out where the problem is.

The other day I had a completely functioning set of several hundred controller integration tests using fixtures. I recently started on an API, which uses a new namespace. Tests for the API would run fine if run specifically, but were failing when running 'rails test'. Suddenly, a test fixture was no longer accessible and was showing as nil. I don't think creating a new namespace in routes, and a directory in tests/controllers/api/ should create any new problems, so I will move on.

Logging into the console with RAILS_ENV=test, I can see there are no fixtures.

Tried RAILS_ENV=test rails db:fixtures:load, no luck.

At some point I was given the following error:

$ rails c RAIL_ENV=test
config.eager_load is set to nil. Please update your config/environments/*.rb files

but this was not true, test was already to false (dev was false and production was true, so no nil anywhere). Resolved it by running RAILS_ENV=test bundle exec rails c not sure why this was necessary as I never needed it before.

Schema file is present and appears intact. Never touched between working and not working. Some of my fixtures files are loaded in the console, but some are not.

I've been trying to figure out the flow of things: create test database, create tables, load fixtures or seed etc. and there are a number of different options for manipulating the db in rails.

Not sure where to look at this point, but might be best to start from scratch. As I mentioned, the suddenness between working and not working and lack of modification that is really concerning for future reliance if I don't know how to start at the beginning of the test process and work through to the problem. If it only makes sense to address this particular problem then I can change the question title. Otherwise, the hope is that the troubleshooting steps you provide will resolve this issue to be marked as the answer.

Aucun commentaire:

Enregistrer un commentaire