ephemeral-env: A managed ephemeral environment for testing
If your code is driven by environment variables you'll often find yourself writing tests like this:
The trouble with this is twofold:
- You need to remember to undo whatever changes you made at the end of your test, lest you pollute the environment for other tests.
- You're at the mercy of tests racing and changing the environment from under one another.
ephemeral-env solves this by:
- Creating a copy of the current environment
- Reverting to that original state when the ephemeral env is dropped
- Providing you with a convenience function to avoid having to pepper your tests with
unsafe {...}.
Rewriting the example above with ephemeral-env would give you: